Each of the seven vzdump cases ran the whole update entry point in check mode, when they assert only the guard's decision. The guard now lives in an internal tasks/vzdump_guard.yml, imported by update.yml so the update tag, when and main-flow vars still reach it. Six cases include it alone; the ubuntu_lxc case keeps running tasks_from: update end to end, and a static check asserts the guard is imported before the upgrade and that the upgrade's when reads its fact. The purge of unwanted packages becomes one apt call over the installed ones, skipped when none is installed. The scenario's gathering plays use gather_subset min: the role reads only os_family and package_facts. Closes #456 Assisted-by: Claude Code
866 lines
37 KiB
YAML
866 lines
37 KiB
YAML
---
|
|
# 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 size journald reads, or empty: infinity (SystemMaxUse does not take it), a lower-case unit, a unit with a trailing B,
|
|
# a line break 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:
|
|
- infinity
|
|
- "10m"
|
|
- "10MB"
|
|
- "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
|
|
tasks:
|
|
- name: Read the installed packages
|
|
ansible.builtin.package_facts:
|
|
manager: auto
|
|
|
|
- name: The essential packages are installed and the removed one is gone
|
|
ansible.builtin.assert:
|
|
that:
|
|
- "'ufw' in ansible_facts.packages"
|
|
- "'fail2ban' in ansible_facts.packages"
|
|
- "'unattended-upgrades' in ansible_facts.packages"
|
|
- "'tmux' in ansible_facts.packages"
|
|
- "'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
|
|
register: system_baseline_verify_journald
|
|
|
|
- name: The journal size is capped
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_verify_journald.content | b64decode is search('(?m)^SystemMaxUse=200M$')
|
|
quiet: true
|
|
|
|
- name: Read the tmux auto-start snippet
|
|
ansible.builtin.slurp:
|
|
src: /etc/profile.d/tmux-autostart.sh
|
|
register: system_baseline_verify_tmux
|
|
|
|
- name: Stat the tmux auto-start snippet
|
|
ansible.builtin.stat:
|
|
path: /etc/profile.d/tmux-autostart.sh
|
|
register: system_baseline_verify_tmux_stat
|
|
|
|
- name: The snippet is root-owned, attaches to the session, and quotes the window command as one argument
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_verify_tmux_stat.stat.pw_name == 'root'
|
|
- system_baseline_verify_tmux_stat.stat.mode == '0644'
|
|
- system_baseline_verify_tmux.content | b64decode is search('tmux attach-session -t =molecule')
|
|
- system_baseline_verify_tmux.content | b64decode is search("-n logs 'echo '\"'\"'a b'\"'\"'; true'")
|
|
quiet: true
|
|
|
|
- name: The snippet is valid shell
|
|
ansible.builtin.command: /bin/sh -n /etc/profile.d/tmux-autostart.sh
|
|
changed_when: false
|
|
|
|
- name: Read the apt configuration the role writes
|
|
ansible.builtin.slurp:
|
|
src: "{{ item }}"
|
|
loop:
|
|
- /etc/apt/apt.conf.d/20auto-upgrades
|
|
- /etc/apt/apt.conf.d/50unattended-upgrades
|
|
register: system_baseline_verify_apt
|
|
|
|
- name: Automatic upgrades are on and the reboot setting is applied
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_verify_apt.results[0].content | b64decode is search('APT::Periodic::Unattended-Upgrade "1";')
|
|
- system_baseline_verify_apt.results[1].content | b64decode is search('Unattended-Upgrade::Automatic-Reboot "False";')
|
|
- system_baseline_verify_apt.results[1].content | b64decode is search('Unattended-Upgrade::Automatic-Reboot-Time "05:00";')
|
|
quiet: true
|
|
|
|
- name: Read the generated locales
|
|
ansible.builtin.command: locale -a
|
|
register: system_baseline_verify_locales
|
|
changed_when: false
|
|
|
|
- name: The configured locale exists
|
|
ansible.builtin.assert:
|
|
that: system_baseline_verify_locales.stdout_lines | map('lower') | map('replace', '-', '') | select('match', 'en_us.utf8') | list | length > 0
|
|
quiet: true
|
|
|
|
# The converge sets system_baseline_apt_daily_timeout: 1h. systemd must have read the drop-in after the reload, not only the file exist.
|
|
- name: The apt-daily start timeout is written and loaded
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Read the drop-in
|
|
ansible.builtin.slurp:
|
|
src: /etc/systemd/system/apt-daily.service.d/10-timeout.conf
|
|
register: system_baseline_verify_apt_daily
|
|
|
|
- name: Ask systemd for the unit
|
|
# The systemd module cannot return TimeoutStartUSec, which is the point of this check.
|
|
ansible.builtin.command: systemctl show -p LoadState -p TimeoutStartUSec apt-daily.service # noqa: command-instead-of-module
|
|
register: system_baseline_verify_apt_daily_show
|
|
changed_when: false
|
|
|
|
- name: The drop-in is there and systemd applies it
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_verify_apt_daily.content | b64decode is search('(?m)^TimeoutStartSec=1h$')
|
|
- system_baseline_verify_apt_daily_show.stdout_lines is contains('LoadState=loaded')
|
|
- system_baseline_verify_apt_daily_show.stdout_lines is contains('TimeoutStartUSec=1h')
|
|
quiet: true
|
|
|
|
# The scenario skips the `update` tag (molecule.yml), so the upgrade never runs here and its scratch directory is never created. This reads the
|
|
# task file on the controller and checks that the directory is private and that both apt tasks use it as TMPDIR.
|
|
- name: The update tasks give the apt upgrade a private scratch directory
|
|
hosts: localhost
|
|
connection: local
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Read the update tasks
|
|
ansible.builtin.set_fact:
|
|
system_baseline_verify_update_tasks: "{{ lookup('ansible.builtin.file', playbook_dir ~ '/../../tasks/update.yml') }}"
|
|
|
|
- name: The scratch directory is created private and both apt tasks use it
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_verify_update_tasks is search('(?m)^ path:\s"\{\{ system_baseline_apt_tmpdir \}\}"$')
|
|
- system_baseline_verify_update_tasks is search('(?m)^ mode:\s"0700"$')
|
|
- system_baseline_verify_update_tasks | regex_findall('(?m)^ TMPDIR:\s"\{\{ system_baseline_apt_tmpdir \}\}"$') | length == 2
|
|
- system_baseline_verify_update_tasks is search('(?m)^ ansible.builtin.meta:\sreset_connection$')
|
|
quiet: true
|
|
|
|
# The guard cases below run vzdump_guard.yml alone, so this holds the wiring: the guard is imported before the upgrade, and the upgrade
|
|
# task's when reads the guard's fact.
|
|
- name: The vzdump guard is imported before the upgrade, and the upgrade waits on its fact
|
|
ansible.builtin.assert:
|
|
that:
|
|
- >-
|
|
system_baseline_verify_update_tasks is search('(?ms)^ ansible\.builtin\.import_tasks:\svzdump_guard\.yml$'
|
|
~ '.*^- name:\sUpdate & upgrade apt packages$')
|
|
- >-
|
|
system_baseline_verify_update_tasks is search('(?m)^- name:\sUpdate & upgrade apt packages\n(?: .*\n)*?'
|
|
~ ' - not \(__system_baseline_vzdump_running \| default\(false\)\)$')
|
|
quiet: true
|
|
|
|
# The reboot entry point is a supported interface: with system_baseline_reboot_if_required
|
|
# false it only sets system_baseline_reboot_required. Here and not in converge, because it
|
|
# creates and removes the marker file, which the idempotence run would report as a change.
|
|
# Reaching the assert after the marker exists shows the entry point did not reboot.
|
|
- name: The reboot entry point only computes the fact when told not to reboot
|
|
hosts: all
|
|
gather_facts: true
|
|
gather_subset: [min]
|
|
tasks:
|
|
- name: Remove the reboot marker
|
|
ansible.builtin.file:
|
|
path: /var/run/reboot-required
|
|
state: absent
|
|
|
|
- name: Run the reboot entry point without a pending reboot
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: reboot
|
|
vars:
|
|
system_baseline_reboot_if_required: false
|
|
|
|
- name: No reboot is required
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_reboot_required is defined
|
|
- not system_baseline_reboot_required
|
|
quiet: true
|
|
|
|
- name: Create the reboot marker
|
|
ansible.builtin.copy:
|
|
dest: /var/run/reboot-required
|
|
content: ""
|
|
mode: "0644"
|
|
|
|
- name: Run the reboot entry point with a pending reboot
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: reboot
|
|
vars:
|
|
system_baseline_reboot_if_required: false
|
|
|
|
- name: A reboot is required and the host did not reboot
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_reboot_required
|
|
quiet: true
|
|
|
|
- name: Remove the reboot marker again
|
|
ansible.builtin.file:
|
|
path: /var/run/reboot-required
|
|
state: absent
|
|
|
|
# The snippet must do nothing without a terminal: SSH_CONNECTION is set, stdin is not a tty. It must reach the line after it
|
|
# and leave no tmux server behind.
|
|
- name: Source the snippet with an SSH connection and no terminal
|
|
ansible.builtin.command:
|
|
argv: [/bin/sh, -c, '. /etc/profile.d/tmux-autostart.sh; echo reached']
|
|
environment:
|
|
SSH_CONNECTION: 192.0.2.1 50000 192.0.2.2 22
|
|
register: system_baseline_verify_snippet
|
|
changed_when: false
|
|
|
|
- name: It continued to the next line and started no tmux session
|
|
ansible.builtin.assert:
|
|
that: system_baseline_verify_snippet.stdout == 'reached'
|
|
quiet: true
|
|
|
|
- name: Ask tmux for sessions
|
|
ansible.builtin.command: tmux list-sessions
|
|
register: system_baseline_verify_sessions
|
|
changed_when: false
|
|
failed_when: system_baseline_verify_sessions.rc == 0
|
|
|
|
# The inputs reject a trailing newline (a YAML block scalar adds one): the check anchors with \Z, not $.
|
|
- name: Run the validation with a session name that ends in a newline
|
|
block:
|
|
- name: Include the validation
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: validate
|
|
vars:
|
|
system_baseline_system_type: ubuntu_lxc
|
|
system_baseline_tmux_autostart: true
|
|
system_baseline_tmux_session: "main\n"
|
|
- name: Unreachable when validation works
|
|
ansible.builtin.fail:
|
|
msg: a session name with a trailing newline was accepted
|
|
rescue:
|
|
- name: The validation refused it
|
|
ansible.builtin.assert:
|
|
that: "'system_baseline_tmux_session must be' in ansible_failed_result.msg | default('')"
|
|
quiet: true
|
|
|
|
- name: Run the validation with a window command that ends in a newline
|
|
block:
|
|
- name: Include the validation
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: validate
|
|
vars:
|
|
system_baseline_system_type: ubuntu_lxc
|
|
system_baseline_tmux_autostart: true
|
|
system_baseline_tmux_windows:
|
|
- name: logs
|
|
command: "journalctl -f\n"
|
|
- name: Unreachable when validation works
|
|
ansible.builtin.fail:
|
|
msg: a window command with a trailing newline was accepted
|
|
rescue:
|
|
- name: The validation refused it
|
|
ansible.builtin.assert:
|
|
that: "'system_baseline_tmux_session must be' in ansible_failed_result.msg | default('')"
|
|
quiet: true
|
|
|
|
# The removal path runs last, because it deletes the snippet the checks above read. It lives here and not in converge: a
|
|
# converge that installs and then removes the file would not be idempotent.
|
|
- name: Run the tmux tasks with autostart off
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: tmux
|
|
vars:
|
|
system_baseline_system_type: ubuntu_lxc
|
|
system_baseline_tmux_autostart: false
|
|
|
|
- name: Stat the snippet again
|
|
ansible.builtin.stat:
|
|
path: /etc/profile.d/tmux-autostart.sh
|
|
register: system_baseline_verify_removed
|
|
|
|
- name: The snippet is gone
|
|
ansible.builtin.assert:
|
|
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
|
|
# and not in converge, because switching profiles and back would not be idempotent. Applying the pve profile also rewrites
|
|
# the 50unattended-upgrades keys (Automatic-Reboot-Time 03:00); the ubuntu_lxc re-run at the end restores them.
|
|
- name: The pve profile pins the unattended-upgrades origins
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Stat the origins drop-in after the ubuntu_lxc converge
|
|
ansible.builtin.stat:
|
|
path: /etc/apt/apt.conf.d/90unattended-upgrades-origins
|
|
register: system_baseline_verify_origins_before
|
|
|
|
- name: The ubuntu_lxc profile pins nothing
|
|
ansible.builtin.assert:
|
|
that: not system_baseline_verify_origins_before.stat.exists
|
|
quiet: true
|
|
|
|
- name: Run the unattended-upgrades tasks with the pve profile
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: unattended_upgrades
|
|
vars:
|
|
system_baseline_system_type: pve
|
|
|
|
- name: Dump the merged apt configuration
|
|
ansible.builtin.command: apt-config dump
|
|
register: system_baseline_verify_apt_config
|
|
changed_when: false
|
|
|
|
- name: Only the pinned Debian origins are allowed
|
|
ansible.builtin.assert:
|
|
that:
|
|
- >-
|
|
system_baseline_verify_apt_config.stdout_lines | select('match', 'Unattended-Upgrade::Origins-Pattern::\s') | list ==
|
|
['Unattended-Upgrade::Origins-Pattern:: "origin=Debian,codename=${distro_codename},label=Debian";',
|
|
'Unattended-Upgrade::Origins-Pattern:: "origin=Debian,codename=${distro_codename},label=Debian-Security";',
|
|
'Unattended-Upgrade::Origins-Pattern:: "origin=Debian,codename=${distro_codename}-security,label=Debian-Security";']
|
|
- system_baseline_verify_apt_config.stdout_lines | select('match', 'Unattended-Upgrade::Allowed-Origins::\s') | list == []
|
|
quiet: true
|
|
|
|
- name: Run the unattended-upgrades tasks with the ubuntu_lxc profile again
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: unattended_upgrades
|
|
vars:
|
|
system_baseline_system_type: ubuntu_lxc
|
|
|
|
- name: Dump the merged apt configuration again
|
|
ansible.builtin.command: apt-config dump
|
|
register: system_baseline_verify_apt_config_restored
|
|
changed_when: false
|
|
|
|
- name: The drop-in is gone and the distribution origins are back
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_verify_apt_config_restored.stdout_lines | select('match', 'Unattended-Upgrade::Allowed-Origins::\s') | list | length > 0
|
|
- system_baseline_verify_apt_config_restored.stdout is not search('origin=Debian')
|
|
quiet: true
|
|
|
|
# The package blacklist: written and parsed by apt as a list, left alone by a second run, removed by an empty list. Here and not in
|
|
# converge, because converge runs the default (empty) list.
|
|
- name: The unattended-upgrades package blacklist is written, kept and removed
|
|
hosts: all
|
|
gather_facts: false
|
|
vars:
|
|
system_baseline_verify_blacklist: ["linux-image-.*", "nvidia-.*"]
|
|
tasks:
|
|
- name: Run the unattended-upgrades tasks with a blacklist
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: unattended_upgrades
|
|
vars:
|
|
system_baseline_system_type: ubuntu_lxc
|
|
system_baseline_unattended_upgrade_package_blacklist: "{{ system_baseline_verify_blacklist }}"
|
|
|
|
- name: Stat the blacklist drop-in
|
|
ansible.builtin.stat:
|
|
path: /etc/apt/apt.conf.d/90unattended-upgrades-blacklist
|
|
register: system_baseline_verify_blacklist_first
|
|
|
|
- name: Dump the merged apt configuration
|
|
ansible.builtin.command: apt-config dump
|
|
register: system_baseline_verify_blacklist_dump
|
|
changed_when: false
|
|
|
|
- name: Apt reads both entries as a list
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_verify_blacklist_first.stat.exists
|
|
- >-
|
|
system_baseline_verify_blacklist_dump.stdout_lines | select('match', 'Unattended-Upgrade::Package-Blacklist::\s') | list ==
|
|
['Unattended-Upgrade::Package-Blacklist:: "linux-image-.*";', 'Unattended-Upgrade::Package-Blacklist:: "nvidia-.*";']
|
|
quiet: true
|
|
|
|
- name: Run the same tasks again
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: unattended_upgrades
|
|
vars:
|
|
system_baseline_system_type: ubuntu_lxc
|
|
system_baseline_unattended_upgrade_package_blacklist: "{{ system_baseline_verify_blacklist }}"
|
|
|
|
- name: Stat the blacklist drop-in again
|
|
ansible.builtin.stat:
|
|
path: /etc/apt/apt.conf.d/90unattended-upgrades-blacklist
|
|
register: system_baseline_verify_blacklist_second
|
|
|
|
- name: A second run does not rewrite the file
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_verify_blacklist_second.stat.checksum == system_baseline_verify_blacklist_first.stat.checksum
|
|
- system_baseline_verify_blacklist_second.stat.mtime == system_baseline_verify_blacklist_first.stat.mtime
|
|
quiet: true
|
|
|
|
- name: Run the same tasks with an empty blacklist
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: unattended_upgrades
|
|
vars:
|
|
system_baseline_system_type: ubuntu_lxc
|
|
system_baseline_unattended_upgrade_package_blacklist: []
|
|
|
|
- name: Stat the blacklist drop-in after the empty list
|
|
ansible.builtin.stat:
|
|
path: /etc/apt/apt.conf.d/90unattended-upgrades-blacklist
|
|
register: system_baseline_verify_blacklist_removed
|
|
|
|
- name: Dump the merged apt configuration after the empty list
|
|
ansible.builtin.command: apt-config dump
|
|
register: system_baseline_verify_blacklist_dump_removed
|
|
changed_when: false
|
|
|
|
- name: The file is gone and apt lists no blacklisted package
|
|
ansible.builtin.assert:
|
|
that:
|
|
- not system_baseline_verify_blacklist_removed.stat.exists
|
|
- system_baseline_verify_blacklist_dump_removed.stdout_lines | select('match', 'Unattended-Upgrade::Package-Blacklist::\s') | list == []
|
|
quiet: true
|
|
tags: always
|
|
|
|
# The vzdump guard (system_baseline_skip_upgrade_during_vzdump): a running backup is a vzdump task without an endtime. With the input off, or on
|
|
# a system type other than pve, pvesh is never run. Only the decision is asserted: the upgrade itself is not run in CI. The cases run the guard
|
|
# alone; the last one runs the update entry point, so it still runs end to end in check mode.
|
|
- name: The vzdump guard skips the upgrade only for a running backup on a pve node
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Run each case
|
|
ansible.builtin.include_tasks: tasks/vzdump_guard_case.yml
|
|
vars:
|
|
system_baseline_case: "{{ item }}"
|
|
loop:
|
|
- {type: pve, input: true, running: true, asked: true, answer: [{type: vzdump, upid: a, starttime: 1}]}
|
|
- {type: pve, input: true, running: true, asked: true, answer: [{type: vzdump, upid: a, starttime: 1}, {type: qmstart, upid: b, starttime: 1}]}
|
|
- {type: pve, input: true, running: false, asked: true, answer: [{type: vzdump, upid: a, starttime: 1, endtime: 2}]}
|
|
- {type: pve, input: true, running: false, asked: true, answer: [{type: qmstart, upid: b, starttime: 1}]}
|
|
- {type: pve, input: true, running: false, asked: true, answer: []}
|
|
- {type: pve, input: false, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}]}
|
|
- {type: ubuntu_lxc, input: true, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}], tasks_from: update}
|
|
|
|
# An empty system_baseline_journal_max_use leaves journald alone: with the drop-in gone, the role neither writes it again nor restarts
|
|
# systemd-journald. It runs last, because it applies the role with its defaults (the converge's tmux autostart and apt-daily timeout are
|
|
# not set here) and the checks above read what the converge wrote.
|
|
# It removes what the converge wrote, so a second `molecule verify` needs a converge first.
|
|
- name: An empty journal size cap leaves journald alone
|
|
hosts: all
|
|
gather_facts: true
|
|
gather_subset: [min]
|
|
tasks:
|
|
- name: Remove the drop-in and its directory
|
|
ansible.builtin.file:
|
|
path: /etc/systemd/journald.conf.d
|
|
state: absent
|
|
|
|
- name: Note when journald last started
|
|
ansible.builtin.command:
|
|
argv: [systemctl, show, systemd-journald, --property=ActiveEnterTimestampMonotonic, --value]
|
|
register: system_baseline_verify_journald_before
|
|
changed_when: false
|
|
|
|
- name: Run the role with an empty cap
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
vars:
|
|
system_baseline_system_type: ubuntu_lxc
|
|
system_baseline_journal_max_use: ""
|
|
|
|
- name: Look for the drop-in directory
|
|
ansible.builtin.stat:
|
|
path: /etc/systemd/journald.conf.d
|
|
register: system_baseline_verify_journald_dir
|
|
|
|
- name: Note when journald last started, after the run
|
|
ansible.builtin.command:
|
|
argv: [systemctl, show, systemd-journald, --property=ActiveEnterTimestampMonotonic, --value]
|
|
register: system_baseline_verify_journald_after
|
|
changed_when: false
|
|
|
|
- name: Nothing was written and journald was not restarted
|
|
ansible.builtin.assert:
|
|
that:
|
|
- not system_baseline_verify_journald_dir.stat.exists
|
|
- system_baseline_verify_journald_before.stdout | length > 0
|
|
- system_baseline_verify_journald_after.stdout == system_baseline_verify_journald_before.stdout
|
|
quiet: true
|