adc/ansible/roles/mediaserver/tasks/main.yml

110 lines
2.9 KiB
YAML

---
# deploy a media server from scratch.
# boot strap server
- name: Install aptitude using apt
apt: name=aptitude state=latest update_cache=yes force_apt_get=yes
- name: Install required system packages for docker install
apt: name={{ item }} state=latest update_cache=yes
loop: [ 'apt-transport-https', 'ca-certificates', 'software-properties-common' ]
- name: Add Docker GPG apt Key
apt_key:
url: https://download.docker.com/linux/debian/gpg
state: present
- name: Add Docker Repository
apt_repository:
repo: deb https://download.docker.com/linux/ubuntu bionic stable
state: present
- name: Update apt
apt: update_cache=yes
- name: Install required system packages
apt: name={{ sys_packages }} state=latest
- name: add 'josiah' to docker group
user:
name='josiah'
groups=docker
append=yes
- name: Init a new swarm with default parameters
community.general.docker_swarm:
state: present
# set up mediaserver specific bullshit.
- name: ensure traefik config directory exists
file: state=directory path=/home/josiah/apps/traefik/ owner=josiah group=josiah mode=0700
- name: ensure the webdav-docker repo exists
git:
repo: 'https://git.awful.club/hosted/webdav-docker.git'
dest: /home/josiah/apps/webdav-docker/
version: master
- name: build jlj-webdav image
community.general.docker_image:
name: jlj-webdav
build:
path: /home/josiah/apps/webdav-docker/latest
dockerfile: Dockerfile
source: build
- name: ensure mediaserver config directory exists
file: state=directory path=/home/josiah/apps/mediaserver/ owner=josiah group=josiah mode=0700
- name: ensure traefik.log exists
file: state=file path=/home/josiah/apps/traefik/traefik.log owner=josiah group=josiah mode=0700
- name: allow for pretty json errors
pip:
name: jsondiff
- name: Create deploy configs dir if it does not exist
file:
path: /home/josiah/deploys/mediaserver
state: directory
mode: '0755'
- name: copy over mediaserver config files
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: 0777
with_items:
- {src: 'mediaserver-compose.yml', dest: '/home/josiah/apps/mediaserver/mediaserver-compose.yml'}
- {src: 'traefik.yml.j2', dest: '/home/josiah/apps/traefik/traefik.yml'}
- name: Ensure acme.json exists
copy:
content: ""
dest: /home/josiah/apps/traefik/acme.json
force: no
owner: root
group: root
state: file
mode: '0600'
- name: Remove the mediaserver stack
block:
- name: Remove the mediaserver stack
docker_stack:
state: absent
name: mediaserver
compose:
- /home/josiah/apps/mediaserver/mediaserver-compose.yml
- name: Pause so the network gets deleted too
pause:
seconds: 15
- name: Deploy mediaserver stack
docker_stack:
state: present
name: mediaserver
prune: yes
compose:
- /home/josiah/apps/mediaserver/mediaserver-compose.yml