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
56 lines
2.7 KiB
YAML
56 lines
2.7 KiB
YAML
---
|
|
# In the main flow a dry run (--check) does not run the upgrade: a package that is only waiting for the next patch run is not drift, and
|
|
# the package module reports `changed` for it, so a scheduled dry run flagged every host whenever a package landed in between. The
|
|
# tasks_from: update entry point is an explicit request to update and still previews the upgrade in check mode: only main.yml sets
|
|
# __system_baseline_main_flow. Leftover packages (autoremove) and the cache (autoclean) stay checked either way.
|
|
- name: Validate the apt upgrade mode
|
|
ansible.builtin.import_tasks: validate_apt_upgrade.yml
|
|
|
|
- name: Validate the apt scratch directory
|
|
ansible.builtin.import_tasks: validate_apt_tmpdir.yml
|
|
|
|
# apt and the package module put their temporary files, including the staged .deb files, in TMPDIR. A restart of ssh.service during the upgrade
|
|
# (an openssh-server update) deletes a PrivateTmp /tmp, so TMPDIR points at a directory systemd leaves alone. Created in check mode too,
|
|
# because the autoremove below runs there with the same TMPDIR.
|
|
- name: Create the apt scratch directory
|
|
ansible.builtin.file:
|
|
path: "{{ system_baseline_apt_tmpdir }}"
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: "0700"
|
|
become: true
|
|
|
|
# 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).
|
|
- name: Update & upgrade apt packages
|
|
ansible.builtin.package:
|
|
update_cache: true
|
|
upgrade: "{{ system_baseline_apt_upgrade }}"
|
|
cache_valid_time: 3600
|
|
environment:
|
|
TMPDIR: "{{ system_baseline_apt_tmpdir }}"
|
|
become: true
|
|
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
|
|
ansible.builtin.package:
|
|
autoremove: true
|
|
autoclean: true
|
|
environment:
|
|
TMPDIR: "{{ system_baseline_apt_tmpdir }}"
|
|
become: true
|
|
|
|
# A restart of ssh.service ends the connection that was open during the upgrade; a new one gets a new private /tmp, which later tasks
|
|
# of the play (and a caller's own tasks) may use.
|
|
- name: Open a new connection after the upgrade
|
|
ansible.builtin.meta: reset_connection
|
|
when: not (ansible_check_mode and __system_baseline_main_flow | default(false))
|