]> Untitled Git - lemmy.git/blob - ansible/lemmy.yml
Merge branch 'master' into iav-arm-musl-dessalines
[lemmy.git] / ansible / lemmy.yml
1 ---
2 - hosts: all
3
4   # Install python if required
5   # https://www.josharcher.uk/code/ansible-python-connection-failure-ubuntu-server-1604/
6   gather_facts: False
7   pre_tasks:
8     - name: install python for Ansible
9       raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal python-setuptools)
10       args:
11         executable: /bin/bash
12       register: output
13       changed_when: output.stdout != ""
14     - setup: # gather facts
15
16   tasks:
17   - name: install dependencies
18     apt:
19       pkg: ['nginx', 'docker-compose', 'docker.io', 'certbot', 'python-certbot-nginx']
20
21   - name: request initial letsencrypt certificate
22     command: certbot certonly --nginx --agree-tos -d '{{ domain }}' -m '{{ letsencrypt_contact_email }}'
23     args:
24       creates: '/etc/letsencrypt/live/{{domain}}/privkey.pem'
25
26   - name: create lemmy folder
27     file: path={{item.path}} {{item.owner}} state=directory
28     with_items:
29       - { path: '/lemmy/', owner: 'root' }
30       - { path: '/lemmy/volumes/', owner: 'root' }
31       - { path: '/lemmy/volumes/pictrs/', owner: '991' }
32
33   - block:
34     - name:  add template files
35       template: src={{item.src}} dest={{item.dest}} mode={{item.mode}}
36       with_items:
37         - { src: 'templates/docker-compose.yml', dest: '/lemmy/docker-compose.yml', mode: '0600' }
38         - { src: 'templates/nginx.conf', dest: '/etc/nginx/sites-enabled/lemmy.conf', mode: '0644' }
39         - { src: '../docker/iframely.config.local.js', dest: '/lemmy/iframely.config.local.js', mode: '0600' }
40       vars: 
41         lemmy_docker_image: "dessalines/lemmy:{{ lookup('file', 'VERSION') }}"
42         lemmy_port: "8536"
43         pictshare_port: "8537"
44         iframely_port: "8538"
45
46     - name:  add config file (only during initial setup)
47       template: src='templates/config.hjson' dest='/lemmy/lemmy.hjson' mode='0600' force='no' owner='1000' group='1000'
48     vars:
49       postgres_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/postgres chars=ascii_letters,digits') }}"
50       jwt_password: "{{ lookup('password', 'passwords/{{ inventory_hostname }}/jwt chars=ascii_letters,digits') }}"
51
52   - name: enable and start docker service
53     systemd:
54       name: docker
55       enabled: yes
56       state: started
57
58   - name: start docker-compose
59     docker_compose:
60       project_src: /lemmy/
61       state: present
62       pull: yes
63       remove_orphans: yes
64
65   - name: reload nginx with new config
66     shell: nginx -s reload
67
68   - name: certbot renewal cronjob
69     cron:
70       special_time=daily
71       name=certbot-renew-lemmy
72       user=root
73       job="certbot certonly --nginx -d '{{ domain }}' --deploy-hook 'nginx -s reload'"