Skip to content

Commit

Permalink
chore: simplify conditional kodi_extra_packages
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tomeon committed Mar 18, 2024
1 parent 2f8b9cf commit f20a016
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
4 changes: 2 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 10 additions & 21 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"

0 comments on commit f20a016

Please sign in to comment.