peertube.social/peertube.yml
2020-04-01 18:51:42 +02:00

79 lines
2.7 KiB
YAML

---
- hosts: all
# Install python if required
# https://www.josharcher.uk/code/ansible-python-connection-failure-ubuntu-server-1604/
gather_facts: False
pre_tasks:
- name: install python for Ansible
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal python-setuptools)
args:
executable: /bin/bash
register: output
changed_when: output.stdout != ""
- setup: # gather facts
tasks:
- name: install dependencies
apt:
pkg: ['docker-compose', 'docker.io', 'certbot']
- name: copy docker config
copy: src='files/docker-daemon.json' dest='/etc/docker/daemon.json' mode='0644'
- name: create peertube folder
file: path={{item.path}} state=directory
with_items:
- { path: '/peertube/volumes/' }
- { path: '/peertube/volumes/certbot/' }
- name: get latest peertube version from github
uri:
url: https://api.github.com/repos/Chocobozzz/PeerTube/releases/latest
return_content: true
register: peertube_version_response
check_mode: no
- debug:
msg: "Using Peertube version {{ peertube_version_response.json.tag_name }}"
- name: check to make sure the specified tag exists
docker_image:
name: "chocobozzz/peertube:{{ peertube_version_response.json.tag_name }}-buster"
source: pull
- name: add all template files
template: src={{item.src}} dest={{item.dest}} mode={{item.mode}}
with_items:
- { src: 'templates/docker-compose.yml.j2', dest: '/peertube/docker-compose.yml', mode: '0644' }
- { src: 'templates/nginx.conf.j2', dest: '/peertube/nginx.conf', mode: '0644' }
- { src: 'templates/env.j2', dest: '/peertube/.env', mode: '0600' }
- { src: 'templates/peertube-production.yaml.j2', dest: '/peertube/volumes/config/production.yaml', mode: '0600' }
vars:
peertube_version: "{{ peertube_version_response.json.tag_name }}"
- name: request letsencrypt certificates
command: certbot certonly --standalone --agree-tos -d '{{ domain }}' -m '{{ letsencrypt_contact_email }}'
args:
creates: '/etc/letsencrypt/live/{{domain}}/privkey.pem'
- name: enable and start docker service
systemd:
name: docker
enabled: yes
state: started
- name: start docker-compose
docker_compose:
project_src: /peertube/
state: present
pull: yes
# TODO: might need to restart peertube if production.yaml was changed
- name: renew certbot certificates
cron:
special_time=daily
name=certbot-renew
user=root
job="certbot certonly --webroot --webroot-path=/peertube/volumes/certbot/ -d '{{ domain }}' --deploy-hook 'docker-compose -f /peertube/docker-compose.yml exec nginx nginx -s reload'"