Files
Kamino/roles/system_baseline/molecule/default/converge.yml
T
Dragonish d5a91520df
Build / build (pull_request) Successful in 1m15s
Lint / lint (pull_request) Successful in 5m37s
Molecule / molecule (pull_request) Successful in 7m20s
feat(system_baseline): add inputs that append packages to the profile's lists
system_baseline_essential_packages and system_baseline_remove_packages
replace the whole list, and so does a list inside
system_baseline_profile_overrides, so adding one package meant repeating
the profile's list and keeping it in step with every release.

system_baseline_extra_packages and system_baseline_extra_remove_packages
(lists, default empty) append to the resolved lists. The tmux and
unattended-upgrades checks read the combined list, so an extra tmux or
unattended-upgrades enables the matching task like a profile package.
Items must be Debian package names: a null item would have become the
package "None", and apt reads a trailing minus (jq-) as a removal. A
package that one input installs and another purges stops the run before
any change; only overlaps that involve an extra are checked, so a
consumer's own overlap between the resolved lists behaves as before. A
flat input that is a plain string still counts as a one-item list.

With both inputs left at their default the role behaves as before.

Closes #399

Assisted-by: Claude Code:claude-sonnet-5-5
2026-11-26 22:25:36 +00:00

302 lines
13 KiB
YAML

---
- name: Refuse an unknown system_baseline_system_type
hosts: all
gather_facts: false
tasks:
- name: Run the role with a bad system_baseline_system_type
block:
- name: Include system_baseline
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
vars:
system_baseline_system_type: not_a_type
- name: Unreachable when validation works
ansible.builtin.fail:
msg: system_baseline ran with an invalid system_baseline_system_type
rescue:
- name: The validation stopped the play
ansible.builtin.assert:
that: "'is invalid' in ansible_failed_result.msg | default('')"
quiet: true
# The apt upgrade mode is safe or dist: anything else (here `full`, an apt module value the role does not offer) stops the run before
# any change, with a message that names the input.
- name: An unknown apt upgrade mode is refused
hosts: all
gather_facts: false
tasks:
- name: Run the role with a bad system_baseline_apt_upgrade
block:
- name: Include system_baseline
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
vars:
system_baseline_system_type: ubuntu_lxc
system_baseline_apt_upgrade: full
- name: Unreachable when validation works
ansible.builtin.fail:
msg: system_baseline ran with an invalid system_baseline_apt_upgrade
rescue:
- name: The validation stopped the play
ansible.builtin.assert:
that: "'system_baseline_apt_upgrade is' in ansible_failed_result.msg | default('')"
quiet: true
# The update entry point does not run validate.yml, so it checks the mode itself and stops before it calls the package module.
- name: The update entry point refuses an unknown apt upgrade mode
hosts: all
gather_facts: false
tasks:
- name: Run the update entry point with a bad system_baseline_apt_upgrade
block:
- name: Include system_baseline, tasks_from update
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: update
vars:
system_baseline_apt_upgrade: full
- name: Unreachable when validation works
ansible.builtin.fail:
msg: the update entry point ran with an invalid system_baseline_apt_upgrade
rescue:
- name: The validation stopped the play
ansible.builtin.assert:
that: "'system_baseline_apt_upgrade is' in ansible_failed_result.msg | default('')"
quiet: true
# The apt scratch directory becomes TMPDIR of the upgrade: a path under /tmp or /var/tmp (which a restart of ssh.service can delete), a relative
# path and a `..` each stop the run before any change, in the main flow and in the update entry point (which does not run validate.yml).
- name: A bad apt scratch directory is refused
hosts: all
gather_facts: false
tasks:
- name: Refuse each bad value
ansible.builtin.include_tasks: tasks/refuse_apt_tmpdir_entries.yml
vars:
system_baseline_refused_tmpdir: "{{ item }}"
loop:
- /tmp
- /var/tmp/apt
- /var/cache/../../tmp/x
- var/cache/apt-tmp
- ""
# The reboot inputs are whole numbers, 0 or more: a negative number and a boolean each stop the run before a host reboots,
# in the main flow and in the reboot entry point (which does not run validate.yml).
- name: A bad reboot throttle or post-reboot delay is refused
hosts: all
gather_facts: false
tasks:
- name: Refuse each bad value
ansible.builtin.include_tasks: tasks/refuse_reboot.yml
vars:
system_baseline_refused_reboot: "{{ item }}"
loop:
- {system_baseline_reboot_throttle: -1}
- {system_baseline_reboot_post_delay: -5}
- {system_baseline_reboot_post_delay: true}
# The value is written into a unit file, so a line break (a second directive) is refused.
- name: A bad apt-daily timeout is refused
hosts: all
gather_facts: false
tasks:
- name: Run the role with a line break in system_baseline_apt_daily_timeout
block:
- name: Include system_baseline
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
vars:
system_baseline_system_type: ubuntu_lxc
system_baseline_apt_daily_timeout: "1h\nExecStart=/bin/true"
- name: Unreachable when validation works
ansible.builtin.fail:
msg: system_baseline ran with an invalid system_baseline_apt_daily_timeout
rescue:
- name: The validation stopped the play
ansible.builtin.assert:
that: "'system_baseline_apt_daily_timeout must be' in ansible_failed_result.msg | default('')"
quiet: true
# A quote, a null item and a bare string (not a list) each stop the run: the bare string would otherwise be split into one-character
# patterns, and the null item would become an empty pattern that matches every package.
- name: A bad package blacklist is refused
hosts: all
gather_facts: false
tasks:
- name: Refuse each bad value
ansible.builtin.include_tasks: tasks/refuse_blacklist.yml
vars:
system_baseline_refused_blacklist: "{{ item }}"
loop:
- ['bad"name']
- [null]
- linux-image-.*
# Items that are not Debian package names (whitespace, null, empty, a trailing minus that apt reads as a removal, an option, upper case, a
# version pin), and a package that one input installs and another purges, each stop the run before any change.
# The overlaps are: an extra install against the profile's remove list (telnet), an extra install against an extra remove, and an extra
# remove against the profile's install list (tmux).
- name: A bad extra package list is refused
hosts: all
gather_facts: false
tasks:
- name: Refuse each bad value
ansible.builtin.include_tasks: tasks/refuse_extra_packages.yml
vars:
system_baseline_refused_case: "{{ item }}"
loop:
- { install: ['bad name'], expect: 'must be lists of package names' }
- { install: [null], expect: 'must be lists of package names' }
- { install: jq, expect: 'must be lists of package names' }
- { remove: [''], expect: 'must be lists of package names' }
- { install: ['jq-'], expect: 'must be lists of package names' }
- { install: ['-y'], expect: 'must be lists of package names' }
- { remove: ['Telnet'], expect: 'must be lists of package names' }
- { remove: ['ed=1.0'], expect: 'must be lists of package names' }
- { install: [telnet], expect: 'is both installed and purged' }
- { install: [jq], remove: [jq], expect: 'is both installed and purged' }
- { remove: [tmux], expect: 'is both installed and purged' }
- name: Converge the LXC profile
hosts: all
gather_facts: true
vars:
system_baseline_system_type: ubuntu_lxc
system_baseline_extra_packages: [jq]
system_baseline_extra_remove_packages: [ed]
system_baseline_tmux_autostart: true
system_baseline_apt_daily_timeout: 1h
system_baseline_tmux_session: molecule
system_baseline_tmux_windows:
- { name: logs, command: "echo 'a b'; true" }
roles:
- role: mortis.kamino.system_baseline
# The remaining plays only load the role's defaults (validate.yml changes nothing) and assert
# the resolved inputs. They cover the profiles the converge above cannot run.
- name: The pve profile resolves
hosts: all
gather_facts: false
vars:
system_baseline_system_type: pve
tasks:
- name: Load the role defaults
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: validate.yml
public: true
- name: Assert the pve profile
ansible.builtin.assert:
that:
- "'ufw' not in system_baseline_essential_packages"
- "'tmux' not in system_baseline_essential_packages"
- "'unattended-upgrades' in system_baseline_essential_packages"
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot'] == false
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot-Time'] == '03:00'
- system_baseline_secure_tmp_mounts == ['/dev/shm', '/tmp', '/var/tmp']
- system_baseline_update
- system_baseline_apt_upgrade == 'dist'
- system_baseline_unattended_upgrade_origins | length == 3
- system_baseline_unattended_upgrade_origins | select('search', 'Proxmox') | list == []
- __system_baseline_install_packages == system_baseline_essential_packages
- __system_baseline_purge_packages == system_baseline_remove_packages
quiet: true
- name: The ubuntu_vm profile resolves
hosts: all
gather_facts: false
vars:
system_baseline_system_type: ubuntu_vm
tasks:
- name: Load the role defaults
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: validate.yml
public: true
- name: Assert the ubuntu_vm profile
ansible.builtin.assert:
that:
- "'qemu-guest-agent' in system_baseline_essential_packages"
- "'tmux' in system_baseline_essential_packages"
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot'] == false
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot-Time'] == '04:00'
- system_baseline_sysctl_hardening | selectattr('name', 'equalto', 'net.ipv4.conf.all.log_martians') | list | length == 1
- system_baseline_apt_upgrade == 'safe'
- system_baseline_unattended_upgrade_origins == []
- __system_baseline_install_packages == system_baseline_essential_packages
- __system_baseline_purge_packages == system_baseline_remove_packages
quiet: true
# Consumer play vars override the profile.
- name: Consumer overrides win over the profile
hosts: all
gather_facts: false
vars:
system_baseline_system_type: ubuntu_vm
system_baseline_remove_packages: [telnet]
system_baseline_apt_upgrade: dist
system_baseline_profile_overrides:
ubuntu_vm:
unattended_upgrade_settings:
"Unattended-Upgrade::Automatic-Reboot": true
tasks:
- name: Load the role defaults
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: validate.yml
public: true
- name: Assert the overrides
ansible.builtin.assert:
that:
- system_baseline_remove_packages == ['telnet']
- system_baseline_apt_upgrade == 'dist'
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot'] == true
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot-Time'] == '04:00'
- "'qemu-guest-agent' in system_baseline_essential_packages"
quiet: true
# The extras append to the resolved lists, whether the profile's list or a flat input supplies them, and a name that is in both is listed once.
- name: Extra packages append to the resolved lists
hosts: all
gather_facts: false
vars:
system_baseline_system_type: ubuntu_lxc
system_baseline_essential_packages: [vim, curl]
system_baseline_extra_packages: [jq, vim, unattended-upgrades]
system_baseline_extra_remove_packages: [ed, telnet]
tasks:
- name: Load the role defaults
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: validate.yml
public: true
- name: Assert the lists the role acts on
ansible.builtin.assert:
that:
- __system_baseline_install_packages == ['vim', 'curl', 'jq', 'unattended-upgrades']
- "'ed' in __system_baseline_purge_packages"
- __system_baseline_purge_packages | select('equalto', 'telnet') | list | length == 1
- system_baseline_remove_packages | difference(__system_baseline_purge_packages) | length == 0
quiet: true
# A flat input that is a plain string (the package module accepts one) still counts as a one-item list, with and without extras.
- name: A flat string package list still resolves
hosts: all
gather_facts: false
vars:
system_baseline_system_type: ubuntu_lxc
system_baseline_essential_packages: vim
system_baseline_extra_packages: [jq]
tasks:
- name: Load the role defaults
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: validate.yml
public: true
- name: Assert the lists the role acts on
ansible.builtin.assert:
that:
- __system_baseline_install_packages == ['vim', 'jq']
quiet: true