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

Open
Claude wants to merge 1 commits from feat/apt-cache-valid-time into main
pull from: feat/apt-cache-valid-time
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
Some required checks failed
Build / build (pull_request) Successful in 29s
Required
Details
Lint / lint (pull_request) Successful in 2m18s
Required
Details
Molecule / molecule (pull_request) Canceled after 26m49s
Required
Details
Some required checks were not successful.
This pull request is blocked because it's outdated.
You are not authorized to merge this pull request.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/apt-cache-valid-time:feat/apt-cache-valid-time
git checkout feat/apt-cache-valid-time
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Kamino#443