test: check refusals once on the controller in verify
converge.yml is replayed by check, converge, check and idempotence on both platforms, so the validation-only plays in it ran eight times per scenario. They need no container: move them to the top of verify.yml, on localhost in check mode, so they run once and a regressed refusal cannot change the controller. Applies to the default scenarios of system_baseline, docker, sshd and systemd_hardening. The systemd_hardening refusal of a drop-in entry that is not a mapping comes after the disable and mask tasks, so it moves to verify.yml but stays on the container. The README Tests sections say where each check now runs. Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
6e3ea4521b
commit
2e70980b44
11 files changed
+648
-582
No files matched your search
@@ -128,12 +128,12 @@ The two task files besides `main` are a supported interface, for a caller that d
|
||||
|
||||
The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It installs packages from the Ubuntu mirrors, so the runner needs outbound network. It runs `check` before the converge (a fresh host) and after it (a configured host).
|
||||
|
||||
- Converge first checks that the role refuses a bad input with its own message before any change: an unknown `system_baseline_system_type`, an unknown `system_baseline_apt_upgrade` (main flow and `update` entry point), a negative reboot throttle or a negative or boolean post-reboot delay (main flow and `reboot` entry point), a line break in `system_baseline_apt_daily_timeout`, a bad `system_baseline_journal_max_use` (a bare number, a space, a line break, a number), and a bad package blacklist (a quote, a null item, a bare string).
|
||||
- Converge then applies the `ubuntu_lxc` profile, with tmux autostart and `system_baseline_apt_daily_timeout: 1h`, and only resolves the `pve` and `ubuntu_vm` profiles and a consumer override, asserting the resolved inputs.
|
||||
- Verify first checks, on the controller, that the role refuses a bad input with its own message before any change: an unknown `system_baseline_system_type`, an unknown `system_baseline_apt_upgrade` (main flow and `update` entry point), a negative reboot throttle or a negative or boolean post-reboot delay (main flow and `reboot` entry point), a line break in `system_baseline_apt_daily_timeout`, a bad `system_baseline_journal_max_use` (a bare number, a space, a line break, a number), and a bad package blacklist (a quote, a null item, a bare string).
|
||||
- Converge applies the `ubuntu_lxc` profile, with tmux autostart and `system_baseline_apt_daily_timeout: 1h`. Verify only resolves the `pve` and `ubuntu_vm` profiles and a consumer override, on the controller, asserting the resolved inputs.
|
||||
- Verify checks the installed and removed packages, the journal size cap, the apt settings in `20auto-upgrades` and `50unattended-upgrades`, the locale, and that systemd loaded the `apt-daily.service` timeout.
|
||||
- Verify checks the tmux snippet: root-owned, valid shell, the session and quoted window command, no effect without a terminal, a session name or window command ending in a newline refused, and the file removed when autostart is off.
|
||||
- Converge refuses bad items in `system_baseline_extra_packages` and `system_baseline_extra_remove_packages` (whitespace, a null, an empty string, a trailing minus, upper case, a bare string) and a package that one input installs and another purges, then applies the `ubuntu_lxc` profile with `jq` as an extra package and `ed` as an extra removal; verify checks that `jq` is installed, `ed` is gone and the profile's packages are still there, and that an extra `tmux` installs the snippet where a flat list without it installs none.
|
||||
- Converge also checks that a bad `system_baseline_apt_tmpdir` (under `/tmp` or `/var/tmp`, relative, with `..`, empty) is refused in the main flow and in the `update` entry point. Verify reads `tasks/update.yml` and checks that the scratch directory is created with mode `0700`, that both apt tasks set `TMPDIR` to it, and that the connection is reset afterwards: the scenario skips the `update` tag, so the upgrade itself never runs there.
|
||||
- Verify refuses bad items in `system_baseline_extra_packages` and `system_baseline_extra_remove_packages` (whitespace, a null, an empty string, a trailing minus, upper case, a bare string) and a package that one input installs and another purges; converge applies the `ubuntu_lxc` profile with `jq` as an extra package and `ed` as an extra removal; verify checks that `jq` is installed, `ed` is gone and the profile's packages are still there, and that an extra `tmux` installs the snippet where a flat list without it installs none.
|
||||
- Verify also checks that a bad `system_baseline_apt_tmpdir` (under `/tmp` or `/var/tmp`, relative, with `..`, empty) is refused in the main flow and in the `update` entry point. It reads `tasks/update.yml` and checks that the scratch directory is created with mode `0700`, that both apt tasks set `TMPDIR` to it, and that the connection is reset afterwards: the scenario skips the `update` tag, so the upgrade itself never runs there.
|
||||
- Verify ends by running the role once with `system_baseline_journal_max_use: ""` after removing the drop-in, and asserts that no drop-in is written and that `systemd-journald` was not restarted.
|
||||
- Verify runs the `reboot` entry point with `system_baseline_reboot_if_required: false`, without and with `/var/run/reboot-required`, and checks the fact and that the host did not reboot.
|
||||
- The `pve` origins pin is applied to the Ubuntu container and read back with `apt-config dump`, then removed again. The package blacklist is written, read back as a list, left alone by a second run and removed by an empty list.
|
||||
|
||||
@@ -1,181 +1,4 @@
|
||||
---
|
||||
- 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
|
||||
|
||||
# The journal cap is a number and a unit letter, or empty: a bare number (journald would read bytes), a zero, a space, a line break, a
|
||||
# lower-case unit and a number that is not a string each stop the run before any change.
|
||||
- name: A bad journal size cap is refused
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Refuse each bad value
|
||||
ansible.builtin.include_tasks: tasks/refuse_journal_max_use.yml
|
||||
vars:
|
||||
system_baseline_refused_journal: "{{ item }}"
|
||||
loop:
|
||||
- "300"
|
||||
- "0"
|
||||
- 10 M
|
||||
- "10m"
|
||||
- "200M\nStorage=none"
|
||||
- 300
|
||||
|
||||
# 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
|
||||
@@ -190,130 +13,3 @@
|
||||
- { 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
|
||||
@@ -1,4 +1,338 @@
|
||||
---
|
||||
# Validation-only plays: they need no container, so they run once, on the controller, in
|
||||
# check mode so that a refusal that regressed cannot change the controller.
|
||||
- name: Refuse an unknown system_baseline_system_type
|
||||
hosts: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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
|
||||
|
||||
# The journal cap is a number and a unit letter, or empty: a bare number (journald would read bytes), a zero, a space, a line break, a
|
||||
# lower-case unit and a number that is not a string each stop the run before any change.
|
||||
- name: A bad journal size cap is refused
|
||||
hosts: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Refuse each bad value
|
||||
ansible.builtin.include_tasks: tasks/refuse_journal_max_use.yml
|
||||
vars:
|
||||
system_baseline_refused_journal: "{{ item }}"
|
||||
loop:
|
||||
- "300"
|
||||
- "0"
|
||||
- 10 M
|
||||
- "10m"
|
||||
- "200M\nStorage=none"
|
||||
- 300
|
||||
|
||||
# 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: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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' }
|
||||
|
||||
# The remaining plays only load the role's defaults (validate.yml changes nothing) and assert
|
||||
# the resolved inputs. They cover the profiles converge.yml cannot run.
|
||||
- name: The pve profile resolves
|
||||
hosts: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
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
|
||||
|
||||
- name: Verify
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
|
||||
Reference in new issue
Block a user