Skip to content

feat(infra): plan a playbook of an infra repo in check mode #5124

Closed

Description

@dan-petty

Problem or Motivation

A change to dan-petty/homelab reaches the hosts by make <target> ANSIBLE_ARGS="--limit <host>". Nobody sees before the run which tasks change on which host, or that a change restarts k3s. Example of 2026-11-12: dan-petty/homelab#19 (kubelet memory reservations) is merged and not applied. The owner ran make k3s ANSIBLE_ARGS="--limit hawk.lan --check --diff": ok=9 changed=2, the agent config template (no diff output, because it holds the join token) and the k3s-agent restart. Only a person reading the task names sees that the apply restarts k3s. Agents may apply plays (owner decision 2026-11-12), but only after a plan of the same commit.

Proposed Solution & Architectural Design

devops infra plan <repo> <playbook> [--limit] [--tags] [--ref] (design sections 5 and 6 in tracker #5120).

  1. Export the commit with git archive (default origin/<default branch>; --ref takes a branch or a PR head that origin holds) into the project folder of an ansible-runner private data folder under .data/infra/<owner>/<name>/plans/<id>/ (mode 0700). Never use the working tree.
  2. Run ansible-runner run <pd> -p <playbook> --cmdline "--check --diff --limit '<limit>:!offline'" through run_subprocess (isolate_env=True; ANSIBLE_CONFIG of the export; the key of devops ssh as the extra variable ansible_ssh_private_key_file). Install the pinned collections of collections/requirements.yml first, when the repo has one.
  3. Read artifacts/<ident>/job_events/*.json into Pydantic models. For each host: changed tasks (task_path, name), tasks that check mode skipped (unchecked), changes with the diff hidden (diff: false, no_log), and disruptive classes from the events: reboot (ansible.builtin.reboot), service-restart:<unit> (a changed systemd, systemd_service or service task with state restarted, reloaded or stopped, for any unit that the host variable devops_infra_nondisruptive_units does not list; the safe side is the default), drain (kubernetes.core.k8s_drain).
  4. Save plan.json: repo, commit, ref, playbook, limit, tags, ansible-core version, inventory hash, the per-host summary. The plan id is the SHA-256 of its canonical JSON without the time. Print a table and the id; --format json prints the model.
  5. Agent level plan or higher. --dry-run makes zero requests and prints the would-be commands.

Target Subsystem

OpenTofu / Infrastructure as Code

Existing Tool Considered

ansible-runner gives the run folder, the AWX event schema and the timeouts. A probe on 2026-11-12 (ansible-runner 2.4.3, ansible-core 2.21.4, Python 3.14.10) showed runner_on_ok with res.changed and res.diff, runner_on_skipped for command in check mode, and handlers that run in check mode. Building the same on the ansible.posix.jsonl callback costs about 1.5M tokens and 3 hours more. Cost of this item: about 3.5M tokens to build, 0.5M a quarter to keep, 5 hours.

Acceptance Criteria

  • Tests with recorded runner event files: a changed template with a diff, a changed template with the diff hidden, a skipped command, a notified restart handler, a reboot task, a failed task (the plan is marked failed).
  • A test: the same events give the same plan id; a different commit or limit gives another id.
  • A test: a host in offline is never in the limit.
  • A test: an agent caller on a repo at level none is refused before any process starts.
  • A test: --dry-run starts no process.
  • Live run on origin/main of dan-petty/homelab (dan-petty/homelab#19 merged, not applied), recorded in a PR comment: uv run devops infra plan dan-petty/homelab ansible/playbooks/03_k3s.yaml --limit hawk.lan shows the same 2 changes as the owner's check run: on hawk the agent config template changed with the diff hidden and service-restart:k3s-agent, and no change on other hosts. No host changes (check uptime and the k3s-agent start time on hawk before and after).

Dependencies

#5121

Activity

  1. added
    source/agent
    type/feature
    scope/infra
    status/new
    value/high
    effort/medium
    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 20:34 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/mediumpriority/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