From 42d5036c2de6e0ece58fa0a7cf285f11324d5d74 Mon Sep 17 00:00:00 2001 From: saltydk Date: Fri, 26 Jul 2024 00:20:42 +0200 Subject: [PATCH] plex: remove credentials as they are no longer being used --- defaults/accounts.yml.default | 3 - filter_plugins/plex_filters.py | 26 +++++++++ inventories/group_vars/all.yml | 12 +--- roles/plex/defaults/main.yml | 2 - .../subtasks/preferences/claim_server.yml | 57 +++++++------------ .../migrator/accounts_yml/migration_01.yml | 22 +++---- 6 files changed, 57 insertions(+), 65 deletions(-) create mode 100644 filter_plugins/plex_filters.py diff --git a/defaults/accounts.yml.default b/defaults/accounts.yml.default index c677871e88..a6a672d959 100644 --- a/defaults/accounts.yml.default +++ b/defaults/accounts.yml.default @@ -6,9 +6,6 @@ cloudflare: dockerhub: token: user: -plex: - pass: - user: user: domain: testsaltbox.ml email: your@email.com diff --git a/filter_plugins/plex_filters.py b/filter_plugins/plex_filters.py new file mode 100644 index 0000000000..90f4590b7d --- /dev/null +++ b/filter_plugins/plex_filters.py @@ -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', '') + } diff --git a/inventories/group_vars/all.yml b/inventories/group_vars/all.yml index c21fb35133..5e6e6da23a 100644 --- a/inventories/group_vars/all.yml +++ b/inventories/group_vars/all.yml @@ -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 diff --git a/roles/plex/defaults/main.yml b/roles/plex/defaults/main.yml index df7892291c..75e6380c03 100644 --- a/roles/plex/defaults/main.yml +++ b/roles/plex/defaults/main.yml @@ -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 diff --git a/roles/plex/tasks/subtasks/preferences/claim_server.yml b/roles/plex/tasks/subtasks/preferences/claim_server.yml index 1b65299904..1a499fb00c 100644 --- a/roles/plex/tasks/subtasks/preferences/claim_server.yml +++ b/roles/plex/tasks/subtasks/preferences/claim_server.yml @@ -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: @@ -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 }}" diff --git a/roles/settings/tasks/subtasks/migrator/accounts_yml/migration_01.yml b/roles/settings/tasks/subtasks/migrator/accounts_yml/migration_01.yml index cce01a007c..abc061c637 100644 --- a/roles/settings/tasks/subtasks/migrator/accounts_yml/migration_01.yml +++ b/roles/settings/tasks/subtasks/migrator/accounts_yml/migration_01.yml @@ -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: