From be8c3f2ed92c1a256523520884904078eed11c2f Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sat, 28 Nov 2026 20:39:19 +0000 Subject: [PATCH 1/3] test(docker): merge the verify role runs and assert a unit change keeps dockerd running The verify ran the role four times to switch the unit, daemon and restart inputs, and each run refreshed apt against the stand-in repository. Nothing showed that removing a unit leaves dockerd running. The daemon-settings check now runs before any role run; those runs set no daemon input until the last play, so daemon.json still holds converge's content. One play then runs the role twice: first with the boot unit off, a daemon change and no restart, asserting the units, the new value and an unchanged dockerd start time; then with both units on and a restart, asserting the boot unit is back, the value and a new start time. Closes #460 Assisted-by: Claude Code --- roles/docker/molecule/default/verify.yml | 94 +++++++++++------------- 1 file changed, 42 insertions(+), 52 deletions(-) diff --git a/roles/docker/molecule/default/verify.yml b/roles/docker/molecule/default/verify.yml index aead9c4..9d9b704 100644 --- a/roles/docker/molecule/default/verify.yml +++ b/roles/docker/molecule/default/verify.yml @@ -297,48 +297,7 @@ changed_when: false failed_when: docker_verify_start_run.rc != 2 -# Switching an input back to false removes that unit and script and leaves the other alone. -- name: Verify that a unit is removed when its input is false - hosts: all - vars: - docker_gpg_url: file:///srv/docker-stub-repo/docker.asc - docker_keyring_checksum: "{{ docker_stub_key.stat.checksum }}" - docker_repo_base_url: file:///srv/docker-stub-repo - docker_users: [moleculeuser] - docker_start_missed: false - docker_stop_at_shutdown: true - docker_stop_at_shutdown_timeout: 20 - tasks: - - name: Stat the stand-in repository key - ansible.builtin.stat: - path: /srv/docker-stub-repo/docker.asc - checksum_algorithm: sha256 - register: docker_stub_key - - - name: Apply the role with the boot unit off - ansible.builtin.include_role: - name: mortis.kamino.docker - - - name: Stat the boot unit's files and the shutdown unit's script - ansible.builtin.stat: - path: "{{ item }}" - loop: - - /usr/local/sbin/docker-start-missed - - /etc/systemd/system/docker-start-missed.service - - /usr/local/sbin/docker-stop-at-shutdown - register: docker_verify_off - - - name: The boot unit is gone and the shutdown unit is still there - ansible.builtin.assert: - that: docker_verify_off.results | map(attribute='stat.exists') | list == [false, false, true] - quiet: true - - - name: Apply the role again with both inputs on - ansible.builtin.include_role: - name: mortis.kamino.docker - vars: - docker_start_missed: true - +# Converge's daemon.json, read before the role runs below change it. - name: Verify the daemon settings hosts: all gather_facts: false @@ -369,22 +328,26 @@ - docker_verify_daemon_stat.stat.pw_name == 'root' quiet: true -# The stand-in docker.service runs for real, so a restart shows in its start time: a changed file with docker_daemon_restart false leaves -# it alone, and with true restarts it. -- name: Verify that dockerd restarts only when asked +# The stand-in docker.service runs for real, so a restart shows in its start time. The first run turns the boot unit off and changes +# daemon.json with docker_daemon_restart false: the unit goes, the other stays and dockerd keeps running. The second turns everything +# back on with docker_daemon_restart true: the boot unit returns and dockerd restarts. +- name: Verify the unit inputs and that dockerd restarts only when asked hosts: all vars: docker_gpg_url: file:///srv/docker-stub-repo/docker.asc docker_keyring_checksum: "{{ docker_stub_key.stat.checksum }}" docker_repo_base_url: file:///srv/docker-stub-repo docker_users: [moleculeuser] - docker_start_missed: true docker_stop_at_shutdown: true docker_stop_at_shutdown_timeout: 20 docker_log_driver: local docker_log_max_size: 10m docker_log_max_file: "3" docker_live_restore: true + docker_verify_unit_paths: + - /usr/local/sbin/docker-start-missed + - /etc/systemd/system/docker-start-missed.service + - /usr/local/sbin/docker-stop-at-shutdown tasks: - name: Stat the stand-in repository key ansible.builtin.stat: @@ -397,10 +360,11 @@ register: docker_verify_before changed_when: false - - name: Apply a changed setting with docker_daemon_restart false + - name: Apply the boot unit off and a changed setting with docker_daemon_restart false ansible.builtin.include_role: name: mortis.kamino.docker vars: + docker_start_missed: false docker_daemon_options: {max-concurrent-downloads: 5} docker_daemon_restart: false @@ -409,10 +373,30 @@ register: docker_verify_kept changed_when: false - - name: Apply another change with docker_daemon_restart true + - name: Stat the boot unit's files and the shutdown unit's script + ansible.builtin.stat: + path: "{{ item }}" + loop: "{{ docker_verify_unit_paths }}" + register: docker_verify_off + + - name: Read daemon.json + ansible.builtin.slurp: + src: /etc/docker/daemon.json + register: docker_verify_daemon_kept + + - name: The boot unit is gone, the shutdown unit is still there, and the changed file left dockerd running + ansible.builtin.assert: + that: + - docker_verify_off.results | map(attribute='stat.exists') | list == [false, false, true] + - (docker_verify_daemon_kept.content | b64decode | from_json)['max-concurrent-downloads'] == 5 + - docker_verify_kept.stdout == docker_verify_before.stdout + quiet: true + + - name: Apply both units on and another change with docker_daemon_restart true ansible.builtin.include_role: name: mortis.kamino.docker vars: + docker_start_missed: true docker_daemon_options: {max-concurrent-downloads: 6} docker_daemon_restart: true @@ -421,17 +405,23 @@ register: docker_verify_restarted changed_when: false - - name: Read daemon.json + - name: Stat the unit files again + ansible.builtin.stat: + path: "{{ item }}" + loop: "{{ docker_verify_unit_paths }}" + register: docker_verify_on + + - name: Read daemon.json again ansible.builtin.slurp: src: /etc/docker/daemon.json register: docker_verify_daemon_after - - name: The first change left dockerd alone and the second restarted it + - name: Both units are back and the second change restarted dockerd ansible.builtin.assert: that: - - docker_verify_kept.stdout == docker_verify_before.stdout - - docker_verify_restarted.stdout != docker_verify_kept.stdout + - docker_verify_on.results | map(attribute='stat.exists') | unique | list == [true] - (docker_verify_daemon_after.content | b64decode | from_json)['max-concurrent-downloads'] == 6 + - docker_verify_restarted.stdout != docker_verify_kept.stdout quiet: true # A key that does not match docker_keyring_checksum fails at the key download, so the source line and packages are untouched. It goes to a separate path, so From 28655734290e4bcb3a3f9992f6acebf0e2f08601 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sat, 28 Nov 2026 20:39:32 +0000 Subject: [PATCH 2/3] test(gitea_runner): fold the disk-pressure run into the failed-download case The verify step ran the whole role once only to set the disk threshold to 0. Prune runs before update in tasks/main.yml, so the failed-download run can carry that input: the pressure units are removed before the download fails at staging. The exact staging message the rescue asserts comes only from update.yml, so a prune error still fails it. The run with the scenario's inputs stays before the remove path, which needs the units back. The forced re-registration child runs now start once instead of per host: they check only controller state and group_vars, and run_once gives every host the registered results. Closes #459 Assisted-by: Claude Code --- .../gitea_runner/molecule/default/verify.yml | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/roles/gitea_runner/molecule/default/verify.yml b/roles/gitea_runner/molecule/default/verify.yml index 8c2b279..3758388 100644 --- a/roles/gitea_runner/molecule/default/verify.yml +++ b/roles/gitea_runner/molecule/default/verify.yml @@ -359,23 +359,26 @@ loop_var: gitea_runner_test_path # 6.0.2 has a wrong checksum file (prepare.yml): the download must fail before anything is -# stopped, so the runner keeps running 6.0.1. -- name: Verify a failed download leaves the runner running +# stopped, so the runner keeps running 6.0.1. The same run sets the disk threshold to 0: prune +# runs before update, so the pressure units are already removed when the download fails. +- name: Verify a failed download leaves the runner running, and turning the pressure prune off hosts: all gather_facts: false tasks: - name: Update to a release whose checksum does not match block: - - name: Include the role with gitea_runner_version 6.0.2 + - name: Include the role with gitea_runner_version 6.0.2 and the disk threshold at 0 ansible.builtin.include_role: name: mortis.kamino.gitea_runner vars: gitea_runner_version: 6.0.2 + gitea_runner_docker_prune_disk_threshold_percent: 0 - name: Fail because the include returned ansible.builtin.fail: msg: The role accepted a binary with a wrong checksum rescue: + # The message comes only from the staging rescue, so a prune error fails this assert. - name: The staging failed, and nothing else failed first ansible.builtin.assert: that: @@ -407,6 +410,31 @@ - not gitea_runner_test_staged.stat.exists quiet: true + - name: Stat the pressure units and script + ansible.builtin.stat: + path: "{{ gitea_runner_test_path }}" + loop: + - /etc/systemd/system/gitea-runner-docker-prune-pressure.service + - /etc/systemd/system/gitea-runner-docker-prune-pressure.timer + - /usr/local/sbin/gitea-runner-docker-prune-disk-check + loop_control: + loop_var: gitea_runner_test_path + register: gitea_runner_test_pressure_off + + - name: Ask systemd about the pressure timer after turning it off + ansible.builtin.systemd: + name: gitea-runner-docker-prune-pressure.timer + register: gitea_runner_test_pressure_timer_off + # The module errors for a unit that no longer exists, which is also a pass. + failed_when: false + + - name: The pressure units are gone and the timer is not active + ansible.builtin.assert: + that: + - gitea_runner_test_pressure_off.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0 + - gitea_runner_test_pressure_timer_off.status.ActiveState | default('inactive') != 'active' + quiet: true + # Each input assert, through the main entry point. Every one runs in validate.yml, before any # change. - name: Verify the input asserts @@ -448,8 +476,9 @@ label: "{{ gitea_runner_test_refused.name }}" # The CI guard and the mint-before-drop order of a forced re-registration, through a child -# ansible-playbook against this instance (see force_register.yml). Neither case may touch the -# registration or stop the runner. +# ansible-playbook against one instance (see force_register.yml). Neither case may touch the +# registration or stop the runner. The children run once: what they check is controller state +# and group_vars, the same for every host, and run_once gives every host their results. - name: Verify the forced re-registration guards hosts: all gather_facts: false @@ -465,6 +494,7 @@ - name: Force a re-registration under each CI variable, as a child process with only that one set delegate_to: localhost + run_once: true ansible.builtin.command: argv: - ansible-playbook @@ -497,6 +527,7 @@ - name: Force a re-registration outside CI with no token host, as a child process delegate_to: localhost + run_once: true ansible.builtin.command: argv: - ansible-playbook @@ -550,43 +581,12 @@ - gitea_runner_test_unit.status.ActiveState == 'active' quiet: true -# A threshold of 0 removes the pressure units; the run after it, with the scenario's inputs, +# The failed-download run above removed the pressure units; this run, with the scenario's inputs, # puts them back, so the remove path below still has them to remove. -- name: Verify turning the pressure prune off +- name: Verify turning the pressure prune on again hosts: all gather_facts: false tasks: - - name: Run the role with the disk threshold at 0 - ansible.builtin.include_role: - name: mortis.kamino.gitea_runner - vars: - gitea_runner_docker_prune_disk_threshold_percent: 0 - - - name: Stat the pressure units and script - ansible.builtin.stat: - path: "{{ gitea_runner_test_path }}" - loop: - - /etc/systemd/system/gitea-runner-docker-prune-pressure.service - - /etc/systemd/system/gitea-runner-docker-prune-pressure.timer - - /usr/local/sbin/gitea-runner-docker-prune-disk-check - loop_control: - loop_var: gitea_runner_test_path - register: gitea_runner_test_pressure_off - - - name: Ask systemd about the pressure timer after turning it off - ansible.builtin.systemd: - name: gitea-runner-docker-prune-pressure.timer - register: gitea_runner_test_pressure_timer_off - # The module errors for a unit that no longer exists, which is also a pass. - failed_when: false - - - name: The pressure units are gone and the timer is not active - ansible.builtin.assert: - that: - - gitea_runner_test_pressure_off.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0 - - gitea_runner_test_pressure_timer_off.status.ActiveState | default('inactive') != 'active' - quiet: true - - name: Run the role again with the scenario's inputs ansible.builtin.include_role: name: mortis.kamino.gitea_runner From f766666476633fcd43bafcd0515fb1517deb3887 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Sat, 28 Nov 2026 20:40:45 +0000 Subject: [PATCH 3/3] test(system_baseline): run the vzdump guard cases against the guard alone 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 --- .../456-system-baseline-purge-batch.yml | 4 ++ roles/system_baseline/README.md | 4 +- .../molecule/default/converge.yml | 1 + .../default/tasks/vzdump_guard_case.yml | 15 +++--- .../molecule/default/verify.yml | 20 ++++++- roles/system_baseline/tasks/packages.yml | 8 +-- roles/system_baseline/tasks/update.yml | 54 ++----------------- roles/system_baseline/tasks/vzdump_guard.yml | 52 ++++++++++++++++++ 8 files changed, 93 insertions(+), 65 deletions(-) create mode 100644 changelogs/fragments/456-system-baseline-purge-batch.yml create mode 100644 roles/system_baseline/tasks/vzdump_guard.yml diff --git a/changelogs/fragments/456-system-baseline-purge-batch.yml b/changelogs/fragments/456-system-baseline-purge-batch.yml new file mode 100644 index 0000000..6ce6f74 --- /dev/null +++ b/changelogs/fragments/456-system-baseline-purge-batch.yml @@ -0,0 +1,4 @@ +--- +trivial: + - >- + system_baseline - Purge the unwanted packages that are installed in one apt call instead of one call per package. diff --git a/roles/system_baseline/README.md b/roles/system_baseline/README.md index 2af7464..40b6c4d 100644 --- a/roles/system_baseline/README.md +++ b/roles/system_baseline/README.md @@ -134,8 +134,8 @@ The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_ - 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. - 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 runs the `update` entry point in check mode on the Ubuntu container with `system_baseline_system_type: pve` and a `pvesh` stub, in seven cases (a running, a finished or no vzdump task, the input off, `ubuntu_lxc`), and asserts the fact that decides the upgrade and that `pvesh` was run, with `--source active`, only when it should be. It does not assert that the apt task itself was skipped. The stub stands for the real answer, which no CI image has. +- 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, that the connection is reset afterwards, and that the vzdump guard is imported before the upgrade, whose `when` reads the guard's fact: the scenario skips the `update` tag, so the upgrade itself never runs there. +- Verify runs the vzdump guard in check mode on the Ubuntu container with `system_baseline_system_type: pve` and a `pvesh` stub, in seven cases (a running, a finished or no vzdump task, the input off, `ubuntu_lxc`); six run the guard's task file alone and the `ubuntu_lxc` case runs the whole `update` entry point. Each case asserts the fact that decides the upgrade and that `pvesh` was run, with `--source active`, only when it should be. It does not assert that the apt task itself was skipped. The stub stands for the real answer, which no CI image has. - 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. diff --git a/roles/system_baseline/molecule/default/converge.yml b/roles/system_baseline/molecule/default/converge.yml index be9aa95..11439fe 100644 --- a/roles/system_baseline/molecule/default/converge.yml +++ b/roles/system_baseline/molecule/default/converge.yml @@ -2,6 +2,7 @@ - name: Converge the LXC profile hosts: all gather_facts: true + gather_subset: [min] vars: system_baseline_system_type: ubuntu_lxc system_baseline_extra_packages: [jq] diff --git a/roles/system_baseline/molecule/default/tasks/vzdump_guard_case.yml b/roles/system_baseline/molecule/default/tasks/vzdump_guard_case.yml index 9062f2d..08c25d4 100644 --- a/roles/system_baseline/molecule/default/tasks/vzdump_guard_case.yml +++ b/roles/system_baseline/molecule/default/tasks/vzdump_guard_case.yml @@ -1,7 +1,7 @@ --- -# One case of the vzdump guard: a pvesh stub answers with system_baseline_case_answer, the update entry point runs in check mode, and the -# fact that decides the upgrade, and whether pvesh was asked at all, are compared with what the case expects. Kept outside the role's own tasks: -# no CI image is a Proxmox node, so the stub stands for the real `pvesh get /nodes//tasks` answer. +# One case of the vzdump guard: a pvesh stub answers with system_baseline_case.answer, the role's tasks_from file (the guard alone unless the +# case names update) runs in check mode, and the fact that decides the upgrade, and whether pvesh was asked at all, are compared with what the +# case expects. Kept outside the role's own tasks: no CI image is a Proxmox node, so the stub stands for the real `pvesh get` answer. - name: Write the pvesh stub check_mode: false ansible.builtin.copy: @@ -14,8 +14,9 @@ {{ system_baseline_case.answer | to_json }} JSON -- name: Create the apt scratch directory, which a check mode run does not +- name: Create the apt scratch directory, which a check mode run of the update entry point does not check_mode: false + when: system_baseline_case.tasks_from | default('vzdump_guard') == 'update' ansible.builtin.file: path: /var/cache/system-baseline-apt-tmp state: directory @@ -26,13 +27,13 @@ path: /var/tmp/pvesh-calls state: absent -- name: Run the update entry point in check mode +- name: Run the case's tasks in check mode check_mode: true block: - - name: Include system_baseline, tasks_from update + - name: Include system_baseline, tasks_from {{ system_baseline_case.tasks_from | default('vzdump_guard') }} ansible.builtin.include_role: name: mortis.kamino.system_baseline - tasks_from: update + tasks_from: "{{ system_baseline_case.tasks_from | default('vzdump_guard') }}" vars: system_baseline_system_type: "{{ system_baseline_case.type }}" system_baseline_skip_upgrade_during_vzdump: "{{ system_baseline_case.input }}" diff --git a/roles/system_baseline/molecule/default/verify.yml b/roles/system_baseline/molecule/default/verify.yml index 1cae3ad..c25bbb7 100644 --- a/roles/system_baseline/molecule/default/verify.yml +++ b/roles/system_baseline/molecule/default/verify.yml @@ -464,6 +464,19 @@ - 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. @@ -471,6 +484,7 @@ - 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: @@ -785,7 +799,8 @@ 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. +# 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 @@ -801,7 +816,7 @@ - {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}]} + - {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 @@ -810,6 +825,7 @@ - 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: diff --git a/roles/system_baseline/tasks/packages.yml b/roles/system_baseline/tasks/packages.yml index 149388b..c35c489 100644 --- a/roles/system_baseline/tasks/packages.yml +++ b/roles/system_baseline/tasks/packages.yml @@ -12,11 +12,13 @@ manager: auto become: true +# One apt call for every unwanted package that is installed, skipped when none is. - name: Remove unnecessary packages if installed ansible.builtin.package: - name: "{{ item }}" + name: "{{ __system_baseline_purge_present }}" state: absent purge: true - loop: "{{ __system_baseline_purge_packages }}" - when: item in ansible_facts.packages + vars: + __system_baseline_purge_present: "{{ __system_baseline_purge_packages | select('in', ansible_facts.packages) | list }}" + when: __system_baseline_purge_present | length > 0 become: true diff --git a/roles/system_baseline/tasks/update.yml b/roles/system_baseline/tasks/update.yml index e9ec0eb..f10c59f 100644 --- a/roles/system_baseline/tasks/update.yml +++ b/roles/system_baseline/tasks/update.yml @@ -21,57 +21,9 @@ mode: "0700" become: true -# Opt-in guard (system_baseline_skip_upgrade_during_vzdump, pve only): an upgrade can restart Proxmox services while a backup holds a snapshot -# of a guest, so the upgrade waits for the next run when this node has a vzdump task without an end time. Both tasks read state only, so -# they run in check mode too; they are skipped where the upgrade is (a dry run of the main flow). `localhost` is the node's own alias, so no -# node name and no gathered facts are needed. --source active lists the running tasks: the default, archive, holds only finished ones. The -# fact is set on every run, so a guard that is off or skipped never inherits the answer of an earlier run in the same play. -- name: List the recent Proxmox tasks of this node - ansible.builtin.command: - argv: - - pvesh - - get - - /nodes/localhost/tasks - - --source - - active - - --limit - - "0" - - --output-format - - json - register: __system_baseline_pve_tasks - changed_when: false - check_mode: false - become: true - when: - - system_baseline_skip_upgrade_during_vzdump | bool - - system_baseline_system_type | default('') == 'pve' - - not (ansible_check_mode and __system_baseline_main_flow | default(false)) - -- name: Check that pvesh answered with a list of tasks - ansible.builtin.assert: - that: - - __system_baseline_pve_tasks.stdout | from_json is sequence - - __system_baseline_pve_tasks.stdout | from_json is not string - - __system_baseline_pve_tasks.stdout | from_json is not mapping - fail_msg: pvesh did not answer with a JSON list of tasks, so the role cannot tell whether a backup is running. - quiet: true - when: __system_baseline_pve_tasks is not skipped - -- name: Note whether a vzdump backup is running on this node - ansible.builtin.set_fact: - __system_baseline_vzdump_running: >- - {{ __system_baseline_pve_tasks is not skipped - and (__system_baseline_pve_tasks.stdout | from_json - | selectattr('type', 'equalto', 'vzdump') - | rejectattr('endtime', 'defined') - | list | length) > 0 }} - -- name: Skip the upgrade while a vzdump backup is running - ansible.builtin.debug: - msg: >- - Skipping the apt upgrade on {{ inventory_hostname }}: a vzdump task is running on this node. Run the update again after the backup - has finished. - when: __system_baseline_vzdump_running | default(false) +# import_tasks, not include_tasks: the update tag, the caller's when and __system_baseline_main_flow must reach the guard's tasks. +- name: Decide whether a vzdump backup holds back the upgrade + ansible.builtin.import_tasks: vzdump_guard.yml # safe is the apt module's name for the plain upgrade (apt-get upgrade --with-new-pkgs), what `true` meant here before; dist runs # apt-get dist-upgrade (profile key apt_upgrade, `pve` by default). diff --git a/roles/system_baseline/tasks/vzdump_guard.yml b/roles/system_baseline/tasks/vzdump_guard.yml new file mode 100644 index 0000000..6b9c635 --- /dev/null +++ b/roles/system_baseline/tasks/vzdump_guard.yml @@ -0,0 +1,52 @@ +--- +# Opt-in guard (system_baseline_skip_upgrade_during_vzdump, pve only): an upgrade can restart Proxmox services while a backup holds a snapshot +# of a guest, so the upgrade waits for the next run when this node has a vzdump task without an end time. Both tasks read state only, so +# they run in check mode too; they are skipped where the upgrade is (a dry run of the main flow). `localhost` is the node's own alias, so no +# node name and no gathered facts are needed. --source active lists the running tasks: the default, archive, holds only finished ones. The +# fact is set on every run, so a guard that is off or skipped never inherits the answer of an earlier run in the same play. +- name: List the recent Proxmox tasks of this node + ansible.builtin.command: + argv: + - pvesh + - get + - /nodes/localhost/tasks + - --source + - active + - --limit + - "0" + - --output-format + - json + register: __system_baseline_pve_tasks + changed_when: false + check_mode: false + become: true + when: + - system_baseline_skip_upgrade_during_vzdump | bool + - system_baseline_system_type | default('') == 'pve' + - not (ansible_check_mode and __system_baseline_main_flow | default(false)) + +- name: Check that pvesh answered with a list of tasks + ansible.builtin.assert: + that: + - __system_baseline_pve_tasks.stdout | from_json is sequence + - __system_baseline_pve_tasks.stdout | from_json is not string + - __system_baseline_pve_tasks.stdout | from_json is not mapping + fail_msg: pvesh did not answer with a JSON list of tasks, so the role cannot tell whether a backup is running. + quiet: true + when: __system_baseline_pve_tasks is not skipped + +- name: Note whether a vzdump backup is running on this node + ansible.builtin.set_fact: + __system_baseline_vzdump_running: >- + {{ __system_baseline_pve_tasks is not skipped + and (__system_baseline_pve_tasks.stdout | from_json + | selectattr('type', 'equalto', 'vzdump') + | rejectattr('endtime', 'defined') + | list | length) > 0 }} + +- name: Skip the upgrade while a vzdump backup is running + ansible.builtin.debug: + msg: >- + Skipping the apt upgrade on {{ inventory_hostname }}: a vzdump task is running on this node. Run the update again after the backup + has finished. + when: __system_baseline_vzdump_running | default(false)