forked from PGBlitz/Apps-Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plex.yml
289 lines (258 loc) · 10.2 KB
/
plex.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/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: 'plex'
intport: '32400/tcp'
extport: '32400'
intport2: '3005/tcp'
extport2: '3005'
intport3: '8324/tcp'
extport3: '8324'
intport4: '32410/udp'
extport4: '32410'
intport5: '32412/udp'
extport5: '32412'
intport6: '32413/udp'
extport6: '32413'
intport7: '32414/udp'
extport7: '32414'
intport8: '33400/tcp'
extport8: '33400'
intport9: '33443/tcp'
extport9: '33443'
image: 'plexinc/pms-docker:latest'
# CORE (MANDATORY) ############################################################
- name: 'Including cron job'
include_tasks: '/opt/coreapps/apps/_core.yml'
# FACTS #######################################################################
- name: 'Plex Server Network Type'
shell: 'cat /var/plexguide/plex.server'
register: servertype
- name: Register Claim Number
shell: 'cat /var/plexguide/plex.claim'
register: claim
when: servertype.stdout == "remote"
# CORE (MANDATORY) ############################################################
- name: 'Including cron job'
include_tasks: '/opt/coreapps/apps/_core.yml'
######################################### FOR BOTH
- name: 'Set Default Labels'
set_fact:
default_labels:
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: 'Set Default Volume - {{extension.stdout}}'
set_fact:
default_volumes:
- '/etc/localtime:/etc/localtime:ro'
- '{{path.stdout}}:{{path.stdout}}'
- '/mnt:/mnt'
- '/opt/appdata/{{pgrole}}/database:/config'
- '/tmp:/tmp'
- '/opt/transcodes:/transcode'
- '/dev/shm:/ram_transcode'
- name: 'Establish Key Variables'
set_fact:
default_env:
UID: '1000'
GID: '1000'
- name: Check Preferences.xml exists
stat:
path: '/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Preferences.xml'
register: plex_prefs
############### This is needed because on a fresh installaions the value is missing and is defaulted to 1 Security perfered
- name: secureConnections is missing
xml:
path: '/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Preferences.xml'
xpath: /Preferences/@secureConnections
count: yes
register: secure_hits
when:
- plex_prefs.stat.exists
############### This is needed because on a fresh installaions the value is missing and is defaulted to 1 Security perfered
- name: Add secureConnections if missing
xml:
path: '/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Preferences.xml'
xpath: /Preferences
attribute: secureConnections
value: '1'
when:
- plex_prefs.stat.exists
- secure_hits.count == 0
- name: Read Preferences.xml
xml:
path: '/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Preferences.xml'
xpath: /Preferences
content: attribute
register: plex_pref_content
when: plex_prefs.stat.exists
- name: Add https to default_label if secureConnection != 2
set_fact:
default_labels: "{{default_labels | combine( {'traefik.protocol': 'https'} )}}"
when:
- plex_prefs.stat.exists
- plex_pref_content.matches[0]['Preferences']['secureConnections']
- name: Read customConnections
set_fact:
customConnections: "{{plex_pref_content.matches[0]['Preferences']['customConnections']}}"
when:
- plex_prefs.stat.exists
- plex_pref_content.matches[0]['Preferences']['customConnections'] is defined
- name: customConnections missing
set_fact:
customConnections: 'http://{{ipaddress.stdout}}:32400, http://plex.{{domain.stdout}}:32400'
when:
- plex_prefs.stat.exists == False
- name: 'Get Plex Custom URL'
shell: 'echo https://plex.{{domain.stdout}}:443,http://plex.{{domain.stdout}}:80'
register: plex_url
when: servertype.stdout == "remote"
- debug: msg="Your plex_url is {{ plex_url.stdout }}"
when: servertype.stdout == "remote"
- set_fact:
plex_advert_ip: 'http://{{ipaddress.stdout}}:32400'
when: servertype.stdout == "remote"
- set_fact:
plex_advert_ip: '{{plex_url.stdout}}'
when: servertype.stdout == "remote"
- debug: msg="plex_advert_ip is {{plex_advert_ip}}"
when: servertype.stdout == "remote"
########################################## Other
- name: Check /dev/dri exists
stat:
path: '/dev/dri'
register: dev_dri
- name: Create Transcodes Directory
file: 'path={{item}} state=directory mode=0775 owner=1000 group=1000'
with_items:
- /opt/transcodes
- name: customConnections FailSafe
set_fact:
customConnections: 'none'
when: customConnections is undefined
######################################### DEPLOY PLEX REMOTE (ANSWER 2)
- name: Deploy Plex Container (Remote Edition)
docker_container:
name: plex
image: '{{image}}'
pull: yes
published_ports:
- '{{extport}}:{{intport}}'
- '{{ports.stdout}}{{extport2}}:{{intport2}}'
- '{{ports.stdout}}{{extport3}}:{{intport3}}'
- '{{ports.stdout}}{{extport4}}:{{intport4}}'
- '{{ports.stdout}}{{extport5}}:{{intport5}}'
- '{{ports.stdout}}{{extport6}}:{{intport6}}'
- '{{ports.stdout}}{{extport7}}:{{intport7}}'
- '{{ports.stdout}}{{extport8}}:{{intport8}}'
- '{{extport9}}:{{intport9}}'
env:
PLEX_UID: '1000'
PLEX_GID: '1000'
PLEX_CLAIM: '{{claim.stdout}}'
ADVERTISE_IP: '{{customConnections}}'
NVIDIA_VISIBLE_DEVICES: 'all'
NVIDIA_DRIVER_CAPABILITIES: 'compute,video,utility'
purge_networks: yes
networks:
- name: plexguide
aliases:
- plex
volumes: '{{default_volumes}}'
devices: "{{ '/dev/dri:/dev/dri' if dev_dri.stat.exists == True | default(false) else omit }}"
etc_hosts:
{ 'analytics.plex.tv': '127.0.0.1', 'metrics.plex.tv': '127.0.0.1' }
restart_policy: unless-stopped
state: started
labels: '{{default_labels}}'
when: servertype.stdout == "remote"
######################################### DEPLOY PLEX LOCAL (ANSWER 3)
- name: Deploy Plex Container (Local Edition)
docker_container:
name: plex
image: '{{image}}'
pull: yes
published_ports:
- '32400:32400/tcp'
- '3005:3005/tcp'
- '8324:8324/tcp'
- '32469:32469/tcp'
- '1900:1900/udp'
- '32410:32410/udp'
- '32412:32412/udp'
- '32413:32413/udp'
- '32414:32414/udp'
- '33400:33400/tcp'
- '33443:33443/tcp'
env:
PLEX_UID: '1000'
PLEX_GID: '1000'
ADVERTISE_IP: '{{customConnections}}'
NVIDIA_VISIBLE_DEVICES: 'all'
NVIDIA_DRIVER_CAPABILITIES: 'compute,video,utility'
networks:
- name: plexguide
aliases:
- plex
volumes: '{{default_volumes}}'
devices: "{{ '/dev/dri:/dev/dri' if dev_dri.stat.exists == True | default(false) else omit }}"
etc_hosts:
{ 'analytics.plex.tv': '127.0.0.1', 'metrics.plex.tv': '127.0.0.1' }
restart_policy: unless-stopped
state: started
labels: '{{default_labels}}'
when: servertype.stdout == "local"
###################### Plex WebTools
- name: Check WebTools
stat:
path: '/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-ins/WebTools.bundle'
register: webtools
- name: Create Basic Directories
file: 'path={{item}} state=directory mode=0775 owner=1000 group=1000'
with_items:
- '/opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-ins/WebTools.bundle'
when:
- webtools.stat.exists == False
- name: Installing WebTools
unarchive:
src: https://github.com/ukdtom/WebTools.bundle/releases/download/3.0.0/WebTools.bundle.zip
dest: /opt/appdata/plex/database/Library/Application Support/Plex Media Server/Plug-ins
keep_newer: no
owner: '1000'
group: '1000'
mode: 0775
copy: no
when:
- webtools.stat.exists == False
- name: Notify User
pause:
prompt: "\nWebTools Installed! [PRESS ENTER] to Continue"
when:
- webtools.stat.exists == False
- debug: msg="Final Notes - Remote Plex | IP Address {{ipaddress.stdout}} | Plex Type {{servertype.stdout}} | Token {{claim.stdout}}"
when: servertype.stdout == "remote"
- debug: msg="Final Notes - Local Plex | IP Address {{ipaddress.stdout}} | Plex Type {{servertype.stdout}}"
when: servertype.stdout == "local"
##PG-Core
##PG-Core