Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 5fd7a1f

Browse files
committed
Plex: Reclaim server when PlexOnlineToken is missing.
1 parent 8a5810f commit 5fd7a1f

File tree

2 files changed

+79
-56
lines changed

2 files changed

+79
-56
lines changed

roles/plex/tasks/main.yml

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -46,62 +46,33 @@
4646
- name: "Check if 'Preferences.xml' exists"
4747
stat:
4848
path: "/opt/plex/Library/Application Support/Plex Media Server/Preferences.xml"
49-
register: plex_prefs
50-
51-
- name: "Get Plex server claim code"
52-
uri:
53-
url: https://plex.tv/api/claim/token.json
54-
user: "{{ plex.user }}"
55-
password: "{{ plex.pass }}"
56-
force_basic_auth: yes
57-
register: plex_claim
58-
when: plex_account_enabled and not (
59-
(plex_prefs.stat.exists)
60-
or
61-
(continuous_integration)
62-
)
63-
64-
- name: "Set 'plex_claim_code' variable"
65-
set_fact:
66-
plex_claim_code: "{{ plex_claim.json.token }}"
67-
when: plex_account_enabled and not (
68-
(plex_prefs.stat.exists)
69-
or
70-
(continuous_integration)
71-
)
72-
73-
- name: "Ask user for Plex server claim code"
74-
pause:
75-
prompt: "Please visit 'https://plex.tv/claim', login with your Plex account, copy the Claim Code, paste it below, and press ENTER."
76-
register: plex_claim_code_prompt
77-
when: not (
78-
(plex_prefs.stat.exists)
79-
or
80-
(plex_account_enabled)
81-
or
82-
(continuous_integration)
83-
)
84-
85-
- name: "Set 'plex_claim_code' variable"
86-
set_fact:
87-
plex_claim_code: "{{ plex_claim_code_prompt.user_input }}"
88-
when: not (
89-
(plex_prefs.stat.exists)
90-
or
91-
(plex_account_enabled)
92-
or
93-
(continuous_integration)
94-
)
95-
96-
- name: "Display Plex server claim code"
97-
debug: msg="Using Plex Claim Code{{ ':' }} {{ plex_claim_code }}"
98-
when: not (
99-
(plex_claim_code is undefined)
100-
or
101-
(plex_claim_code is none)
102-
or
103-
(plex_claim_code | trim | length == 0)
104-
)
49+
register: preferences_xml
50+
51+
- name: Check 'Preferences.xml' for Plex Token
52+
block:
53+
54+
- name: Get 'Preferences.xml' XML data
55+
xml:
56+
path: "/opt/plex/Library/Application Support/Plex Media Server/Preferences.xml"
57+
xpath: /Preferences
58+
content: attribute
59+
attribute: PlexOnlineToken
60+
register: preferences_xml_resp
61+
62+
- name: Set 'claimed_plex_server' variable
63+
set_fact:
64+
claimed_plex_server: "{{ (preferences_xml_resp.matches[0].Preferences.PlexOnlineToken is defined)
65+
and (preferences_xml_resp.matches[0].Preferences.PlexOnlineToken | trim | length > 0) }}"
66+
67+
when:
68+
- (not continuous_integration)
69+
- (preferences_xml.stat.exists)
70+
71+
- name: Claim Plex Server
72+
import_tasks: subtasks/claim_server.yml
73+
when:
74+
- (not continuous_integration)
75+
- (not preferences_xml.stat.exists) or (preferences_xml.stat.exists and not claimed_plex_server)
10576

10677
- name: "Grab lazyman IP address"
10778
set_fact:
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
##########################################################################
2+
# Title: Plex: Claim Server #
3+
# Author(s): desimaniac #
4+
# URL: https://github.com/cloudbox/cloudbox #
5+
# -- #
6+
# Part of the Cloudbox project: https://cloudbox.works #
7+
##########################################################################
8+
# GNU General Public License v3.0 #
9+
##########################################################################
10+
---
11+
- name: Get Plex Media Server claim code via API
12+
block:
13+
14+
- name: "Get Plex Media Server claim code"
15+
uri:
16+
url: https://plex.tv/api/claim/token.json
17+
user: "{{ plex.user }}"
18+
password: "{{ plex.pass }}"
19+
force_basic_auth: yes
20+
register: plex_claim
21+
22+
- name: "Set 'plex_claim_code' variable"
23+
set_fact:
24+
plex_claim_code: "{{ plex_claim.json.token }}"
25+
26+
when: (plex_account_enabled)
27+
28+
- name: Get Plex Media Server claim code via prompts
29+
block:
30+
31+
- name: "Ask user for Plex Media Server claim code"
32+
pause:
33+
prompt: "Please visit 'https://plex.tv/claim', login with your Plex account,
34+
copy the 'Claim Code', paste it below, and press ENTER."
35+
register: plex_claim_code_prompt
36+
37+
- name: "Set 'plex_claim_code' variable"
38+
set_fact:
39+
plex_claim_code: "{{ plex_claim_code_prompt.user_input }}"
40+
41+
when: (not plex_account_enabled)
42+
43+
- name: Assert Plex Media Server claim code exists
44+
assert:
45+
that:
46+
- "plex_claim_code is defined"
47+
- "plex_claim_code is not none"
48+
- "plex_claim_code | trim | length > 0"
49+
50+
- name: "Display Plex Media Server claim code"
51+
debug:
52+
msg: "Using Plex Claim Code{{ ':' }} {{ plex_claim_code }}"

0 commit comments

Comments
 (0)