Skip to content

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

Merged
dan-petty merged 2 commits into
mainfrom
feat/5124-plan-a-playbook-of-an-infra
Nov 12, 2026
Merged

dan-petty merged 2 commits into
mainfrom
feat/5124-plan-a-playbook-of-an-infra

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

devops infra plan <repo> <playbook> runs a playbook of an infra repo in check mode and keeps the plan record that the apply of #5125 checks. It exports one commit of origin (default branch, or --ref a branch or pull/<n>/head) into a private ansible-runner folder under <data dir>/infra/<owner>/<name>/plans/, never the working tree. It installs the pinned collections once, and runs with --check --diff -v, <limit>:!<offline group>, the devops ssh key and host key checks on. The job events give for each host the changes, the hidden diffs, the unchecked tasks, the failures and the disruptive classes reboot, service-restart:<unit> and drain. The id is the SHA-256 of the facts. A failed plan exits 1. An agent needs the level plan; --dry-run starts no process.

Closes #5124

Change: openspec/changes/archive/2026-11-12-5124-plan-a-playbook-of-an-infra/

`devops infra plan <repo> <playbook> [--limit] [--tags] [--ref]` runs a
playbook of an infra repo in check mode with diffs and keeps the plan
record. The command exports one commit that origin holds (by default the
head of the default branch; --ref takes a branch of origin or
pull/<number>/head) into the project folder of a private ansible-runner
data folder under <data dir>/infra/<owner>/<name>/plans/. It never reads
the working tree.

The run installs the pinned collections of collections/requirements.yml
once for each version of the file, and runs ansible-runner with --check
--diff -v, the limit <limit>:!<offline group>, the key of devops ssh,
host key checks on and the rendered task arguments in each result. The
job events give, for each host, the changed tasks, the changes with the
diff hidden, the unchecked tasks and the disruptive classes reboot,
service-restart:<unit> and drain. The plan id is the SHA-256 of the
facts of the plan, without the time. A failed task marks the plan
failed, and the command exits 1. An agent needs the agent access level
plan. --dry-run starts no process.

The tests use recorded runner events of a probe repo in
tests/fixtures/infra/runner_events/.
Move the change folder to the archive and add the infra-plan spec.
@dan-petty dan-petty added type/feature Type feature: a new function scope/infra Docker container images, DevContainers, and infrastructure tooling labels Nov 12, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Live run on dan-petty/homelab (2026-11-12)

origin/main of dan-petty/homelab is at 19f0457. homelab #19 (kubelet memory reservations) is merged and not applied. hawk is cordoned. The agent access level of dan-petty/homelab is full, so the agent caller may plan.

The plan

$ uv run devops infra plan dan-petty/homelab ansible/playbooks/03_k3s.yaml --limit hawk.lan
Plan of dan-petty/homelab: ansible/playbooks/03_k3s.yaml on hawk.lan:!offline (check mode)
Reads origin/main at 19f04572eec78781f923792b4fea1d628eae9505, not the working tree of the checkout.
 Host      Changed  Disruptive                 Diff hidden  Unchecked  Result
 hawk.lan  2        service-restart:k3s-agent  1            0          ok
 Host      Kind                  Task                                                     Path
 hawk.lan  changed, diff hidden  Deploy K3s agent configuration file                      ansible/roles/k3s_agent/tasks/main.yaml:11
 hawk.lan  changed               Ensure K3s-agent systemd service is started and enabled  ansible/roles/k3s_agent/tasks/main.yaml:41
  Unchecked: check mode skipped the task, so the plan does not show what it does. Diff hidden: the task sets diff: false or no_log.
Plan da9629acaf9ed3bd72c53d4420bbeaa1263b028c18fede34f5d5104fb806df9b (ok), in <data dir>/infra/dan-petty/homelab/plans/da9629acaf9ed3bd72c53d4420bbeaa1263b028c18fede34f5d5104fb806df9b

The run recap in the runner artifacts: hawk.lan : ok=9 changed=2 unreachable=0 failed=0 skipped=1. This is the same as the owner's make k3s ANSIBLE_ARGS="--limit hawk.lan --check --diff" run: the agent config template changed with the diff hidden, and the k3s-agent restart. No other host is in the plan. The one skip is the k3s install script, whose when is false because the binary exists, so it is not unchecked. The two no_log reads of the join token are not changes: the stats count 2 changes on hawk.

  • The first run installed the 4 pinned collections of collections/requirements.yml and took 36 s. Two more runs used the kept install and took about 7 s each.
  • The three runs gave the same plan id.
  • The first run was from the worktree with --path, because the default checkout does not resolve from a worktree (fix(infra): find the checkout of an infra repo from a worktree #5195). The other two runs were the command above, from the main checkout folder with the code of this branch.

No host changed

I read hawk with a read-only ad-hoc ansible.builtin.command (no become, the key of devops ssh, host key checks on) before the first plan and after the last plan:

Read Before (19:11Z) After (19:31Z)
uptime -s 2026-11-12 08:03:39 2026-11-12 08:03:39
k3s-agent ActiveEnterTimestamp Thu 2026-11-12 08:03:51 MST Thu 2026-11-12 08:03:51 MST
k3s-agent ExecMainStartTimestamp Thu 2026-11-12 08:03:47 MST Thu 2026-11-12 08:03:47 MST
k3s-agent MainPID / NRestarts 1163 / 0 1163 / 0

uv run devops infra status dan-petty/homelab --ping before the plan: the 4 hosts in service are reachable, none waits for a reboot, and hawk is cordoned.

Checks run locally

  • uv run devops ci test tests/infra tests/commands/test_infra_plan.py tests/commands/test_infra_status.py tests/commands/test_infra_onboard.py tests/invariants/test_source_tree.py: 128 passed.
  • uv run devops ci test of the tests that cover the changed modules under src/devops_cli/infra/, models/infra.py, commands/infra.py and config/defaults.py: 4741 passed.
  • tests/lang and tests/docs: 101 passed. uv run devops ci docs, uv run devops openspec check, ruff, mypy on the changed modules and bandit on the changed source files pass.

@dan-petty
dan-petty marked this pull request as ready for review November 12, 2026 19:38
@dan-petty
dan-petty merged commit 050a6ef into main Nov 12, 2026
25 checks passed
@dan-petty
dan-petty deleted the feat/5124-plan-a-playbook-of-an-infra branch November 12, 2026 19:43
dan-petty pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.123.0](v0.122.0...v0.123.0)
(2026-11-12)


### Features

* **infra:** plan a playbook of an infra repo in check mode
([#5196](#5196))
([050a6ef](050a6ef))
* **monitoring:** enable the image renderer for panel checks
([#5193](#5193))
([e413c40](e413c40))


### Bug Fixes

* **monitoring:** make the GitHub and command panels readable
([#5194](#5194))
([e99810e](e99810e))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/infra Docker container images, DevContainers, and infrastructure tooling type/feature Type feature: a new function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant