From 2f8b9cf0c47aa8ad8b3acf1cbb8a1e24b5c9c339 Mon Sep 17 00:00:00 2001 From: Matt Schreiber Date: Sun, 17 Mar 2024 21:11:48 -0400 Subject: [PATCH 1/2] fix(tests): ensure `kodi_codename` is defined to avoid an undefined variable error on LibreELEC when expanding the URL of the official Kodi repository URL. Do this by (a) filtering the special `omit` token from the `kodi_repositories` list, (b) getting rid of the `set_fact` task that extends `kodi_repositories` on LibreELEC only, and (c) replacing it with an entry in `kodi_repositories` that evaluates to a repository URL on LibreELEC and `omit` on other distributions. Taken together, this permits deferring the evaluation of `kodi_codename` until that variable has been initializaed by the `facts.yml` tasks file. --- tasks/main.yml | 2 +- tests/test.yml | 47 ++++++++++++++++++----------------------------- vars/main.yml | 6 +++++- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 3485fb8..c16b5be 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -316,7 +316,7 @@ become_user: "{{ kodi_user }}" become: True environment: - REPOSITORIES: "{{ kodi_repositories | map('quote') | list | join(' ') }}" + REPOSITORIES: "{{ kodi_repositories_final | map('quote') | list | join(' ') }}" ENABLED_REPOSITORIES: "{{ kodi_enabled_repositories | map('quote') | list | join(' ') }}" KODI_USER: "{{ kodi_user }}" KODI_DATA_DIR: "{{ kodi_data_dir }}" diff --git a/tests/test.yml b/tests/test.yml index ee5b4d3..b792cb5 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -35,34 +35,6 @@ - hosts: all become: True - vars: - # Define this structure here, rather than in the `role` application stanza, - # so that we can extend it with the LibreELEC repository for LibreELEC - # hosts only. - kodi_repositories: - - 'official_cached=https://mirrors.kodi.tv/addons/{{ kodi_codename }}/addons.xml.gz' - - 'jellyfin_cached=https://repo.jellyfin.org/releases/client/kodi/addons.xml' - - 'sandmann79_cached=https://raw.githubusercontent.com/Sandmann79/xbmc/master/packages/addons.xml' - - 'sandmann79_py3_cached=https://raw.githubusercontent.com/Sandmann79/xbmc/master/packages-py3/addons.xml' - pre_tasks: - # The LibreELEC repository used to appear statically in the main - # `kodi_repositories` definition, but LibreELEC does aggressive - # rate-limiting on their repository, causing this playbook to fail from - # connection and/or HTTP errors. - # - # Reference for LibreELEC repository rate-limiting: - # https://forum.libreelec.tv/thread/26597-add-on-repository-problems-2024-03/?pageNo=1 - # - # Note that LibreELEC appears to namespace addons under the path - # `.0.0`; for instance, the addon repository URL - # for LibreELEC release 11.0.6 is `https://addons.libreelec.tv/11.0.0/`. - - name: 'test | add LibreELEC repository for LibreELEC hosts' - set_fact: - kodi_repositories: '{{ - kodi_repositories + [("libreelec_cached=https://addons.libreelec.tv/" ~ ansible_distribution_major_version ~ ".0.0/Generic/x86_64/addons.xml.gz")] - }}' - when: 'ansible_distribution == "LibreELEC"' - # NOTE that `kodi-inputstream-adaptive` does not ship with the base Kodi # package, so we have to install `kodi-addon-inputstream-adaptive` on Arch # Linux, and `kodi-inputstream-adaptive` elsewhere. @@ -104,10 +76,27 @@ - repository.sandmann79-py3.plugins - 'repository.jellyfin.kodi=https://repo.jellyfin.org/releases/client/kodi/repository.jellyfin.kodi.zip' - plugin.video.youtube - - plugin.video.amazon-test - plugin.video.jellyfin - script.module.amazoncaptcha - plugin.video.amazon-test + kodi_repositories: + - 'official_cached=https://mirrors.kodi.tv/addons/{{ kodi_codename }}/addons.xml.gz' + - 'jellyfin_cached=https://repo.jellyfin.org/releases/client/kodi/addons.xml' + - 'sandmann79_cached=https://raw.githubusercontent.com/Sandmann79/xbmc/master/packages/addons.xml' + - 'sandmann79_py3_cached=https://raw.githubusercontent.com/Sandmann79/xbmc/master/packages-py3/addons.xml' + # The LibreELEC repository used to appear statically in the main + # `kodi_repositories` definition, but LibreELEC does aggressive + # rate-limiting on their repository, causing this playbook to fail + # from connection and/or HTTP errors. + # + # Reference for LibreELEC repository rate-limiting: + # https://forum.libreelec.tv/thread/26597-add-on-repository-problems-2024-03/?pageNo=1 + # + # Note that LibreELEC appears to namespace addons under the path + # `.0.0`; for instance, the addon repository + # URL for LibreELEC release 11.0.6 is + # `https://addons.libreelec.tv/11.0.0/`. + - '{{ (ansible_distribution == "LibreELEC") | ternary( ("libreelec_cached=https://addons.libreelec.tv/" ~ ansible_distribution_major_version ~ ".0.0/Generic/x86_64/addons.xml.gz"), omit) }}' kodi_config: - file: 'userdata/guisettings.xml' key: 'settings/setting[@id="input.libinputkeyboardlayout"]' diff --git a/vars/main.yml b/vars/main.yml index fa075a0..4839429 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -28,6 +28,10 @@ kodi_config_cond_resolved: "{{ kodi_config_cond | selectattr('cond') | map(attri kodi_config_final: "{{ kodi_config_cond_resolved + (kodi_config | default([])) }}" -kodi_repository_names: "{{ kodi_repositories | map('regex_search', '^[^=]*') | list }}" +# The special `omit` token signifies "leave me out". Mainly for the +# LibreELEC-related code in `tests/test.yml`. +kodi_repositories_final: "{{ kodi_repositories | reject('equalto', omit) | list }}" + +kodi_repository_names: "{{ kodi_repositories_final | map('regex_search', '^[^=]*') | list }}" kodi_addon_names: "{{ kodi_addons | map('regex_search', '^[^=]*') | list }}" From f20a01643c290365fbabe12698bd34d3c0e49442 Mon Sep 17 00:00:00 2001 From: Matt Schreiber Date: Sun, 17 Mar 2024 21:19:15 -0400 Subject: [PATCH 2/2] chore: simplify conditional `kodi_extra_packages` by filtering the special `omit` token from the list of packages, and using this affordance to replace conditional `set_fact` tasks with "conditional" list entries. --- tasks/main.yml | 4 ++-- tests/test.yml | 31 ++++++++++--------------------- vars/main.yml | 2 ++ 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index c16b5be..7c90159 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -61,9 +61,9 @@ - name: Install Kodi and related apps package: - name: "{{ (packages | default([])) + (kodi_extra_packages | default([])) }}" + name: "{{ packages_final }}" state: present - when: "(((packages | default([])) + (kodi_extra_packages | default([]))) | length) > 0" + when: "(packages_final | length) > 0" tags: - install - get_addons diff --git a/tests/test.yml b/tests/test.yml index b792cb5..df29f7d 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -35,27 +35,6 @@ - hosts: all become: True - # NOTE that `kodi-inputstream-adaptive` does not ship with the base Kodi - # package, so we have to install `kodi-addon-inputstream-adaptive` on Arch - # Linux, and `kodi-inputstream-adaptive` elsewhere. - - name: 'test | define extra packages (Arch Linux)' - set_fact: - kodi_extra_packages: - - kodi-addon-inputstream-adaptive - when: 'ansible_distribution == "Archlinux"' - - # LibreELEC and OSMC do not need additional packages (and, in LibreELEC's - # case, cannot install additional packages anyway). - - name: 'test | define extra packages (other)' - set_fact: - kodi_extra_packages: - - kodi-inputstream-adaptive - when: 'ansible_distribution not in ["Archlinux", "LibreELEC", "OSMC"]' - - - name: 'test | add xvfb to extra packages for Debian and Ubuntu hosts' - set_fact: - kodi_extra_packages: '{{ (kodi_extra_packages | default([])) + ["xvfb"] }}' - when: 'ansible_distribution in ["Debian", "Ubuntu"]' roles: - role: "{{ playbook_dir | dirname }}" vars: @@ -67,6 +46,16 @@ - name: custom-group-for-testing system: False gid: 12345 + # NOTE that `kodi-inputstream-adaptive` does not ship with the base + # Kodi package, so we have to install `kodi-addon-inputstream-adaptive` + # on Arch Linux, and `kodi-inputstream-adaptive` elsewhere. + # + # LibreELEC and OSMC do not need additional packages (and, in + # LibreELEC's case, cannot install additional packages anyway). + kodi_extra_packages: + - '{{ (ansible_distribution == "Archlinux") | ternary("kodi-addon-inputstream-adaptive", omit) }}' + - '{{ (ansible_distribution in ["Archlinux", "LibreELEC", "OSMC"]) | ternary(omit, "kodi-inputstream-adaptive") }}' + - '{{ (ansible_distribution in ["Debian", "Ubuntu"]) | ternary("xvfb", omit) }}' kodi_language: 'en_US' kodi_locale_country: 'United States' kodi_locale_timezone_country: 'United States' diff --git a/vars/main.yml b/vars/main.yml index 4839429..b5debbd 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -35,3 +35,5 @@ kodi_repositories_final: "{{ kodi_repositories | reject('equalto', omit) | list kodi_repository_names: "{{ kodi_repositories_final | map('regex_search', '^[^=]*') | list }}" kodi_addon_names: "{{ kodi_addons | map('regex_search', '^[^=]*') | list }}" + +packages_final: "{{ ((packages | default([])) + (kodi_extra_packages | default([]))) | reject('equalto', omit) | list }}"