Repository navigation
Description
Problem or Motivation
devops infra apply runs each disruptive host of a plan alone, "in plan order", and the plan lists its hosts in name order. So a play whose host order matters does not run in the order of the play.
The case that shows it: the K3s upgrade play of dan-petty/homelab (ansible/playbooks/07_cluster_upgrade.yaml, hosts: k3s_server:k3s_agent, serial: 1) upgrades the server node first and then each agent. The server host of that inventory sorts after four agent hosts by name. An apply of that play then changes the agents before the server, and each agent gets a newer kubelet than the API server, which the version skew policy of Kubernetes forbids. make upgrade (plain ansible-playbook) keeps the play order.
Evidence
src/devops_cli/infra/plan.py: the host plans are built withfor host in sorted(hosts).src/devops_cli/infra/apply.py,_apply_hosts:alone = [host for host in plan.hosts if host.disruptive], then one run for each of them in that order. Its docstring says "each disruptive host alone in plan order".- Read from the code on 2026-11-27. Not run: no apply of the upgrade play ran for this record.
- dan-petty/homelab pull request 439 adds a stop to the play: an agent does not change while the server node does not report
k3s_version. With it, an apply in name order stops at the first agent and changes nothing. It does not make the apply work.
Proposed Solution & Architectural Design
Run the disruptive hosts in the order in which the play runs them: the order that ansible-playbook --list-hosts gives for the play and its limit. Keep name order only as the order of the report.
Acceptance Criteria
- For a play with
hosts: <group a>:<group b>, the apply runs a disruptive host of group a before a disruptive host of group b, whatever their names are. - A test with a fake inventory holds the order: a server host whose name sorts last runs first.
- The plan report says in which order an apply runs the hosts.
Target Subsystem
Infrastructure repositories (devops infra)
Existing Tool Considered
ansible-playbook --list-hosts and ansible-inventory give the host order of a play. The change needs no new tool.
Alternatives check of 2026-11-27: in-use.
The repository already uses this tool.
Tool: ansible/ansible (https://github.com/ansible/ansible), GPL-3.0, last activity 2026-11-23, maintained.
Reason: Searches surfaced no tool that orders a per-host disruptive apply; Ansible's own --list-hosts already yields a play's host order, but the apply loop, the serial sequencing and the report are the project's code.
Covers:
- --list-hosts reports a play's hosts in play and group order
- Group order such as k3s_server:k3s_agent is preserved
- A plain run applies hosts in that order with serial
Lacks:
- No API to feed that order into a per-host apply loop
- No ordering of disruptive hosts run one at a time
- No plan report line naming the apply order
Proposed design
Problem statement
devops infra apply runs disruptive hosts in the name order of the saved plan. A play that needs a group order, such as a K3s upgrade with servers before agents, runs agents first and can break version skew. The fix makes the plan read the play host order and list disruptive hosts in that order. The report table stays name sorted and the report states the apply order.
Acceptance criteria
Requirement: Host order source
The plan SHALL read the host order from ansible-playbook --list-hosts with the playbook, each inventory source, the limit and the tags.
Scenario: Limit and tags reach list-hosts
- WHEN The saved plan has limit
k3s_server:k3s_agentand tagsupgrade. - THEN The captured
--list-hostscommand has the playbook path, each inventory source,--limit k3s_server:k3s_agentand--tags upgrade.
Requirement: Play order in plan
The plan SHALL list each disruptive host in the play host order, so a host of an earlier group comes before a host of a later group.
Scenario: Server host sorts last but runs first
- WHEN A fake inventory has group
awith hostzetaand groupbwith hostalpha, the play useshosts: a:b, and both hosts are disruptive. - THEN The plan lists
zetabeforealphaas disruptive hosts, althoughalphasorts first by name.
Requirement: Apply uses plan order
The apply SHALL run each disruptive host alone in the order of plan.hosts.
Scenario: Disruptive host order
- WHEN A saved plan lists disruptive hosts
zetathenalphaand non-disruptive hostbeta. - THEN The apply runs
zetaalone, thenalphaalone, and runsbetawith the non-disruptive hosts.
Requirement: Report table name order
The plan report's host table SHALL list hosts in name order.
Scenario: Table stays name sorted
- WHEN The plan host list is
zetathenalpha. - THEN The host table rows are
alphathenzeta.
Requirement: Report apply order
The plan report SHALL state the order in which an apply runs the disruptive hosts.
Scenario: Report line names apply order
- WHEN The plan host list is
zetathenalphaand both hosts are disruptive. - THEN The rendered report has one line that names
zetabeforealphaas the apply order.
Requirement: Host-order failure
The plan MUST stop with an error when ansible-playbook --list-hosts fails, so no plan with no host order can apply.
Scenario: List-hosts failure
- WHEN The
--list-hostscommand exits nonzero. - THEN The plan command exits 1 with an error that names the host-order read and saves no plan.
Existing Tool Considered
The alternatives check of 2026-11-27 in the issue body gives the verdict in-use for ansible/ansible (https://github.com/ansible/ansible). The repository already uses the tool. The check in the issue body lists what the tool covers and lacks. The proposal adds a small parser for the --list-hosts output, orders the plan hosts with it, and adds the report line. It builds no new host-order engine.
Key questions
- Which source gives the host order of a play?: Use
ansible-playbook --list-hostswith the plan's playbook, inventory sources, limit and tags. Do not parse the playbook YAML or keep name order. (best practice) [sources: src/devops_cli/infra/plan.py, src/devops_cli/infra/apply.py]- Chosen: ansible-playbook --list-hosts. The tool reports the play and group order, and the repository already uses Ansible.
- Rejected: Parse playbook YAML. It duplicates Ansible's pattern and group resolution and fails on dynamic inventory.
- Rejected: Keep name order. It causes the version-skew bug that the issue records.
- Does the plan record keep name order or play order?: Keep play order in
plan.hosts, because the apply uses that list. Sort the report host table by name. (best practice) [sources: src/devops_cli/infra/plan.py, src/devops_cli/infra/apply.py]- Chosen: Play order in
plan.hosts. The apply already runsplan.hostsin order, and the report can sort its own table by name. - Rejected: Name order in
plan.hostswith a separate apply-order field. It adds a second order to keep consistent and lets a plan hold two different host orders. - Rejected: Name order in
plan.hostsand re-read order in apply. It makes the apply read the repo again and can disagree with the plan report.
- Chosen: Play order in
- How does the plan report show both name order and apply order?: Keep the host table in name order and add one line to the report footer that lists the apply order. (best practice) [sources: src/devops_cli/infra/plan.py]
- Chosen: Footer line for apply order. It keeps the existing table stable and shows the order in one place.
- Rejected: Apply-order column in the host table. It repeats the order on each row and makes the table wider.
- Rejected: No report change. The issue requires the report to state the apply order.
- What does the plan do when
--list-hostsfails?: The plan ends failed with an error that names the host-order read. It saves no plan. (best practice) [sources: src/devops_cli/infra/plan.py, src/devops_cli/infra/apply.py]- Chosen: Fail the plan. A plan with no play order can apply disruptive hosts in the unsafe name order.
- Rejected: Fall back to name order. It keeps the bug and hides the failed read.
- Rejected: Ask the operator to give the order. It adds a manual step that the tool can do.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 27, 2026
5125 delivers the apply-one-disruptive-host-at-a-time feature; the candidate fixes the order in which those hosts run, a defect within that delivered feature.devops-cli-service commentedon Nov 27, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (6)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 28, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
devops-cli-service commentedon Nov 28, 2026
Released in v0.241.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.241.0
devops-cli-service commentedon Nov 29, 2026
Live since 2026-11-29 00:41 UTC