feat(system_baseline): add inputs that append packages to the profile's lists
Build / build (pull_request) Successful in 1m15s
Lint / lint (pull_request) Successful in 5m37s
Molecule / molecule (pull_request) Successful in 7m20s

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
This commit is contained in:
Dragonish committed 2026-11-26 22:25:36 +00:00
1 parent aa4e8c68a7
commit d5a91520df
12 files changed
+269 -14

No files matched your search

@@ -133,11 +133,38 @@
- [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
@@ -172,6 +199,8 @@
- 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
@@ -195,6 +224,8 @@
- 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.
@@ -224,3 +255,47 @@
- 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
@@ -1,12 +1,18 @@
---
# A package the role must remove, and the locales tool the role assumes exists
# (it does on a stock Ubuntu host).
# (it does on a stock Ubuntu host). jq (system_baseline_extra_packages) must be absent, so that the role is what installs it, and ed
# (system_baseline_extra_remove_packages, on no profile list) must be present, so that the role is what purges it.
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Install a package on the role's remove list and locale-gen
ansible.builtin.apt:
name: [telnet, locales]
name: [telnet, locales, ed]
state: present
update_cache: true
- name: Make sure jq is not installed
ansible.builtin.apt:
name: jq
state: absent
@@ -0,0 +1,21 @@
---
# One refusal per call: the role must stop on validation, before it changes anything, with a message that names the inputs.
# The case comes in as system_baseline_refused_case: {install, remove, expect}.
- name: Run the role with a bad extra package list
block:
- name: Include system_baseline
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
vars:
system_baseline_system_type: ubuntu_lxc
system_baseline_extra_packages: "{{ system_baseline_refused_case.install | default([]) }}"
system_baseline_extra_remove_packages: "{{ system_baseline_refused_case.remove | default([]) }}"
- name: Unreachable when validation works
ansible.builtin.fail:
msg: system_baseline ran with a bad extra package list
rescue:
- name: The validation stopped the play with the expected message
ansible.builtin.assert:
that: system_baseline_refused_case.expect in ansible_failed_result.msg | default('')
fail_msg: "Expected '{{ system_baseline_refused_case.expect }}', got: {{ ansible_failed_result.msg | default('') }}"
quiet: true
@@ -17,6 +17,16 @@
- "'telnet' not in ansible_facts.packages"
quiet: true
# jq was absent before the role ran and is on no profile list: the extra list installed it, and the profile's own packages (tmux,
# curl above) are still there. ed was present and is on no profile list: the extra remove list purged it.
- name: The extra packages were installed and the extra removal purged
ansible.builtin.assert:
that:
- "'jq' in ansible_facts.packages"
- "'curl' in ansible_facts.packages"
- "'ed' not in ansible_facts.packages"
quiet: true
- name: Read the journald drop-in
ansible.builtin.slurp:
src: /etc/systemd/journald.conf.d/50-system-baseline.conf
@@ -254,6 +264,51 @@
that: not system_baseline_verify_removed.stat.exists
quiet: true
# An extra tmux counts like a profile tmux: a flat package list without it installs no snippet, the same list plus the extra does.
- name: Run the tmux tasks with a flat package list that lacks tmux
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: tmux
vars:
system_baseline_system_type: ubuntu_lxc
system_baseline_tmux_autostart: true
system_baseline_essential_packages: [vim]
- name: Stat the snippet without the extra
ansible.builtin.stat:
path: /etc/profile.d/tmux-autostart.sh
register: system_baseline_verify_no_extra
- name: Run the tmux tasks with tmux as an extra package
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: tmux
vars:
system_baseline_system_type: ubuntu_lxc
system_baseline_tmux_autostart: true
system_baseline_essential_packages: [vim]
system_baseline_extra_packages: [tmux]
- name: Stat the snippet with the extra
ansible.builtin.stat:
path: /etc/profile.d/tmux-autostart.sh
register: system_baseline_verify_with_extra
- name: Only the extra tmux installs the snippet
ansible.builtin.assert:
that:
- not system_baseline_verify_no_extra.stat.exists
- system_baseline_verify_with_extra.stat.exists
quiet: true
- name: Remove the snippet again
ansible.builtin.include_role:
name: mortis.kamino.system_baseline
tasks_from: tmux
vars:
system_baseline_system_type: ubuntu_lxc
system_baseline_tmux_autostart: false
# The pve origins pin, run on this Ubuntu host: Ubuntu's 50unattended-upgrades sets Allowed-Origins, so the merged
# configuration showing only the pinned patterns proves the drop-in clears the earlier lists instead of appending to them.
# The patterns match no Ubuntu origin, which only means nothing would be upgraded; the role's dry run still passes. Here