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
274 lines
28 KiB
Markdown
274 lines
28 KiB
Markdown
# system_baseline
|
|
|
|
Applies an OS baseline chosen by `system_baseline_system_type`: apt upgrade, package install and removal, unattended-upgrades, locale, timezone, a journal size cap, sysctl hardening, tmpfs mounts, an optional tmux session on SSH login and an optional reboot. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth.
|
|
|
|
## Supported platforms
|
|
|
|
Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The tasks use apt and the reboot check is limited to the Debian family. See `meta/main.yml`.
|
|
|
|
Untested platforms: Debian 13 (trixie, Proxmox hosts), listed in `meta/main.yml` but not verified by a test.
|
|
|
|
The role targets Ubuntu guests (the `ubuntu_lxc` and `ubuntu_vm` profiles) and Proxmox VE hosts on Debian (the `pve` profile).
|
|
|
|
## Requirements and run order
|
|
|
|
- Facts must be gathered (`gather_facts: true`); `reboot.yml` reads `ansible_facts['os_family']`.
|
|
- `system_baseline_system_type` is required and has no default (the role does not read a global such as `system_type`; map it in the inventory). Valid values: `ubuntu_lxc`, `ubuntu_vm` or `pve`.
|
|
- Use it by its fully qualified name, `mortis.kamino.system_baseline`.
|
|
- Collections: `community.general` (locale, timezone) and `ansible.posix` (sysctl, mount).
|
|
- Run it after the roles that manage users and SSH, and before the roles that harden services and manage firewalls and jails. A firewall role that rewrites sysctl values (ufw re-applies its stock `/etc/ufw/sysctl.conf` when it is enabled) must run after this role and needs the same values as this role's `sysctl_hardening` to keep them.
|
|
- Role dependencies: none.
|
|
|
|
## Role variables
|
|
|
|
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
|
|
templating error instead of the role's own message.
|
|
|
|
| Name | Default | Required | Description |
|
|
| --- | --- | --- | --- |
|
|
| `system_baseline_system_type` | none | yes | Profile selector, validated by `tasks/validate.yml` |
|
|
| `system_baseline_profiles` | see `defaults/main.yml` | no | Policy per system type; overriding replaces all profiles |
|
|
| `system_baseline_profile_overrides` | `{}` | no | Per-system-type overrides, merged recursively into the active profile |
|
|
| `system_baseline_profile` | derived | no | Active profile after overrides |
|
|
| `system_baseline_essential_packages` | from profile | no | Packages to install |
|
|
| `system_baseline_remove_packages` | from profile | no | Packages to purge when present |
|
|
| `system_baseline_extra_packages` | `[]` | no | Packages to install in addition to the resolved list; appends, see "Adding packages to a profile" |
|
|
| `system_baseline_extra_remove_packages` | `[]` | no | Packages to purge in addition to the resolved list; appends |
|
|
| `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_skip_upgrade_during_vzdump` | `false` | no | `pve` only: skip the apt upgrade while a vzdump backup is running on the node (see "Skipping the upgrade during a backup") |
|
|
| `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) |
|
|
| `system_baseline_sysctl_hardening` | from profile | no | List of `name` and `value` sysctl pairs |
|
|
| `system_baseline_secure_tmp_mounts` | from profile | no | Paths remounted as tmpfs with `noexec,nosuid,nodev` |
|
|
| `system_baseline_journal_max_use` | `200M` | no | Upper bound of the persistent journal (journald `SystemMaxUse`): a number with an optional upper-case `B`, `K`, `M`, `G`, `T`, `P` or `E`, such as `1.5G`; a bare number is bytes. journald does not take `infinity`. Empty leaves the host alone and removes nothing a former run wrote (see "Leaving journald alone") |
|
|
| `system_baseline_tmux_autostart` | `false` | no | Attach interactive SSH logins to a tmux session (`ubuntu_lxc` and `ubuntu_vm` only) |
|
|
| `system_baseline_tmux_session` | `main` | no | Session name, `A-Za-z0-9_-`, up to 32 characters |
|
|
| `system_baseline_tmux_windows` | `[]` | no | `{name, command}` windows made when the session is created |
|
|
| `system_baseline_timezone` | `Etc/UTC` | no | Timezone |
|
|
| `system_baseline_locale` | `en_US.UTF-8` | no | Locale |
|
|
| `system_baseline_reboot_if_required` | `true` | no | Reboot when `/var/run/reboot-required` exists |
|
|
| `system_baseline_reboot_throttle` | `0` | no | Hosts that reboot at the same time; `0` is no limit, `1` one at a time (see "Rebooting one host at a time") |
|
|
| `system_baseline_reboot_post_delay` | `0` | no | Seconds to wait after a rebooted host answers again |
|
|
| `system_baseline_apt_daily_timeout` | empty | no | Systemd time span written as `TimeoutStartSec` of `apt-daily.service`; empty leaves the host alone (see "Bounding a hung apt-daily.service") |
|
|
| `system_baseline_apt_tmpdir` | `/var/cache/system-baseline-apt-tmp` | no | Directory the apt upgrade uses as `TMPDIR`; absolute, never `/tmp` or `/var/tmp` (see "Apt scratch directory") |
|
|
| `system_baseline_update` | `true` | no | Run the package update in the main flow; `false` skips it (the `update` entry point ignores it) |
|
|
|
|
A flat `system_baseline_*` input replaces that value entirely. To change one key of a profile dict, use `system_baseline_profile_overrides`, for example to let unattended-upgrades reboot a group on its own:
|
|
|
|
```yaml
|
|
system_baseline_profile_overrides:
|
|
ubuntu_vm:
|
|
unattended_upgrade_settings:
|
|
"Unattended-Upgrade::Automatic-Reboot": true
|
|
```
|
|
|
|
## Entry points
|
|
|
|
- `main`: the whole baseline, as in the example play.
|
|
- `tasks_from: update`: see [`update`](#update).
|
|
- `tasks_from: reboot`: see [`reboot`](#reboot).
|
|
|
|
The two task files besides `main` are a supported interface, for a caller that drives its own reboot (for example a Kubernetes node patch flow that cordons and drains first). Their names, the fact name and the behaviour below follow the Collection's semantic versioning: changing them is a breaking change.
|
|
|
|
```yaml
|
|
- name: Upgrade packages
|
|
ansible.builtin.import_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: update
|
|
|
|
- name: Check whether a reboot is required
|
|
ansible.builtin.import_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: reboot
|
|
vars:
|
|
system_baseline_reboot_if_required: false
|
|
|
|
- name: Reboot after draining
|
|
ansible.builtin.reboot:
|
|
when: system_baseline_reboot_required | default(false)
|
|
```
|
|
|
|
`validate.yml` has no spec and is not an entry point; the molecule scenario calls it to load the defaults.
|
|
|
|
### `update`
|
|
|
|
`tasks_from: update`: apt update, upgrade, autoremove and autoclean, nothing else. It does not read `system_baseline_update`: calling the entry point is the request to update. In check mode it previews the upgrade; the main flow does not (see "Check mode"). It reads `system_baseline_apt_tmpdir` (see "Apt scratch directory").
|
|
|
|
### `reboot`
|
|
|
|
`tasks_from: reboot`: sets the fact `system_baseline_reboot_required` (see [Variables set by the role](#variables-set-by-the-role)) on Debian family hosts, then reboots when `system_baseline_reboot_if_required` is true and the fact is true. With `system_baseline_reboot_if_required: false` it only computes the fact. It reads `system_baseline_reboot_throttle` and `system_baseline_reboot_post_delay` as the main flow does, and refuses a bad value before anything runs.
|
|
|
|
## Variables set by the role
|
|
|
|
| Name | Type | Set by | Description |
|
|
| --- | --- | --- | --- |
|
|
| `system_baseline_reboot_required` | bool | `tasks_from: reboot` | True when `/var/run/reboot-required` exists. Set on Debian family hosts only; on other families the fact is not set, so read it with `default(false)`. |
|
|
|
|
## Tags
|
|
|
|
`always` (validation), `update` (apt upgrade and the reboot), `packages`, `unattended-upgrades`, `locale`, `timezone`, `journald`, `apt-daily-timeout`, `sysctl`, `secure_tmp`, `tmux`.
|
|
|
|
## Example play
|
|
|
|
```yaml
|
|
- name: Baseline LXC guests
|
|
hosts: lxc_guests
|
|
gather_facts: true
|
|
vars:
|
|
system_baseline_system_type: ubuntu_lxc
|
|
roles:
|
|
- role: mortis.kamino.system_baseline
|
|
```
|
|
|
|
## Tests
|
|
|
|
The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It installs packages from the Ubuntu mirrors, so the runner needs outbound network. It runs `check` before the converge (a fresh host) and after it (a configured host).
|
|
|
|
- Verify first checks, on the controller, that the role refuses a bad input with its own message before any change: an unknown `system_baseline_system_type`, an unknown `system_baseline_apt_upgrade` (main flow and `update` entry point), a negative reboot throttle or a negative or boolean post-reboot delay (main flow and `reboot` entry point), a line break in `system_baseline_apt_daily_timeout`, a bad `system_baseline_journal_max_use` (`infinity`, a lower-case unit, a unit with a trailing `B`, a line break, a number), and a bad package blacklist (a quote, a null item, a bare string).
|
|
- Converge applies the `ubuntu_lxc` profile, with tmux autostart and `system_baseline_apt_daily_timeout: 1h`. Verify only resolves the `pve` and `ubuntu_vm` profiles and a consumer override, on the controller, asserting the resolved inputs.
|
|
- 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, 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.
|
|
|
|
Not covered: Molecule skips `sysctl`, `secure_tmp`, `update` and `timezone` (no privileged container); see `molecule/default/molecule.yml`. So `system_baseline_update` is checked only for its default; the skip itself is not exercised by a test. No host reboots, and the `pve` profile is not converged: Debian 13 is not verified by a test.
|
|
|
|
## Notes
|
|
|
|
- Idempotent: yes.
|
|
- The `pve` profile has no `ufw`; the `ubuntu_*` profiles install it and `fail2ban`.
|
|
- No profile lets unattended-upgrades reboot on its own (`Automatic-Reboot: false`); a host opts in through `system_baseline_profile_overrides`.
|
|
- Set `system_baseline_reboot_if_required: false` for hosts whose reboot takes other machines down (hypervisors) or needs a drain first (cluster nodes).
|
|
- Policy lives in defaults, not `vars/`, so group_vars and host_vars can override it.
|
|
- `no_log` is not used: the role handles no secrets.
|
|
|
|
### Adding packages to a profile
|
|
|
|
`system_baseline_essential_packages` and `system_baseline_remove_packages` replace the profile's whole list, and so does a list inside `system_baseline_profile_overrides`. To add or drop a few packages and keep the profile's own, use the two extra lists, which append:
|
|
|
|
```yaml
|
|
system_baseline_extra_packages: [jq]
|
|
system_baseline_extra_remove_packages: [telnet]
|
|
```
|
|
|
|
- Each item is a Debian package name: lower-case letters, digits, `+`, `-` and `.`, two or more characters, starting with a letter or digit and not ending in `-` (apt reads a trailing minus as a removal). Anything else stops the run. Duplicates of the profile list are harmless.
|
|
- The role does not refresh an APT cache younger than an hour, so a package from a source you add just before the role (`ansible.builtin.deb822_repository` does not refresh) needs your own cache refresh first.
|
|
- An extra counts wherever the role looks for a package in the list: an extra `tmux` enables the tmux snippet and an extra `unattended-upgrades` the unattended-upgrades tasks, as a profile package does.
|
|
- A package that one input installs and another purges stops the run before any change: `system_baseline_extra_packages` against `system_baseline_remove_packages` or `system_baseline_extra_remove_packages`, and `system_baseline_extra_remove_packages` against `system_baseline_essential_packages`. The resolved lists are not checked against each other, so a consumer's own overlap there behaves as before.
|
|
|
|
### tmux on SSH login
|
|
|
|
With `system_baseline_tmux_autostart: true` an interactive SSH login attaches to the session `system_baseline_tmux_session` (created when missing), so a dropped connection loses nothing. The `ubuntu_lxc` and `ubuntu_vm` profiles install `tmux`; the `pve` profile has none, so it gets the snippet only if `system_baseline_extra_packages` adds `tmux`.
|
|
|
|
```yaml
|
|
system_baseline_tmux_autostart: true
|
|
system_baseline_tmux_session: ops
|
|
system_baseline_tmux_windows:
|
|
- { name: logs, command: "journalctl -f" }
|
|
```
|
|
|
|
- It is `/etc/profile.d/tmux-autostart.sh`. Every login shell reads that directory, so the snippet itself acts only for an interactive shell (`case $-`) with a terminal and an SSH connection, outside tmux, and without `~/.no-tmux`. `scp`, `sftp`, `ssh host command`, Ansible and `ssh -t host 'bash -lc cmd'` never trigger it. sshd's `ForceCommand` is not used: it applies to every session type and a broken tmux would lock all of them out. Users whose login shell is zsh or fish are not affected, because those shells do not read `/etc/profile.d`.
|
|
- The snippet is installed when autostart is on and the packages to install contain `tmux`: the `ubuntu_lxc` and `ubuntu_vm` profiles have it, and `system_baseline_extra_packages` can add it. If you override `system_baseline_essential_packages` without it and add no extra `tmux`, nothing is installed.
|
|
- A failed attach (for example a client `TERM` such as `xterm-kitty` or `wezterm` without a terminfo entry on the host) prints a line and leaves a plain shell. Detaching (`Ctrl-b d`) ends the SSH connection, as `exit` would.
|
|
- Turn it off for one login with `ssh -t host bash` (a non-login shell does not read `/etc/profile.d`), for one user with `touch ~/.no-tmux`, and for the host by setting the variable to `false` and running the role (it removes the snippet).
|
|
- The windows are made when the session is created; a login that re-attaches adds none, so a change applies from the next new session. A window closes when its command exits. A window command runs with `sh -c` from the tmux server of the first login, before `~/.profile` is read, so it does not see `~/.local/bin` and other additions made there: use absolute paths.
|
|
- Security: the name and commands are validated (`A-Za-z0-9_-`, one line) and shell-quoted, and come from the inventory, never from a user. The file is root-owned and not writable by its users. The commands run as the user who logs in, are readable by every user and show in `ps`: no secrets in a command. A session outlives the SSH connection, so a root session stays open until it is closed.
|
|
|
|
### Rebooting one host at a time
|
|
|
|
`system_baseline_reboot_throttle` is the `throttle` of the reboot task: how many hosts of the play reboot at once. The default `0` is no limit, which is what the role did before. `1` makes the hosts reboot one after the other, for a group whose members must not be down together (a cluster, a replicated pair). `system_baseline_reboot_post_delay` is the `post_reboot_delay` of the same task: the seconds to wait after a host answers again, so a service on it can settle before the next host goes down. Both are whole numbers, 0 or more; anything else stops the run before a host reboots, in the main flow and in `tasks_from: reboot`.
|
|
|
|
```yaml
|
|
system_baseline_reboot_throttle: 1
|
|
system_baseline_reboot_post_delay: 45
|
|
```
|
|
|
|
The throttle applies to the reboot task only, and to hosts that need a reboot: it does not serialise the rest of the role. A play-level `serial` still works as before.
|
|
|
|
### Bounding a hung apt-daily.service
|
|
|
|
With `system_baseline_apt_daily_timeout: 1h` the role writes `/etc/systemd/system/apt-daily.service.d/10-timeout.conf` (`[Service]`, `TimeoutStartSec=1h`) and runs `systemctl daemon-reload` when it changed. A hung `apt-daily.service` (a stuck mirror, a lock that never frees) is then stopped after that time instead of blocking every later apt run. Only `apt-daily.service` is changed, not `apt-daily-upgrade.service`.
|
|
|
|
- Empty (the default) leaves the host alone. Clearing the value later does not remove a file already written; delete it by hand and reload systemd.
|
|
- The value must be empty or a one-line systemd time span starting with a digit, or `infinity`. A value systemd cannot parse is ignored by systemd with a log line, so check `systemctl show -p TimeoutStartUSec apt-daily.service`.
|
|
- `0` is accepted but means no timeout to systemd (the same as `infinity`), the opposite of a bound; set a real time span.
|
|
- Run only this step with `--tags apt-daily-timeout`.
|
|
|
|
### Skipping the package update
|
|
|
|
`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.
|
|
|
|
### Skipping the upgrade during a backup
|
|
|
|
An upgrade of a Proxmox node can restart Proxmox services while a backup holds a snapshot of a guest. With `system_baseline_skip_upgrade_during_vzdump: true` and `system_baseline_system_type: pve`, the role runs `pvesh get /nodes/localhost/tasks --source active --limit 0` before the upgrade (`--source active` lists the running tasks; the default, `archive`, holds only finished ones). When one of the listed tasks has the type `vzdump` and no `endtime`, the upgrade is skipped and a message says why; autoremove, autoclean and the reboot check still run, and the role does not wait for the backup, so run it again afterwards.
|
|
|
|
- Off by default. With `false`, or on any other system type, no `pvesh` command runs.
|
|
- The `update` entry point reads the input as well. In check mode the main flow skips the upgrade itself, so it does not ask for the tasks; the entry point previews the upgrade and so asks.
|
|
- `localhost` is the node's own alias in the Proxmox API, so the role needs neither a node name nor gathered facts.
|
|
- A `pvesh` answer that is not a JSON list stops the run, instead of upgrading on a guess.
|
|
|
|
### Leaving journald alone
|
|
|
|
`system_baseline_journal_max_use: ""` skips the journald task: no drop-in directory, no `50-system-baseline.conf` and no restart of `systemd-journald`. Use it where another drop-in, role or policy owns the journal size. A file an earlier run wrote stays, as for an empty `system_baseline_apt_daily_timeout`; remove it by hand if the cap should go. A value that is not empty and not a size journald reads (`infinity`, `10m`, one with a line break) stops the run before any change, in the same way as the apt-daily value.
|
|
|
|
### Apt scratch directory
|
|
|
|
The upgrade runs over the SSH connection Ansible uses. An `openssh-server` upgrade restarts `ssh.service`, and a unit with `PrivateTmp=yes` (the `systemd_hardening` role sets it) has its own `/tmp` and `/var/tmp`, which systemd deletes when the unit stops. The files apt staged there for the running upgrade then disappear and dpkg fails, leaving packages unpacked but not configured. So the `update` flow creates `system_baseline_apt_tmpdir` (root, mode `0700`), runs the upgrade and the autoremove with `TMPDIR` set to it, and opens a new connection afterwards, so that later tasks get a fresh private `/tmp`.
|
|
|
|
- The value must be an absolute path of letters, digits, `.`, `_`, `-` and `/`, without `..`, and not `/tmp`, `/var/tmp` or a path below them; anything else stops the run before a change.
|
|
- The directory is also created in check mode (the autoremove runs there with the same `TMPDIR`), so a dry run reports it once, on a host that does not have it yet.
|
|
- Changing the value does not remove the old directory.
|
|
|
|
### 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.
|
|
|
|
`--check` is the supported preview; a play-level `check_mode: true` is not supported.
|
|
|
|
### Unattended-upgrades origins
|
|
|
|
A profile's `unattended_upgrade_origins` list pins the origins unattended-upgrades may install from. apt merges every file in `/etc/apt/apt.conf.d` and appends list entries across files, so a later file that only lists origins would widen the distribution's `50unattended-upgrades`, never narrow it. A non-empty list is therefore written to `/etc/apt/apt.conf.d/90unattended-upgrades-origins`, which sorts after `50unattended-upgrades`, clears `Unattended-Upgrade::Allowed-Origins` and `Unattended-Upgrade::Origins-Pattern` (apt's `#clear` directive) and sets only the listed patterns. The origin lists in `50unattended-upgrades` itself are not edited. An empty or missing list removes the drop-in.
|
|
|
|
- `pve` pins Debian's own default set: `origin=Debian,codename=${distro_codename},label=Debian` (point releases) and the two `Debian-Security` patterns. The Proxmox repository is never allowed, and a future Debian default cannot widen the set.
|
|
- `ubuntu_lxc` and `ubuntu_vm` pin nothing (`[]`): Ubuntu's default origins apply.
|
|
- `${distro_codename}` is expanded by unattended-upgrades, not by Ansible. An entry may not hold a double quote, a backslash or a line break.
|
|
- A file in `/etc/apt/apt.conf.d` that sorts after `90unattended-upgrades-origins` can still add origins, and so can `/etc/apt/apt.conf`, which apt reads after `apt.conf.d`.
|
|
- Check the merged result on a host with `apt-config dump | grep -E 'Unattended-Upgrade::(Origins-Pattern|Allowed-Origins)'`.
|
|
|
|
### Unattended-upgrades package blacklist
|
|
|
|
`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 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:
|
|
- "^pve-.*" # pve-manager, pve-kernel-*, pve-qemu-kvm, pve-container ...
|
|
- "^libpve-.*"
|
|
- "^proxmox-.*" # proxmox-ve, proxmox-kernel-*, proxmox-backup-client ...
|
|
- "^qemu-server$"
|
|
- "^ceph.*"
|
|
- "^corosync$"
|
|
```
|
|
|
|
- Like the other unattended-upgrades settings, it is applied only when `unattended-upgrades` is in the profile's packages.
|
|
- This is unattended-upgrades only. The role's own apt upgrade (`update` tag, and the `update` entry point) is not limited by it; set `system_baseline_update: false` for a host that is patched by a separate flow.
|
|
- Check the merged result on a host with `apt-config dump | grep Package-Blacklist`.
|