Skip to content

Commit

Permalink
plex: remove credentials as they are no longer being used
Browse files Browse the repository at this point in the history
  • Loading branch information
saltydk committed Jul 25, 2024
1 parent 19d0776 commit 42d5036
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 65 deletions.
3 changes: 0 additions & 3 deletions defaults/accounts.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ cloudflare:
dockerhub:
token:
user:
plex:
pass:
user:
user:
domain: testsaltbox.ml
email: your@email.com
Expand Down
26 changes: 26 additions & 0 deletions filter_plugins/plex_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from ansible.errors import AnsibleFilterError
import os
import configparser

class FilterModule(object):
def filters(self):
return {
'check_plex_ini': self.check_plex_ini
}

def check_plex_ini(self, file_path, plex_name):
if not os.path.exists(file_path):
return {'exists': False, 'identifier': '', 'token': ''}

config = configparser.ConfigParser()
config.read(file_path)

if plex_name not in config.sections():
return {'exists': True, 'identifier': '', 'token': ''}

section = config[plex_name]
return {
'exists': True,
'identifier': section.get('client_identifier', ''),
'token': section.get('token', '')
}
12 changes: 3 additions & 9 deletions inventories/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,9 @@ cloudflare_is_enabled: "{{ (cloudflare is defined) and

cloudflare_records_enabled: "{{ cloudflare_is_enabled }}"

plex_account_is_enabled: "{{ (plex is defined) and
(plex is not none) and
(plex | trim | length > 0) and
(plex.user is defined) and
(plex.user is not none) and
(plex.user | trim | length > 0) and
(plex.pass is defined) and
(plex.pass is not none) and
(plex.pass | trim | length > 0) }}"
plex_account_lookup: "{{ '/opt/saltbox/plex.ini' | check_plex_ini(plex_instances[0]) }}"

plex_account_is_enabled: "{{ plex_account_lookup.exists and plex_account_lookup.identifier | length > 0 and plex_account_lookup.token | length > 0 }}"

################################
# Role Conditionals
Expand Down
2 changes: 0 additions & 2 deletions roles/plex/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ plex_instances: ["plex"]
# Settings
################################

plex_username: "{{ plex.user }}"
plex_password: "{{ plex.pass }}"
plex_open_main_ports: false
plex_open_local_ports: false
plex_plugin_webtools: false
Expand Down
57 changes: 20 additions & 37 deletions roles/plex/tasks/subtasks/preferences/claim_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,27 @@
- name: Claim Server | Import plex_auth_token
ansible.builtin.include_role:
name: plex_auth_token
when: plex_account_is_enabled

- name: Claim Server | Get {{ plex_name | title }} claim code via API
when: plex_account_is_enabled
block:
- name: "Claim Server | Get {{ plex_name | title }} claim code"
ansible.builtin.uri:
url: https://plex.tv/api/claim/token.json
method: GET
return_content: yes
body:
X-Plex-Version: "{{ plex_auth_token_version }}"
X-Plex-Product: "{{ plex_auth_token_product }}"
X-Plex-Client-Identifier: "{{ plex_auth_client_identifier }}"
X-Plex-Token: "{{ plex_auth_token }}"
body_format: form-urlencoded
headers:
Accept: "application/json"
status_code: 200
environment: "{{ plex_proxy_dict }}"
register: plex_claim
- name: "Claim Server | Get {{ plex_name | title }} claim code"
ansible.builtin.uri:
url: https://plex.tv/api/claim/token.json
method: GET
return_content: yes
body:
X-Plex-Version: "{{ plex_auth_token_version }}"
X-Plex-Product: "{{ plex_auth_token_product }}"
X-Plex-Client-Identifier: "{{ plex_auth_client_identifier }}"
X-Plex-Token: "{{ plex_auth_token }}"
body_format: form-urlencoded
headers:
Accept: "application/json"
status_code: 200
environment: "{{ plex_proxy_dict }}"
register: plex_claim

- name: "Claim Server | Set 'plex_claim_code' variable"
ansible.builtin.set_fact:
plex_claim_code: "{{ plex_claim.json.token }}"

- name: Claim Server | Get {{ plex_name | title }} claim code via prompts
when: (not plex_account_is_enabled)
block:
- name: "Claim Server | Ask user for {{ plex_name | title }} claim code"
ansible.builtin.pause:
prompt: "Please visit 'https://plex.tv/claim', login with your Plex account,
copy the 'Claim Code', paste it below, and press ENTER."
register: plex_claim_code_prompt

- name: "Claim Server | Set 'plex_claim_code' variable"
ansible.builtin.set_fact:
plex_claim_code: "{{ plex_claim_code_prompt.user_input }}"
- name: "Claim Server | Set 'plex_claim_code' variable"
ansible.builtin.set_fact:
plex_claim_code: "{{ plex_claim.json.token }}"

- name: Claim Server | Assert {{ plex_name | title }} claim code exists
ansible.builtin.assert:
Expand All @@ -59,4 +42,4 @@

- name: "Claim Server | Display {{ plex_name | title }} claim code"
ansible.builtin.debug:
msg: "Using Plex Claim Code{{ ':' }} {{ plex_claim_code }}"
msg: "Using Plex Claim Code {{ plex_claim_code }}"
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,18 @@
---
- name: "Migrator | 'accounts.yml' | Migration 01 | Set variables"
ansible.builtin.set_fact:
plex_tfa_settings: "{{ not ((plex is undefined)
or
(plex is none)
or
(plex | trim | length == 0)
or
(plex.tfa is undefined)
or
(plex.tfa is none)
or
(plex.tfa | trim | length == 0)) }}"
plex_settings: "{{ not ((plex is undefined)
or
(plex is none)
or
(plex | trim | length == 0)) }}"

- name: Migrator | 'adv_settings.yml' | Migration 01 | Delete 'plex.tfa' dict
- name: Migrator | 'adv_settings.yml' | Migration 01 | Delete 'plex' dict
ansible.builtin.shell: |
yyq -i 'del(.plex.tfa)' {{ playbook_dir }}/{{ file }}
yyq -i 'del(.plex)' {{ playbook_dir }}/{{ file }}
become: true
become_user: "{{ saltbox_yml.stat.pw_name }}"
when: plex_tfa_settings
when: plex_settings

- name: Migrator | 'accounts.yml' | Migration 01 | Remove 'null' values
ansible.builtin.replace:
Expand Down

0 comments on commit 42d5036

Please sign in to comment.