1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# https://docs.pleroma.social/backend/installation/otp_en/
---
- hosts: ramble-hard
  become: true
  vars_files:
    - ../vars.private
  tasks:

    - package:
        name:
        - certbot
        - nginx

    - service:
        name: nginx
        state: stopped

    # certbot certonly --standalone --preferred-challenges http -d yourinstance.tld
    - command: >
        certbot certonly --standalone --preferred-challenges http
        -n --agree-tos -m {{ lets_encrypt.email }}
        -d {{ pleroma.tld }}

    - service:
        name: nginx
        state: started

    # cp /opt/pleroma/installation/pleroma.nginx /etc/nginx/sites-available/pleroma.conf
    # ln -s /etc/nginx/sites-available/pleroma.conf /etc/nginx/sites-enabled/pleroma.conf
    - copy:
        src: /opt/pleroma/installation/pleroma.nginx
        dest: /etc/nginx/sites-available/pleroma.conf
        remote_src: true
      notify: Restart nginx
    # TODO: https://mastodon.bawue.social/@ixs/109514849935951693
    - file:
        src: /etc/nginx/sites-available/pleroma.conf
        dest: /etc/nginx/sites-enabled/pleroma.conf
        state: link
      notify: Restart nginx

    - replace:
        path: /etc/nginx/sites-available/pleroma.conf
        regexp: 'example\.tld'
        replace: "{{ pleroma.tld }}"
      notify: Restart nginx

    # Copy the service into a proper directory
    # cp /opt/pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
    - copy:
        src: /opt/pleroma/installation/pleroma.service
        dest: /etc/systemd/system/pleroma.service
        remote_src: true
      # Start pleroma and enable it on boot
      # systemctl start pleroma
      # systemctl enable pleroma
      notify: Restart pleroma

    # Create the directory for webroot challenges
    # mkdir -p /var/lib/letsencrypt
    - file:
        path: /var/lib/letsencrypt
        state: directory

    # Add it to the daily cron
    # echo '#!/bin/sh
    # certbot renew --cert-name yourinstance.tld --webroot -w /var/lib/letsencrypt/ --post-hook "systemctl reload nginx"
    # ' > /etc/cron.daily/renew-pleroma-cert
    # chmod +x /etc/cron.daily/renew-pleroma-cert
    - ansible.builtin.copy:
        content: |
          \#!/bin/sh
          certbot renew --cert-name {{ pleroma.tld }} --webroot -w /var/lib/letsencrypt/ --post-hook "systemctl reload nginx"
        dest: /etc/cron.daily/renew-pleroma-cert
        mode: +x
    # - template:
    #     src: renew-pleroma-cert
    #     dest: /etc/cron.daily/renew-pleroma-cert
    #     mode: +x

  handlers:
    - name: Restart nginx
      service:
        name: nginx
        state: restarted
    - name: Restart pleroma
      service:
        name: pleroma
        enabled: true
        state: restarted