peertube.social/peertube.yml

85 lines
3.2 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: create peertube folders
file: path={{item.path}} state=directory
with_items:
- { path: '/peertube/volumes/' }
- { path: '/peertube/volumes/certbot/' }
- { path: '/peertube/volumes/config/' }
- name: copy files
copy: src={{item.src}} dest={{item.dest}} mode={{item.mode}} force={{item.force}}
with_items:
- { src: 'files/docker-daemon.json', dest: '/etc/docker/daemon.json', mode: '0644', force: 'yes' }
- { src: 'files/local-production.json', dest: '/peertube/volumes/config/local-production.json', mode: '0644', force: 'yes' }
- { src: 'files/send-email-to-users.bash', dest: '/peertube/send-email-to-users.bash', mode: '755', force: 'yes' }
- { src: 'files/email-template.txt', dest: '/peertube/email-template.txt', mode: '0644', force: 'no' }
- 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'"