feat: refresh the APT cache on distribution-only installs when stale #443

Merged
Defame1297 merged 2 commits from feat/apt-cache-valid-time into main 2026-11-27 18:44:00 +00:00
Owner

What and why

Closes #425

The docker prerequisites (ca-certificates, curl) and the system_baseline packages install only from the distribution's sources, yet refreshed the APT cache on every run. They now pass cache_valid_time: 3600, the value the system_baseline update task and user_management already use, so they refresh only a cache older than an hour.

Installs from a role's own APT source (docker's Engine packages, tailscale's package) still refresh on every run. If a run wrote the source line but its refresh failed or was interrupted, the next run within the hour would otherwise see a fresh cache, skip the refresh and find no package. So tailscale, which issue #425 listed, has no change here: its only install follows its own source. The docker and tailscale update entry points are unchanged.

The apt module (ansible-core 2.19) takes the cache age from /var/lib/apt/periodic/update-success-stamp, else from the mtime of /var/lib/apt/lists.

Known risk: a source a consumer adds just before system_baseline (for example with ansible.builtin.deb822_repository, which does not refresh) is not fetched if the cache is younger than an hour; the system_baseline README now says to refresh the cache first. Likewise, on a host built from an image less than an hour before the run, an empty lists directory looks fresh. The docker and system_baseline Molecule scenarios refresh the cache in prepare.yml.

Verified

  • The commit hooks (pre-commit on the changed files): gitleaks, yamllint, ruff format, merge-conflict check, REUSE, antsibull-changelog-lint, ansible-lint, Conventional Commit and the Assisted-by trailer check all pass; ansible-test sanity (pre-push) passed.
  • ansible-playbook --syntax-check of roles/docker/molecule/default/converge.yml and roles/system_baseline/molecule/default/converge.yml.
  • The cache-age logic was read in the installed ansible-core 2.19.6 apt module (get_cache_mtime, lines 1172-1177; refresh check, lines 1399-1402).
  • Reviewed by a separate agent; its finding (an "only when the source changed" refresh would not heal a failed earlier run) is fixed by always refreshing after the role's own source.

Not verified

  • Molecule (runs in CI).
  • Behaviour on a real host with a cache older or newer than an hour.

  • I confirm third-party material is recorded in NOTICE and REUSE.toml, or there is none.

Assisted-by: Claude Code

## What and why Closes #425 The docker prerequisites (`ca-certificates`, `curl`) and the system_baseline packages install only from the distribution's sources, yet refreshed the APT cache on every run. They now pass `cache_valid_time: 3600`, the value the system_baseline update task and user_management already use, so they refresh only a cache older than an hour. Installs from a role's own APT source (docker's Engine packages, tailscale's package) still refresh on every run. If a run wrote the source line but its refresh failed or was interrupted, the next run within the hour would otherwise see a fresh cache, skip the refresh and find no package. So tailscale, which issue #425 listed, has no change here: its only install follows its own source. The docker and tailscale update entry points are unchanged. The apt module (ansible-core 2.19) takes the cache age from `/var/lib/apt/periodic/update-success-stamp`, else from the mtime of `/var/lib/apt/lists`. Known risk: a source a consumer adds just before system_baseline (for example with `ansible.builtin.deb822_repository`, which does not refresh) is not fetched if the cache is younger than an hour; the system_baseline README now says to refresh the cache first. Likewise, on a host built from an image less than an hour before the run, an empty lists directory looks fresh. The docker and system_baseline Molecule scenarios refresh the cache in `prepare.yml`. ## Verified - The commit hooks (`pre-commit` on the changed files): gitleaks, yamllint, ruff format, merge-conflict check, REUSE, antsibull-changelog-lint, ansible-lint, Conventional Commit and the Assisted-by trailer check all pass; `ansible-test sanity` (pre-push) passed. - `ansible-playbook --syntax-check` of `roles/docker/molecule/default/converge.yml` and `roles/system_baseline/molecule/default/converge.yml`. - The cache-age logic was read in the installed ansible-core 2.19.6 apt module (`get_cache_mtime`, lines 1172-1177; refresh check, lines 1399-1402). - Reviewed by a separate agent; its finding (an "only when the source changed" refresh would not heal a failed earlier run) is fixed by always refreshing after the role's own source. ## Not verified - Molecule (runs in CI). - Behaviour on a real host with a cache older or newer than an hour. --- - [x] I confirm third-party material is recorded in `NOTICE` and `REUSE.toml`, or there is none. Assisted-by: Claude Code
Claude added 1 commit 2026-11-27 15:33:09 +00:00
feat: refresh the APT cache on distribution-only installs when stale
Build / build (pull_request) Successful in 29s
Lint / lint (pull_request) Successful in 2m18s
Molecule / molecule (pull_request) Canceled after 26m49s
0973f39831
The docker prerequisites and the system_baseline packages install only
from the distribution's sources, yet refreshed the APT cache on every
run. They now pass cache_valid_time: 3600, as the system_baseline update
task and user_management already do.

The docker and tailscale installs from the role's own APT source keep
refreshing on every run, so a run that wrote the source line but failed
to fetch its lists heals on the next run. The update entry points are
unchanged.

The system_baseline README tells a consumer who adds a source just
before the role to refresh the cache themselves.

Assisted-by: Claude Code:claude-opus-5-5
Defame1297 added 1 commit 2026-11-27 18:31:11 +00:00
Merge branch 'main' into feat/apt-cache-valid-time
Build / build (pull_request) Successful in 31s
Lint / lint (pull_request) Successful in 4m10s
Molecule / molecule (pull_request) Successful in 11m57s
9ae5eca2a3
Defame1297 scheduled this pull request to auto merge when all checks succeed 2026-11-27 18:31:24 +00:00
Defame1297 approved these changes 2026-11-27 18:31:57 +00:00
Defame1297 merged commit 30352502dd into main 2026-11-27 18:44:00 +00:00
Defame1297 deleted branch feat/apt-cache-valid-time 2026-11-27 18:44:09 +00:00
Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#443