feat(system_baseline): add inputs that append packages to the profile's lists
Build / build (pull_request) Successful in 1m15s
Lint / lint (pull_request) Successful in 5m37s
Molecule / molecule (pull_request) Successful in 7m20s

system_baseline_essential_packages and system_baseline_remove_packages
replace the whole list, and so does a list inside
system_baseline_profile_overrides, so adding one package meant repeating
the profile's list and keeping it in step with every release.

system_baseline_extra_packages and system_baseline_extra_remove_packages
(lists, default empty) append to the resolved lists. The tmux and
unattended-upgrades checks read the combined list, so an extra tmux or
unattended-upgrades enables the matching task like a profile package.
Items must be Debian package names: a null item would have become the
package "None", and apt reads a trailing minus (jq-) as a removal. A
package that one input installs and another purges stops the run before
any change; only overlaps that involve an extra are checked, so a
consumer's own overlap between the resolved lists behaves as before. A
flat input that is a plain string still counts as a one-item list.

With both inputs left at their default the role behaves as before.

Closes #399

Assisted-by: Claude Code:claude-sonnet-5-5
This commit is contained in:
Dragonish committed 2026-11-26 22:25:36 +00:00
1 parent aa4e8c68a7
commit d5a91520df
12 files changed
+269 -14

No files matched your search

+18 -2
View File
@@ -35,6 +35,8 @@ templating error instead of the role's own message.
| `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_unattended_upgrade_settings` | from profile | no | Keys for `50unattended-upgrades` |
@@ -130,6 +132,7 @@ The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_
- Converge then applies the `ubuntu_lxc` profile, with tmux autostart and `system_baseline_apt_daily_timeout: 1h`, and only resolves the `pve` and `ubuntu_vm` profiles and a consumer override, 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.
- Converge 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, then 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.
- Converge 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. Verify 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 `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.
@@ -145,9 +148,22 @@ Not covered: Molecule skips `sysctl`, `secure_tmp`, `update` and `timezone` (no
- 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.
- 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`; `pve` never gets the snippet.
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
@@ -157,7 +173,7 @@ system_baseline_tmux_windows:
```
- 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 resolved package list contains `tmux` (the `ubuntu_lxc` and `ubuntu_vm` profiles). If you override `system_baseline_essential_packages` without it, nothing is installed.
- 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.