- galaxy.yml declares community.general and ansible.posix: system_baseline is the first role that calls modules outside ansible.builtin, and a consumer that installs only this Collection failed to parse the play. - The README override example set Automatic-Reboot to false, which every profile already defaults to; it now shows the opt-in. - Comment and description wording. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
103 lines
6.2 KiB
Markdown
103 lines
6.2 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 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, covered by the molecule scenario), Ubuntu 22.04 (jammy) and Debian 13 (trixie, Proxmox hosts). The tasks use apt and the reboot check is limited to the Debian family. See `meta/main.yml`. The molecule scenario (`molecule/default/`, CI only) converges the `ubuntu_lxc` profile on Ubuntu 24.04 and only resolves the `pve` and `ubuntu_vm` profiles; Ubuntu 22.04 and Debian 13 are not verified by a test.
|
|
|
|
## Requirements and run order
|
|
|
|
- Facts must be gathered (`gather_facts: true`); `reboot.yml` reads `ansible_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.
|
|
- The role has no declared dependencies.
|
|
|
|
## Role variables
|
|
|
|
The resolved `system_baseline_*` inputs derived from the active profile (`_profile`, `_essential_packages`, `_remove_packages`, `_apt_periodic_settings`,
|
|
`_unattended_upgrade_settings`, `_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_apt_periodic_settings` | from profile | no | Keys for `20auto-upgrades` |
|
|
| `system_baseline_unattended_upgrade_settings` | from profile | no | Keys for `50unattended-upgrades` |
|
|
| `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`). |
|
|
| `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 |
|
|
|
|
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
|
|
|
|
Besides `main`, two task files 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.
|
|
|
|
- `tasks_from: update`: apt update, upgrade, autoremove and autoclean, nothing else.
|
|
- `tasks_from: reboot`: sets the fact `system_baseline_reboot_required` (bool, from `/var/run/reboot-required`) 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. On other families the fact is not set, so read it with `default(false)`.
|
|
|
|
```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.
|
|
|
|
## Tags
|
|
|
|
`always` (validation), `update` (apt upgrade and the reboot), `packages`, `unattended-upgrades`, `locale`, `timezone`, `journald`, `sysctl`, `secure_tmp`.
|
|
|
|
## 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
|
|
```
|
|
|
|
## Notes
|
|
|
|
- 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).
|
|
- Molecule skips `sysctl`, `secure_tmp`, `update` and `timezone` (no privileged container); see `molecule/default/molecule.yml`.
|
|
- 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.
|