4 lemmy_docker_image: "lemmy:dev"
6 # Install python if required
7 # https://www.josharcher.uk/code/ansible-python-connection-failure-ubuntu-server-1604/
10 - name: install python for Ansible
11 raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal python-setuptools)
15 changed_when: output.stdout != ""
16 - setup: # gather facts
19 - name: install dependencies
21 pkg: ['nginx', 'docker-compose', 'docker.io', 'certbot', 'python-certbot-nginx']
23 - name: request initial letsencrypt certificate
24 command: certbot certonly --nginx --agree-tos -d '{{ domain }}' -m '{{ letsencrypt_contact_email }}'
26 creates: '/etc/letsencrypt/live/{{domain}}/privkey.pem'
28 - name: create lemmy folder
29 file: path={{item.path}} state=directory
32 - { path: '/lemmy/volumes/' }
35 - name: add template files
36 template: src={{item.src}} dest={{item.dest}} mode={{item.mode}}
38 - { src: 'templates/docker-compose.yml', dest: '/lemmy/docker-compose.yml', mode: '0600' }
39 - { src: 'templates/nginx.conf', dest: '/etc/nginx/sites-enabled/lemmy.conf', mode: '0644' }
41 - name: add config file (only during initial setup)
42 template: src='templates/config.hjson' dest='/lemmy/lemmy.hjson' mode='0600' force='no' owner='1000' group='1000'
44 postgres_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/postgres chars=ascii_letters,digits') }}"
45 jwt_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/jwt chars=ascii_letters,digits') }}"
47 - name: build the dev docker image
48 local_action: shell cd .. && sudo docker build . -f docker/dev/Dockerfile -t lemmy:dev
51 - name: find hash of the new docker image
53 image_hash: "{{ image_build.stdout | regex_search('(?<=Successfully built )[0-9a-f]{12}') }}"
55 # this does not use become so that the output file is written as non-root user and is easy to delete later
56 - name: save dev docker image to file
57 local_action: shell sudo docker save lemmy:dev > lemmy-dev.tar
59 - name: copy dev docker image to server
60 copy: src=lemmy-dev.tar dest=/lemmy/lemmy-dev.tar
62 - name: import docker image
66 load_path: /lemmy/lemmy-dev.tar
69 register: image_import
71 - name: delete remote image file
72 file: path=/lemmy/lemmy-dev.tar state=absent
74 - name: delete local image file
75 local_action: file path=lemmy-dev.tar state=absent
77 - name: enable and start docker service
83 # cant pull here because that fails due to lemmy:dev (without dessalines/) not being on docker hub, but that shouldnt
84 # be a problem for testing
85 - name: start docker-compose
92 - name: reload nginx with new config
93 shell: nginx -s reload
95 - name: certbot renewal cronjob
98 name=certbot-renew-lemmy
100 job="certbot certonly --nginx -d '{{ domain }}' --deploy-hook 'docker-compose -f /peertube/docker-compose.yml exec nginx nginx -s reload'"