Skip to content

feat(infra): apply a saved plan one node at a time #5125

Closed

Description

@dan-petty

Problem or Motivation

The owner decided on 2026-11-12 ("Agents apply all", then "agent use approval of the infra repos should be configurable, and I want homelab specifically to be full access to agents because it is dedicated to developing, troubleshooting, and validating project features and capabilities"). Today AGENTS.md says that only a person changes hosts, so agents hand the owner make commands, for example make k3s ANSIBLE_ARGS="--limit hawk.lan" for dan-petty/homelab#19, which restarts k3s on the host. Agents need one sanctioned path that applies a reviewed plan with guards, and the approval must be a setting of each infra repo, not one global rule.

Proposed Solution & Architectural Design

devops infra apply <repo> --plan <id> [--auto-approve] (design sections 4, 7 and 11 in tracker #5120).

  1. Access level (infra/access.py: require_access): none (an agent reaches no host), plan (status --ping, plan, drift), safe (also apply a plan with no disruptive class and no unchecked task; node uncordon), full (also any plan and the node commands, one node at a time). A person may do all. The caller is an agent when detect_agent or AI_AGENT names a tool, through MCP, or in a cluster Job.
  2. Guards at every level, for every caller: the plan record exists, its hash matches, it is younger than infra.plan_max_age_hours, and its playbook, limit and tags are the ones given; the commit is on origin (an agent: a default-branch commit, or at full the head of an open PR of the infra repo); an agent apply is refused when the effective config turns host key checks off; health before (every in-service node Ready, no memory, disk or PID pressure, no firing severity="critical" alert when prometheus.url is set); hosts with no disruptive class run together; each disruptive host runs alone in plan order: record its cordon state, kubectl drain (no --force by default), a fresh check of that host that must match the plan, the run with --limit <host>, wait for the unit and Ready, GPU allocatable equal to its value before, uncordon only when the node was schedulable before, health again; a changed task that the plan did not list stops the run; the first failure stops the run and leaves the node cordoned.
  3. Audit and telemetry: record_audit_event("infra.apply", ...) with caller kind and tool, level, repo, commit, plan id, hosts with result and disruptive classes, runner ident; instruments devops_cli_infra_runs_total{repo,command,result} in INSTRUMENTS.
  4. Secrets and hardware stay with the owner. devops passes only the devops ssh key. A person changes the level (AGENTS.md rule 12 and the refusal of feat(infra): onboard an Ansible infra repo #5121).
  5. Claude Code permission rule (owner step). The auto-mode classifier refused make k3s ANSIBLE_ARGS="--limit hawk.lan" from an agent on 2026-11-12, because no allow rule covered it. The project .claude/settings.json allows Bash(uv run devops *), and a matching allow rule resolves before the classifier. The owner step: keep that rule. A rule matches the whole command, so a compound shell line (an assignment, ;, &&, |) falls to the classifier: agents run uv run devops infra ... as one plain command. If auto mode drops the rule (the docs say that it drops package-manager run-command rules, and do not say whether uv run is one), the owner adds an autoMode.allow entry in ~/.claude/settings.json. The real control is the access level in the CLI. The docs of apply say all of this.
  6. Policy text, written as merged in this PR: the "Only a person" paragraph of AGENTS.md and a new ## Infra Repos section of SECURITY.md, in the exact words of design section 11 (the tracker quotes them). SECURITY.md item 3 lists ansible-runner.
  7. --dry-run makes zero requests and prints the would-be commands in order.

Target Subsystem

OpenTofu / Infrastructure as Code

Existing Tool Considered

ansible-runner runs the plays; kubectl drain, uncordon and wait do the node steps; the existing Prometheus client reads alerts; record_audit_event writes the record. Considered and not chosen: kured (reboots only, no plan), AWX and Semaphore (a second control plane and secret store). Cost: about 4.5M tokens to build, 0.6M a quarter to keep, 6 hours.

Acceptance Criteria

  • Tests with recorded events and a fake kubectl: refusal for each level and caller kind; refusal for a changed hash, an old plan, another limit, a commit that origin does not hold, host key checks off for an agent; one disruptive host at a time in plan order; a node that was cordoned before stays cordoned; a fresh check that differs stops the run before the run of that host; a health failure after a host stops the run and leaves it cordoned; an unplanned changed task stops the run.
  • A test: the audit record holds every field of the design and no secret.
  • A test: --dry-run starts no process.
  • AGENTS.md and SECURITY.md hold the text of design section 11.
  • Live run at level full by an agent, recorded in a PR comment with the audit records. dan-petty/homelab#19 (kubelet memory reservation, merged, not applied): plan and apply ansible/playbooks/03_k3s.yaml on hawk, then condor, gemini and hog, one host for each plan and apply. Each apply drains the host, restarts k3s, waits for Ready and shows allocatable memory below capacity. hawk stays cordoned, because it was cordoned before; the other 3 are uncordoned. While hog (the control plane) restarts, the API is down for a short time; the waits retry through the gap and the run ends green.
  • Live run: dan-petty/homelab#20 (crash capture, merged, not applied): plan and apply ansible/playbooks/13_crash_capture.yaml on hawk. The reboot that kdump needs is feat(infra): add node drain, uncordon, restart and reboot #5128.
  • The docs of apply name the owner step (keep Bash(uv run devops *) in the allow list), say that a compound shell line falls to the classifier, and say that the access level in the CLI is the real control. The live agent run shows that auto mode let uv run devops infra apply start; if it did not, the PR body gives the autoMode.allow fallback.

Dependencies

#5124; dan-petty/homelab#1 (host key checks on) for the agent run.

Activity

  1. added
    source/agent
    type/feature
    scope/infra
    status/new
    value/high
    effort/high
    on Nov 12, 2026
  2. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 12, 2026
  4. added
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 12, 2026
  5. removed
    status/in-review
    on Nov 12, 2026
  6. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-12 23:12 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p2-mediumscope/infrasource/agenttype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions