feat(system_baseline): optionally skip the upgrade while a vzdump backup is running
Build / build (pull_request) Successful in 42s
Lint / lint (pull_request) Successful in 2m48s
Molecule / molecule (pull_request) Successful in 15m25s

An apt upgrade of a Proxmox node can restart Proxmox services while a
backup holds a snapshot of a guest, and the role had no way to say
"not now".

system_baseline_skip_upgrade_during_vzdump (bool, default false) makes
the main flow and the update entry point ask the node for its running
tasks (pvesh get /nodes/localhost/tasks --source active) before the
upgrade, on the pve system type only. A vzdump task without an end time
skips the upgrade with a message; autoremove, autoclean and the reboot
check still run. The role does not wait for the backup. A pvesh answer
that is not a JSON list stops the run. With the default no pvesh
command runs.

Closes #400

Assisted-by: Claude Code:claude-sonnet-5-5
This commit is contained in:
Dragonish committed 2026-11-26 22:49:33 +00:00
1 parent 1afce962a0
commit 5519733312
7 files changed
+170 -1

No files matched your search

+55 -1
View File
@@ -21,6 +21,58 @@
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)
# 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).
- name: Update & upgrade apt packages
@@ -31,7 +83,9 @@
environment:
TMPDIR: "{{ system_baseline_apt_tmpdir }}"
become: true
when: not (ansible_check_mode and __system_baseline_main_flow | default(false))
when:
- not (ansible_check_mode and __system_baseline_main_flow | default(false))
- not (__system_baseline_vzdump_running | default(false))
# autoremove must stay in this task: the apt module accepts autoclean alone only together with one of autoremove, name, update_cache or upgrade.
- name: Remove unused packages and clean the apt cache