|
46 | 46 | - name: "Check if 'Preferences.xml' exists" |
47 | 47 | stat: |
48 | 48 | 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) |
105 | 76 |
|
106 | 77 | - name: "Grab lazyman IP address" |
107 | 78 | set_fact: |
|
0 commit comments