4 # Install python if required
5 # https://www.josharcher.uk/code/ansible-python-connection-failure-ubuntu-server-1604/
8 - name: install python for Ansible
9 raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal python-setuptools)
13 changed_when: output.stdout != ""
14 - setup: # gather facts
17 - name: install dependencies
19 pkg: ['nginx', 'docker-compose', 'docker.io', 'certbot', 'python-certbot-nginx']
21 - name: request initial letsencrypt certificate
22 command: certbot certonly --nginx --agree-tos -d '{{ domain }}' -m '{{ letsencrypt_contact_email }}'
24 creates: '/etc/letsencrypt/live/{{domain}}/privkey.pem'
26 - name: create lemmy folder
27 file: path={{item.path}} state=directory
30 - { path: '/lemmy/volumes/' }
33 - name: add template files
34 template: src={{item.src}} dest={{item.dest}} mode={{item.mode}}
36 - { src: 'templates/docker-compose.yml', dest: '/lemmy/docker-compose.yml', mode: '0600' }
37 - { src: 'templates/nginx.conf', dest: '/etc/nginx/sites-enabled/lemmy.conf', mode: '0644' }
39 - name: add config file (only during initial setup)
40 template: src='templates/config.hjson' dest='/lemmy/lemmy.hjson' mode='0600' force='no' owner='1000' group='1000'
42 postgres_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/postgres chars=ascii_letters,digits') }}"
43 jwt_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/jwt chars=ascii_letters,digits') }}"
44 lemmy_docker_image: "dessalines/lemmy:{{ lookup('file', 'VERSION') }}"
46 - name: enable and start docker service
52 - name: start docker-compose
58 - name: reload nginx with new config
59 shell: nginx -s reload
61 - name: certbot renewal cronjob
64 name=certbot-renew-lemmy
66 job="certbot certonly --nginx -d '{{ domain }}' --deploy-hook 'docker-compose -f /peertube/docker-compose.yml exec nginx nginx -s reload'"