From 55bd5d52311b2213de3ed9cb7ca55a724565c942 Mon Sep 17 00:00:00 2001 From: Dragonish Date: Mon, 23 Nov 2026 17:44:37 +0000 Subject: [PATCH 01/12] fix(system_baseline): do not report a pending package upgrade as drift in check mode The main flow skips the apt upgrade in check mode; autoremove and autoclean are a task of their own and stay checked. The update entry point is unchanged and still previews the upgrade. Assisted-by: Claude Code --- .../system-baseline-check-mode-upgrade.yml | 8 ++++++++ roles/system_baseline/README.md | 6 +++++- roles/system_baseline/meta/argument_specs.yml | 5 ++++- roles/system_baseline/tasks/main.yml | 2 ++ roles/system_baseline/tasks/update.yml | 14 ++++++++++++-- 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/system-baseline-check-mode-upgrade.yml diff --git a/changelogs/fragments/system-baseline-check-mode-upgrade.yml b/changelogs/fragments/system-baseline-check-mode-upgrade.yml new file mode 100644 index 0000000..eef501e --- /dev/null +++ b/changelogs/fragments/system-baseline-check-mode-upgrade.yml @@ -0,0 +1,8 @@ +--- +bugfixes: + - >- + system_baseline - Do not run the apt upgrade in check mode in the main flow. A package that is only waiting for the next patch run, or a + package cache older than an hour, is not drift, but the package module reports both as changed, so a scheduled dry run flagged every + host. Autoremove and autoclean are now a task of their own and stay checked; as part of the upgrade call the module did not reach + autoclean, so ``apt-get autoclean`` now runs (and may report changed once on a host with stale archives), in the main flow and in the + ``update`` entry point. The ``update`` entry point still previews the upgrade in check mode. diff --git a/roles/system_baseline/README.md b/roles/system_baseline/README.md index 6549f73..d050a30 100644 --- a/roles/system_baseline/README.md +++ b/roles/system_baseline/README.md @@ -58,7 +58,7 @@ system_baseline_profile_overrides: 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. It does not read `system_baseline_update`: calling the entry point is the request to 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"). - `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 @@ -119,6 +119,10 @@ 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. +## 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. + ## 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. diff --git a/roles/system_baseline/meta/argument_specs.yml b/roles/system_baseline/meta/argument_specs.yml index afd2112..1b4d00a 100644 --- a/roles/system_baseline/meta/argument_specs.yml +++ b/roles/system_baseline/meta/argument_specs.yml @@ -111,11 +111,14 @@ argument_specs: separate flow; the reboot check still runs, so set C(system_baseline_reboot_if_required) as well when that flow also owns the reboot. - The C(update) entry point does not read it. + - In check mode the main flow skips the upgrade itself (a pending update is not drift); autoremove and autoclean are still checked. update: short_description: Update and upgrade apt packages description: - Runs an apt update, upgrade, autoremove and autoclean, and nothing else. - - Calling it is a request to update, so it does not read C(system_baseline_update), which only gates the main flow. + - >- + Calling it is a request to update, so it does not read C(system_baseline_update), which only gates the main flow. In check mode it + still previews the upgrade. - >- A supported entry point (C(tasks_from=update)) for a caller that drives its own reboot, for example a Kubernetes node patch flow that drains the node first. diff --git a/roles/system_baseline/tasks/main.yml b/roles/system_baseline/tasks/main.yml index 3be8052..c5006f0 100644 --- a/roles/system_baseline/tasks/main.yml +++ b/roles/system_baseline/tasks/main.yml @@ -6,6 +6,8 @@ # Only the main flow honours system_baseline_update: the tasks_from: update entry point is an explicit request to update. - name: Update & Upgrade Dist ansible.builtin.import_tasks: update.yml + vars: + __system_baseline_main_flow: true when: system_baseline_update | bool tags: update diff --git a/roles/system_baseline/tasks/update.yml b/roles/system_baseline/tasks/update.yml index b8f271b..5194c83 100644 --- a/roles/system_baseline/tasks/update.yml +++ b/roles/system_baseline/tasks/update.yml @@ -1,9 +1,19 @@ --- +# 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: Update & upgrade apt packages ansible.builtin.package: update_cache: true upgrade: true - autoremove: true - autoclean: true cache_valid_time: 3600 become: true + when: not (ansible_check_mode and __system_baseline_main_flow | 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 + become: true From f50ecc29453cd5724b7c83c61791367d7cfa7dcc Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Mon, 23 Nov 2026 18:04:50 +0000 Subject: [PATCH 02/12] feat(gitea_runner): bound the Docker image cache by count and disk usage An age-based prune does not cap disk use: the cache grows with how often new image versions are published, and builds on the runner then fail for lack of space. Keep the newest N image IDs per repository in the weekly prune, and add an hourly pressure prune that runs the count prune and a capped builder prune when the Docker root's filesystem passes a threshold, behind the same job gate. Both are off by default. Refs #319 Assisted-by: Claude Code --- ...ea-runner-docker-prune-count-threshold.yml | 9 + roles/gitea_runner/README.md | 9 +- roles/gitea_runner/defaults/main.yml | 6 + .../files/gitea-runner-docker-prune-keep | 58 ++++ .../files/gitea-runner-docker-prune-pressure | 18 ++ roles/gitea_runner/meta/argument_specs.yml | 32 +++ .../molecule/default/molecule.yml | 2 + .../molecule/default/tasks/refused_input.yml | 3 + .../gitea_runner/molecule/default/verify.yml | 251 +++++++++++++++++- roles/gitea_runner/tasks/prune.yml | 125 ++++++++- roles/gitea_runner/tasks/remove.yml | 21 +- roles/gitea_runner/tasks/validate.yml | 27 ++ 12 files changed, 552 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/gitea-runner-docker-prune-count-threshold.yml create mode 100755 roles/gitea_runner/files/gitea-runner-docker-prune-keep create mode 100755 roles/gitea_runner/files/gitea-runner-docker-prune-pressure diff --git a/changelogs/fragments/gitea-runner-docker-prune-count-threshold.yml b/changelogs/fragments/gitea-runner-docker-prune-count-threshold.yml new file mode 100644 index 0000000..002088b --- /dev/null +++ b/changelogs/fragments/gitea-runner-docker-prune-count-threshold.yml @@ -0,0 +1,9 @@ +--- +minor_changes: + - >- + gitea_runner - The Docker prune can bound the image cache by count and by disk use. With + ``gitea_runner_docker_prune_keep_per_repository`` above 0 the weekly prune keeps the newest N image IDs of each + repository and removes every other image no container uses. With ``gitea_runner_docker_prune_disk_threshold_percent`` + set, a timer (``gitea_runner_docker_prune_disk_check_schedule``, hourly by default) runs the count prune and a builder + prune capped at ``gitea_runner_docker_prune_builder_keep_storage`` when the filesystem holding the Docker root is at + least that full, behind the same job gate as the weekly prune. Both are off by default. diff --git a/roles/gitea_runner/README.md b/roles/gitea_runner/README.md index 6f7b766..d28e2a9 100644 --- a/roles/gitea_runner/README.md +++ b/roles/gitea_runner/README.md @@ -53,6 +53,10 @@ Ubuntu 24.04 (noble), the image the molecule scenario runs on. The role uses `an | `gitea_runner_docker_prune_schedule` | `Sun *-*-* 04:30:00` | `OnCalendar` of the prune timer. | | `gitea_runner_docker_prune_container_age`, `_image_age` | `24h`, `168h` | `until` filters (creation time) for containers, and for images and build cache. | | `gitea_runner_docker_prune_job_max_age` | `21600` | Seconds; the prune skips while a younger container runs and ignores older ones as leaked job containers. | +| `gitea_runner_docker_prune_keep_per_repository` | `0` (off) | Newest image IDs kept per repository by the weekly and pressure prunes; every other image no container uses is removed. A multi-tag image counts once. | +| `gitea_runner_docker_prune_disk_threshold_percent` | `0` (off) | Use % of the Docker root's filesystem at which the pressure prune runs the count prune and a capped builder prune, behind the job gate. 1 to 99; needs the count above 0. | +| `gitea_runner_docker_prune_disk_check_schedule` | `hourly` | `OnCalendar` of the pressure prune timer. | +| `gitea_runner_docker_prune_builder_keep_storage` | `10GB` | `--keep-storage` of the builder prune under pressure. | | `gitea_runner_molecule_enabled` | `false` | Install molecule tooling and add the host label. | | `gitea_runner_molecule_label` | `molecule` | Host-executor label name, registered as `