Files
Apps-Community/apps/deluge-vpn.yml
2019-07-29 15:50:37 -07:00

324 lines
11 KiB
Bash

#!/bin/bash
#
# Title: PGBlitz (Reference Title File)
# Author(s): Admin9705
# URL: https://pgblitz.com - http://github.pgblitz.com
# GNU: General Public License v3.0
################################################################################
---
- hosts: localhost
gather_facts: false
tasks:
# FACTS #######################################################################
- name: 'Set Known Facts'
set_fact:
pgrole: 'deluge'
intport: '8112'
extport: '8112'
intport2: '58846'
extport2: '58846'
intport3: '58946'
extport3: '58946'
intport4: '5418'
extport4: '5418'
intport5: '5419'
extport5: '5419'
intport6: '8118'
extport6: '8118'
image: 'binhex/arch-delugevpn'
# CORE (MANDATORY) ############################################################
- name: 'Including cron job'
include_tasks: '/opt/communityapps/apps/_core.yml'
- name: 'Including folders'
include_tasks: '/opt/communityapps/apps/_downloaders.yml'
- name: 'Checking for existing app data'
stat:
path: /opt/appdata/{{pgrole}}/core.conf
register: confcheck
# LABELS ######################################################################
- name: 'Adding Traefik'
set_fact:
pg_labels:
traefik.frontend.auth.forward.address: '{{gauth}}'
traefik.enable: 'true'
traefik.port: '{{intport}}'
traefik.frontend.rule: 'Host:{{pgrole}}.{{domain.stdout}}{{tldset}}{{cname}}'
traefik.frontend.headers.SSLHost: '{{domain.stdout}}'
traefik.frontend.headers.SSLRedirect: 'true'
traefik.frontend.headers.STSIncludeSubdomains: 'true'
traefik.frontend.headers.STSPreload: 'true'
traefik.frontend.headers.STSSeconds: '315360000'
traefik.frontend.headers.browserXSSFilter: 'true'
traefik.frontend.headers.contentTypeNosniff: 'true'
traefik.frontend.headers.customResponseHeaders: 'X-Robots-Tag:noindex,nofollow,nosnippet,noarchive,notranslate,noimageindex'
traefik.frontend.headers.forceSTSHeader: 'true'
- name: 'Setting PG Volumes'
set_fact:
pg_volumes:
- '/opt/appdata/{{pgrole}}:/config'
- '{{path.stdout}}:{{path.stdout}}'
- '/etc/localtime:/etc/localtime:ro'
- '/mnt:/mnt'
- name: 'Setting PG ENV'
set_fact:
pg_env:
PUID: '1000'
PGID: '1000'
VPN_ENABLED: yes
VPN_USER: vpnuser
VPN_PASS: vpnpass
VPN_PROV: custom
ENABLE_PRIVOXY: no
STRICT_PORT_FORWARD: no
LAN_NETWORK: 192.168.1.1/24
# MAIN DEPLOYMENT #############################################################
- name: 'Deploying {{pgrole}}'
docker_container:
name: '{{pgrole}}'
image: '{{image}}'
pull: yes
published_ports:
- '{{ports.stdout}}{{extport}}:{{intport}}'
- '{{ports.stdout}}{{extport2}}:{{intport2}}'
- '{{ports.stdout}}{{extport3}}:{{intport3}}'
- '{{extport4}}:{{intport4}}'
- '{{extport5}}:{{intport5}}'
- '{{ports.stdout}}{{extport6}}:{{intport6}}'
volumes: '{{pg_volumes}}'
env: '{{pg_env}}'
restart_policy: unless-stopped
networks:
- name: plexguide
aliases:
- '{{pgrole}}'
state: started
labels: '{{pg_labels}}'
# CONFIGURATION ###########################################################
- name: 'Waiting for {{pgrole}} to initialize'
wait_for:
timeout: 10
- name: Stopping {{pgrole}}
docker_container:
name: '{{pgrole}}'
state: stopped
- name: 'Checking for appdata'
wait_for:
path: '/opt/appdata/{{pgrole}}/core.conf'
state: present
delay: 5
- name: Setting plugins directory
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"plugins_location".*'
line: '"plugins_location": "/config/plugins",'
state: present
- name: Set move completed location
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"move_completed_path".*'
line: '"move_completed_path": "{{path.stdout}}/downloads/{{pgrole}}",'
state: present
- name: Set download location
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"download_location".*'
line: '"download_location": "{{path.stdout}}/incomplete/{{pgrole}}",'
state: present
- name: Setting torrent file directory
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"torrentfiles_location".*'
line: '"torrentfiles_location": "{{path.stdout}}/torrent",'
state: present
- name: Setting torrent watch directory
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"autoadd_location".*'
line: '"autoadd_location": "{{path.stdout}}/torrent/watch",'
state: present
- name: Setting move_completed
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"move_completed".*'
line: '"move_completed": True,'
state: present
- name: Setting extractor folder
lineinfile:
path: '/opt/appdata/{{pgrole}}/plugins/extractor.conf'
regexp: '"use_name_folder".*'
line: '"use_name_folder": True,'
state: present
- name: Setting extractor
lineinfile:
path: '/opt/appdata/{{pgrole}}/plugins/extractor.conf'
regexp: '"extract_path".*'
line: '"extract_path": "{{path.stdout}}/downloads/deluge"'
state: present
# FIRST TIME CONFIGURATION ####################################################
- name: 'Configuring {{pgrole}} for first time use'
block:
- name: set enabled_plugins
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"enabled_plugins".*'
line: '"enabled_plugins": ["Extractor", "Label"],'
state: present
- name: set compact_allocation
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"compact_allocation".*'
line: '"compact_allocation": True,'
state: present
- name: set stop_seed_ratio
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"stop_seed_ratio"".*'
line: '"stop_seed_ratio": 1.0,'
state: present
- name: set share_ratio_limit
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"share_ratio_limit".*'
line: '"share_ratio_limit": 1.0,'
state: present
- name: set remove_seed_at_ratio
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"remove_seed_at_ratio".*'
line: '"remove_seed_at_ratio": True,'
state: present
- name: set enc_prefer_rc4
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"enc_prefer_rc4".*'
line: '"enc_prefer_rc4": True,'
state: present
- name: set enc_level
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"enc_level".*'
line: '"enc_level": 1,'
state: present
- name: set enc_in_policy
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"enc_in_policy".*'
line: '"enc_in_policy": 1,'
state: present
- name: set enc_out_policy
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"enc_out_policy".*'
line: '"enc_out_policy": 1,'
state: present
- name: set max_active_downloading
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"max_active_downloading".*'
line: '"max_active_downloading": 4,'
state: present
- name: set dont_count_slow_torrents
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"dont_count_slow_torrents".*'
line: '"dont_count_slow_torrents": True,'
state: present
- name: set max_active_seeding
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"enabled_plugins".*'
line: '"max_active_seeding": 8,'
state: present
- name: set share_ratio_limit
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"share_ratio_limit".*'
line: '"share_ratio_limit": 1,'
state: present
- name: set stop_seed_at_ratio
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"stop_seed_at_ratio".*'
line: '"stop_seed_at_ratio": 1.0,'
state: present
- name: set seed_time_ratio_limit
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"seed_time_ratio_limit".*'
line: '"seed_time_ratio_limit": 1.0,'
state: present
- name: set outgoing_ports
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"outgoing_ports".*'
line: '"outgoing_ports": [{{intport5}}, {{intport5}}],'
state: present
- name: set random_port
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"random_port".*'
line: '"random_port": false,'
state: present
- name: set random_outgoing_ports
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"random_outgoing_ports".*'
line: '"random_outgoing_ports": false,'
state: present
- name: set listen_random_port
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"listen_random_port".*'
line: '"listen_random_port": null,'
state: present
- name: set listen_ports
lineinfile:
path: '/opt/appdata/{{pgrole}}/core.conf'
regexp: '"listen_ports".*'
line: '"listen_ports": [{{intport4}},{{intport4}}],'
state: present
when: not confcheck.stat.exists
- name: Restart {{pgrole}}
docker_container:
name: '{{pgrole}}'
state: started