Files
Apps-Community/apps/plexsynctest.yml
2019-01-23 21:14:16 +04:30

113 lines
3.6 KiB
Bash

#!/bin/bash
#
# Title: Plex Database Sync for PlexGuide Community
# Author(s): timekills
# URL: https://plexguide.com - https://github.com/timekills
# GNU: General Public License v3.0
################################################################################
---
- hosts: localhost
gather_facts: false
tasks:
# FACTS #######################################################################
- name: 'Set Known Facts'
set_fact:
pgrole: 'plexsync'
intport: '1700'
extport: '1700'
image: 'nowsci/plex-db-sync'
# CORE (MANDATORY) ############################################################
- name: 'Including cron job'
include_tasks: '/opt/plexguide/containers/_core.yml'
# LABELS ######################################################################
- name: 'Adding Traefik'
set_fact:
pg_labels:
traefik.enable: 'true'
traefik.port: '{{intport}}'
traefik.frontend.auth.forward.address: '{{gauth}}'
traefik.frontend.rule: 'Host:plexsync.{{domain.stdout}},{{tldset}}'
- name: 'Setting PG Volumes'
set_fact:
pg_volumes:
- '/opt/appdata/{{pgrole}}:/config:rw'
- 'S1_SSH_KEY=/sshkey'
- '/config/Library/Application Support/Plex Media Server/Plug-in Support/Databases/:/mnt/DB2
- '/etc/localtime:/etc/localtime:ro'
- name: 'Setting PG ENV'
set_fact:
pg_env:
USER_ID: 1000
GROUP_ID: 1000
KEEP_APP_RUNNING: 1
S1_SSH_USER: "root"
S1_SSH_HOST: "ssh.timekills.info"
S1_SSH_PORT: "22"
S1_SSH_PATH: "/config/Library/Application Support/Plex Media Server/Plug-in Support/Databases"
S1_START: "ssh -oStrictHostKeyChecking=no -i /sshkey root@ssh.timekills.info 'cd /; docker start plex'"
S1_STOP: "ssh -oStrictHostKeyChecking=no -i /sshkey root@ssh.timekills.info 'cd /; docker stop plex'"
S2_DB_PATH: "/mnt/DB2"
S2_START: "cd /; docker start plex"
S2_STOP: "cd /; docker stop plex"
BACKUP: "true"
DRYRUN: "true"
# MAIN DEPLOYMENT #############################################################
- name: 'Deploying {{pgrole}}'
docker_container:
name: '{{pgrole}}'
image: '{{image}}'
pull: yes
published_ports:
- '{{ports.stdout}}{{extport}}:{{intport}}'
volumes: '{{pg_volumes}}'
env: '{{pg_env}}'
restart_policy: unless-stopped
networks:
- name: plexguide
aliases:
- '{{pgrole}}'
state: started
labels: '{{pg_labels}}'
- name: 'Wait 7 Seconds'
wait_for:
timeout: 7
- name: Stop Container
docker_container:
name: '{{pgrole}}'
state: stopped
# ENDING FOR PLEXSYNC ###########################################################
# - name: 'Waiting for {{pgrole}} to initialize'
# wait_for:
# path: '/opt/appdata/{{pgrole}}/core.conf'
# state: present
- name: 'Configuring {{pgrole}} for first time use'
block:
- name: 'Stopping {{pgrole}}'
docker_container:
name: '{{pgrole}}'
state: stopped
# - name: Setting plugins directory
# lineinfile:
# path: '/opt/appdata/{{pgrole}}/core.conf'
# regexp: '"plugins_location"'
# line: '"plugins_location": "/config/plugins",'
# state: present
- name: Restart Container
docker_container:
name: '{{pgrole}}'
state: started