Merge pull request 'feat(system_baseline): run the apt upgrade as dist-upgrade on the pve profile' (#334) from feat/329-pve-dist-upgrade into main
Lint / lint (push) Canceled after 0s
Molecule / molecule (push) Canceled after 0s
Build / build (push) Successful in 15s

Reviewed-on: #334
This commit was merged in pull request #334.
This commit is contained in:
Dragonish committed 2026-11-23 20:37:37 +00:00
commit e7edddcab2
8 files changed
+110 -5

No files matched your search

@@ -0,0 +1,10 @@
---
minor_changes:
- >-
system_baseline - Add the profile key ``apt_upgrade`` (``safe`` or ``dist``) and the input ``system_baseline_apt_upgrade`` that it resolves
to. The ``pve`` profile now upgrades packages with ``apt-get dist-upgrade``
(``apt full-upgrade``, which Proxmox VE documents), so packages that a plain upgrade
holds back (a new kernel, ``pve-manager``) are installed too; the Ubuntu profiles keep the plain upgrade. A ``pve`` host therefore receives
those packages on the next run: set ``system_baseline_reboot_if_required`` to ``false`` first if the role must not reboot it. The ``update``
entry point follows the input when ``system_baseline_system_type`` is set, and so can also remove packages on a ``pve`` host; it stays on
the plain upgrade when the type is not set, and now refuses an unknown mode.
+11 -2
View File
@@ -17,7 +17,7 @@ Ubuntu 24.04 (noble, covered by the molecule scenario), Ubuntu 22.04 (jammy) and
## Role variables
The resolved `system_baseline_*` inputs derived from the active profile (`_profile`, `_essential_packages`, `_remove_packages`, `_apt_periodic_settings`,
The resolved `system_baseline_*` inputs derived from the active profile (`_profile`, `_essential_packages`, `_remove_packages`, `_apt_periodic_settings`, `_apt_upgrade`,
`_unattended_upgrade_settings`, `_unattended_upgrade_origins`, `_sysctl_hardening`, `_secure_tmp_mounts`) are listed below but
deliberately not in the spec: their defaults index the profile by `system_baseline_system_type`, and the spec is
templated before `validate.yml` runs, so an invalid `system_baseline_system_type` would otherwise fail with a
@@ -32,6 +32,7 @@ templating error instead of the role's own message.
| `system_baseline_essential_packages` | from profile | no | Packages to install |
| `system_baseline_remove_packages` | from profile | no | Packages to purge when present |
| `system_baseline_apt_periodic_settings` | from profile | no | Keys for `20auto-upgrades` |
| `system_baseline_apt_upgrade` | from profile | no | `safe` or `dist`: how the role upgrades packages (`pve`: `dist`, the Ubuntu profiles: `safe`); see "Apt upgrade mode" |
| `system_baseline_unattended_upgrade_settings` | from profile | no | Keys for `50unattended-upgrades` |
| `system_baseline_unattended_upgrade_origins` | from profile | no | Pinned `Origins-Pattern` entries; `[]` keeps the distribution default (see below) |
| `system_baseline_unattended_upgrade_package_blacklist` | `[]` | no | Packages unattended-upgrades must not touch, as regular expressions (see below) |
@@ -120,6 +121,14 @@ system_baseline_tmux_windows:
`system_baseline_update: false` skips the package update of the main flow, for hosts patched by a separate, operator-run flow (for example a full upgrade with a rolling reboot). Everything else, unattended-upgrades included, still runs. The reboot check still runs as well, so set `system_baseline_reboot_if_required: false` too when that flow owns the reboot. Running the play with `--skip-tags update` skips the same task for one run only, and also the reboot.
## Apt upgrade mode
The profile key `apt_upgrade` (`safe` or `dist`, resolved to `system_baseline_apt_upgrade`) sets how the `update` flow upgrades packages. `safe` is `apt-get upgrade --with-new-pkgs`: it installs new dependencies but never removes a package, so an update that needs one removed is held back. `dist` is `apt-get dist-upgrade` (the same as `apt full-upgrade`), which can also remove packages. The `pve` profile uses `dist`, because the Proxmox VE documentation updates a node with `apt full-upgrade` and warns that a plain `apt upgrade` can leave a partially upgraded state; the Ubuntu profiles keep `safe`. Set `system_baseline_apt_upgrade` (or override the profile key) to change one host.
- A `pve` host that was upgraded with `safe` until now also receives, on the next run, the packages that a safe upgrade held back (a new kernel, `pve-manager` and its dependencies). That can restart Proxmox services, and a new kernel needs a reboot. `system_baseline_reboot_if_required` defaults to `true` and the reboot step reads `/var/run/reboot-required`, so set it to `false` before applying the role to a hypervisor you want to reboot yourself.
- The `update` entry point follows the same input: it upgrades with `dist` when `system_baseline_system_type` is `pve`. Without a `system_baseline_system_type` (the entry point does not require one) it stays on `safe`.
- Only the apt upgrade changes. Autoremove and autoclean, the check-mode skip and unattended-upgrades are as before; the example blacklist below keeps unattended-upgrades away from the Proxmox packages.
## Check mode
In a dry run (`--check`) the main flow does not run the apt upgrade: a package that is only waiting for the next patch run, or a package cache older than an hour, is not drift, and the package module reports both as `changed`, so a scheduled dry run would flag every host whenever a package landed in between. The autoremove and autoclean step still runs, and is checked: a leftover package it would remove is reported as `changed`, on purpose. `apt-get autoclean` runs in this step in a real run, in the main flow and in the `update` entry point. The `update` entry point is unchanged: it is an explicit request to update, so in check mode it still previews the upgrade.
@@ -138,7 +147,7 @@ A profile's `unattended_upgrade_origins` list pins the origins unattended-upgrad
`system_baseline_unattended_upgrade_package_blacklist` keeps individual packages out of unattended-upgrades, for a host whose kernel or drivers must not change (for example one with hardware passthrough). Each entry is a regular expression matched against the package name, so `linux-image-.*` covers every kernel image; anchor an entry (`^name$`) when it must not match longer names too. A non-empty list is written to `/etc/apt/apt.conf.d/90unattended-upgrades-blacklist` as `Unattended-Upgrade::Package-Blacklist`. apt appends list entries across files, so the entries are added to those of `50unattended-upgrades`, which is not edited. An empty list removes the file. An entry may not hold a double quote, a backslash or a line break.
- Example for Proxmox VE hosts: packages that should only ever change through a deliberate `apt dist-upgrade` (Proxmox's documented way to update, because its packages add and remove dependencies). The `pve` profile already pins unattended-upgrades to Debian's origins, so these never come from the Proxmox repository through unattended-upgrades; the list keeps that true if the pin is ever removed or widened. Adjust it to the repositories you use:
- Example for Proxmox VE hosts: packages that should only ever change through a deliberate `apt full-upgrade` (Proxmox's documented way to update, which can also remove packages to satisfy dependencies). The `pve` profile already pins unattended-upgrades to Debian's origins, so these never come from the Proxmox repository through unattended-upgrades; the list keeps that true if the pin is ever removed or widened. Adjust it to the repositories you use:
```yaml
system_baseline_unattended_upgrade_package_blacklist:
+13
View File
@@ -67,6 +67,11 @@ system_baseline_profiles:
"APT::Periodic::AutocleanInterval": 7
"APT::Periodic::Unattended-Upgrade": true
# How the main flow upgrades packages: dist runs apt-get dist-upgrade, which can also remove packages that a Proxmox VE update replaces;
# a safe upgrade holds those back. A Proxmox host is updated with full-upgrade, the same as dist-upgrade (Proxmox's documented way);
# the Ubuntu profiles keep safe.
apt_upgrade: dist
unattended_upgrade_settings:
"Unattended-Upgrade::Automatic-Reboot": false
"Unattended-Upgrade::Automatic-Reboot-Time": "03:00"
@@ -134,6 +139,8 @@ system_baseline_profiles:
"APT::Periodic::AutocleanInterval": 7
"APT::Periodic::Unattended-Upgrade": true
apt_upgrade: safe
unattended_upgrade_settings:
"Unattended-Upgrade::Automatic-Reboot": false
"Unattended-Upgrade::Automatic-Reboot-Time": "05:00"
@@ -192,6 +199,8 @@ system_baseline_profiles:
"APT::Periodic::AutocleanInterval": 7
"APT::Periodic::Unattended-Upgrade": true
apt_upgrade: safe
unattended_upgrade_settings:
"Unattended-Upgrade::Automatic-Reboot": false
"Unattended-Upgrade::Automatic-Reboot-Time": "04:00"
@@ -227,6 +236,10 @@ system_baseline_profile: >-
system_baseline_essential_packages: "{{ system_baseline_profile.essential_packages }}"
system_baseline_remove_packages: "{{ system_baseline_profile.remove_packages }}"
system_baseline_apt_periodic_settings: "{{ system_baseline_profile.apt_periodic_settings }}"
# safe or dist (see the profiles). Guarded: the tasks_from: update entry point needs no system_baseline_system_type, and without one it
# stays on a safe upgrade instead of failing on the profile lookup. default('safe'): a system_baseline_profiles written before this key
# existed keeps the plain upgrade.
system_baseline_apt_upgrade: "{{ (system_baseline_profile.apt_upgrade | default('safe')) if system_baseline_system_type is defined else 'safe' }}"
system_baseline_unattended_upgrade_settings: "{{ system_baseline_profile.unattended_upgrade_settings }}"
# default([]): a system_baseline_profiles written before this key existed keeps the distribution default.
system_baseline_unattended_upgrade_origins: "{{ system_baseline_profile.unattended_upgrade_origins | default([]) }}"
@@ -10,7 +10,8 @@ argument_specs:
- Needs gathered facts, because the reboot check reads C(ansible_os_family).
- >-
The resolved inputs C(system_baseline_profile), C(system_baseline_essential_packages),
C(system_baseline_remove_packages), C(system_baseline_apt_periodic_settings), C(system_baseline_unattended_upgrade_settings),
C(system_baseline_remove_packages), C(system_baseline_apt_periodic_settings), C(system_baseline_apt_upgrade),
C(system_baseline_unattended_upgrade_settings),
C(system_baseline_unattended_upgrade_origins), C(system_baseline_sysctl_hardening) and C(system_baseline_secure_tmp_mounts) are
deliberately not listed. Their defaults are
Jinja that indexes C(system_baseline_profiles) with C(system_baseline_system_type), and the argument spec is validated (templated) before
@@ -30,7 +31,7 @@ argument_specs:
type: dict
description:
- >-
Policy per system type. Each profile holds C(essential_packages), C(remove_packages), C(apt_periodic_settings),
Policy per system type. Each profile holds C(essential_packages), C(remove_packages), C(apt_periodic_settings), C(apt_upgrade),
C(unattended_upgrade_settings), C(unattended_upgrade_origins), C(sysctl_hardening) and C(secure_tmp_mounts).
- >-
C(unattended_upgrade_origins) is a list of unattended-upgrades C(Origins-Pattern) entries. A non-empty list is written to
@@ -39,6 +40,9 @@ argument_specs:
to it. An empty or missing list removes that file and leaves the distribution default. The C(pve) profile pins Debian's
point-release and security origins; the C(ubuntu_*) profiles pin nothing. Entries may not hold a double quote, a backslash or a
line break.
- >-
C(apt_upgrade) is C(safe) or C(dist) and sets how the role upgrades packages: C(dist) runs C(apt-get dist-upgrade), which can also
remove packages that an update replaces. The C(pve) profile uses C(dist), the Ubuntu profiles C(safe).
- Overriding it replaces all profiles. To change part of one profile use C(system_baseline_profile_overrides).
system_baseline_profile_overrides:
type: dict
@@ -19,6 +19,51 @@
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
# 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
@@ -69,6 +114,7 @@
- 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 == []
quiet: true
@@ -92,6 +138,7 @@
- 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 == []
quiet: true
@@ -102,6 +149,7 @@
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:
@@ -116,6 +164,7 @@
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"
+6 -1
View File
@@ -3,10 +3,15 @@
# 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
# 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: true
upgrade: "{{ system_baseline_apt_upgrade }}"
cache_valid_time: 3600
become: true
when: not (ansible_check_mode and __system_baseline_main_flow | default(false))
+4
View File
@@ -35,6 +35,10 @@
when: system_baseline_tmux_autostart | bool
tags: always
- name: Validate the apt upgrade mode
ansible.builtin.import_tasks: validate_apt_upgrade.yml
tags: always
# Each package pattern is written inside a double-quoted apt.conf string, like the origins below: the same characters are refused.
- name: Validate the unattended-upgrades package blacklist
ansible.builtin.assert:
@@ -0,0 +1,11 @@
---
# Shared by validate.yml and update.yml: the tasks_from: update entry point does not run validate.yml, and an unknown mode such as `full`
# (an apt module value that calls aptitude, which may not be installed) must stop the run before anything changes.
- name: Validate the apt upgrade mode
ansible.builtin.assert:
that:
- system_baseline_apt_upgrade in ['safe', 'dist']
fail_msg: >-
system_baseline_apt_upgrade is '{{ system_baseline_apt_upgrade }}' and must be safe or dist.
quiet: true
tags: always