Skip to content

Stop cloud-init's apt-configure crashing on the indexers - #49

Merged
TakGN merged 1 commit into
mainfrom
claude/cloudinit-apt-mirrorlists-4e713e
Nov 25, 2026
Merged

TakGN merged 1 commit into
mainfrom
claude/cloudinit-apt-mirrorlists-4e713e

Conversation

@TakGN

@TakGN TakGN commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

indexers-amst1 shows failed cloud-config.service and cloud-init-main.service: cloud-init's apt-configure crashes with KeyError: 'security' in find_apt_mirror_info. This adds /etc/cloud/cloud.cfg.d/99-ipni-apt.cfg on the indexers only (hardening_fix_cloud_init_apt, off by default, on in group_vars/indexers), where the cloud config directory exists.

Why not just generate_mirrorlists: false

Read in Debian 13's source (25.1.4-1+deb13u1, with its mirrorlist patch), cc_apt_configure.apply_apt:

  1. calls find_apt_mirror_info first. With no apt.primary configured, update_mirror_info takes the datasource's mirror dict and reads ["security"]: the crash.
  2. only then checks generate_mirrorlists; if false, and preserve_sources_list is not true, it rewrites the apt sources.

So generate_mirrorlists: false alone would not avoid the crash. The file therefore sets:

Key Effect
primary, security update_mirror_info returns these and never reads the datasource's dict
generate_mirrorlists: false no /etc/apt/mirrors/*.list
preserve_sources_list: true no sources rewrite, mirror keys or list renames

The URIs are Debian's own. With the two flags above they go unused; if higher-priority config (user-data, vendor-data) turned rewriting back on, the result would still be valid sources. 99- overrides the image's 01_debian_cloud.cfg.

Still true of apply_apt_config: with no apt proxy or conf configured, it removes cloud-init's own proxy/conf files if present. This change does not alter that.

What this does not do

  • It does not clear the failed units. A reboot should: status is per boot. systemctl reset-failed cloud-config.service cloud-init-main.service only clears systemd's state. Neither was run.
  • A reboot does not rerun apt-configure on the same instance: it runs once per instance and a failed run keeps its semaphore. So the file matters when it runs again (new instance ID, or cloud-init clean), and a clean reboot alone does not prove the fix.
  • It cannot help the first boot of a fresh install, which happens before site.yml writes the file. A reinstall that wipes the disk will hit the crash again.

Tested

  • --syntax-check on all seven playbooks, yamllint ., ansible-lint (production profile, 0 failures).
  • The flag resolves to true for both indexers and is not set in inventory for the IPFS or infra boxes (the role default is false).

Not tested

  • Nothing was run on any box: no dry run from a controller, no site.yml, no cloud-init.
  • The cloud-init behaviour above comes from reading the source, not executing it.
  • Why the mirror dict lacks security on Cherry's image (MAAS datasource or its config) is still an inference. The fix does not depend on it.
  • indexers-chic1 also gets the file; its cloud-init is currently clean.

site.yml applies from CI after approval. Suggested check afterwards, on indexers-amst1: sudo cloud-init single --name apt_configure --frequency always, then confirm the apt sources are unchanged.

🤖 Generated with Claude Code

With no apt mirrors configured, apt-configure reads them from the
datasource and fails with KeyError: 'security'. Name the mirrors, and keep
it from writing apt sources or mirror lists.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 25, 2026

Copy link
Copy Markdown

Claude review

This is a small, well-scoped change. It adds a cloud-init drop-in (99-ipni-apt.cfg) behind a flag that is off by default and on only for the indexers group. I read the diff and the surrounding hardening tasks. The existing stat task still runs only when one of the flags is set. The new task checks hardening_fix_cloud_init_apt | bool and (cloud_cfg_d.stat.isdir | default(false)), which short-circuits when the stat was skipped, so the IPFS boxes and infra_boxes are untouched. The or in the stat when: parses as intended, because the filter binds tighter than the operator. The drop-in keys match the mechanism described in the PR: naming primary and security avoids the datasource lookup that raises KeyError, and the other two flags keep cloud-init from rewriting sources. I could not execute cloud-init or see Debian's patched source, so that mechanism rests on the PR's source reading. The PR is upfront that nothing was run on a box.

No issues found.

claude-sonnet-5-5 at high effort · requested by TakGN · re-run with @claude review [sonnet|opus|fable] [low|medium|high|xhigh|max]

@TakGN
TakGN merged commit 2517cb7 into main Nov 25, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant