Skip to content

fix(infra): apply skips the last host of a multi-host run #6337

Closed

Description

@dan-petty

Problem Description

devops infra apply does not run the last host of a run of hosts that have no disruptive class. The limit of that run is a comma list of hosts with :!<offline group> at the end. Ansible splits a pattern that has a comma on the commas only, so the last term is <last host>:!offline. That term matches no host. Ansible ignores it with a warning and runs only the other hosts. The !offline exclusion then applies to no host of the run.

Code:

  • host_pattern in src/devops_cli/infra/plan.py:164 appends f":!{offline_group}" to the limit.
  • _apply_together in src/devops_cli/infra/apply.py:553 gives it ",".join(host.host for host in hosts).
  • devops infra plan --limit a,b goes through the same function (plan.py:592), so a plan with a comma limit has the same problem.
  • The dry-run text in src/devops_cli/infra/infra_plans.py:281 shows the same pattern.

Ansible source (ansible/inventory/manager.py, split_host_pattern): "If it's got commas in it, we'll treat it as a straightforward comma-separated list of patterns." A colon is a separator only in a pattern with no comma. The Ansible documentation prefers the comma.

Reproduction Steps

  1. Plan the playbook ansible/playbooks/02_nvidia.yaml of dan-petty/homelab with --limit gpu_nodes. The group has 4 hosts, and none of them has a disruptive change.
  2. Apply the plan with devops infra apply.
  3. Read the command and stdout files of the runner artifacts of the apply.

Expected vs Actual Behavior

Expected: the run reaches each host of the plan, and never a host of the offline group.

Actual (apply bc18ea1590e2472bb1b59929494e08c3 of plan ac4b4b84017e..., 2026-11-18):

  • The command was ansible-playbook -v -i ansible/inventory/hosts.yaml ... --limit <gpu-node-1>,<gpu-node-2>,<gpu-node-3>,<gpu-node-4>:!offline ansible/playbooks/02_nvidia.yaml.
  • Ansible said Could not match supplied host pattern, ignoring: <gpu-node-4>:!offline.
  • The PLAY RECAP lists 3 hosts. The apply said that the run did not reach <gpu-node-4>, so that host did not get the change.

Proposed Fix

Make host_pattern use the separator that Ansible reads for the given limit: , when the limit has a comma, else :. This needs no new dependency.

Acceptance Criteria

  • A test of host_pattern("a,b", "offline") gives a pattern in which a, b and !offline are each one term. It fails on main (devops ci fail-to-pass).
  • A test of host_pattern("gpu_nodes", "offline") keeps a pattern that excludes the offline group.
  • An apply test with a fake runner: a run together of 2 or more hosts gets a limit in which each host is one term.
  • The dry-run text of infra_plans.py shows the new pattern.

Logs, Traces, or Terminal Output

Runner artifacts: .data/infra/dan-petty/homelab/plans/<plan id>/applies/<apply id>/artifacts/<ident>/{command,stdout}.

Alternatives check of 2026-11-19: none.
Tool: none found.
Reason: Searches found no open tool or library for this need: it is a defect in the project's own host_pattern helper, fixed by appending Ansible's documented comma-or-colon separator and adding no dependency.

Lacks:

  • No external tool builds the ansible limit pattern
  • Separator choice must follow whether the limit has a comma
  • Dry-run text and apply command must share one separator rule
  • Fix stays inside the existing helper with no new dependency

Proposed design

Problem statement

The apply and plan commands can skip the last host of a comma limit. host_pattern appends :!<offline group> to the limit. Ansible splits a comma limit on commas only, so the last term <last host>:!offline matches no host. The offline exclusion then applies to no host of the run. The fix appends a comma when the limit has a comma and a colon when it has no comma.

Acceptance criteria

Requirement: Comma limit uses a comma before the offline exclusion

host_pattern SHALL append the offline exclusion as its own comma-separated term when the limit contains a comma.

Scenario: Comma-separated limit

  • WHEN A test in tests/infra/test_plan.py calls host_pattern('a,b', 'offline'), and uv run devops ci fail-to-pass --base origin/main runs the test before the fix.
  • THEN The test asserts a,b,!offline, and the same test fails on main.

Requirement: Single group uses a colon before the offline exclusion

host_pattern SHALL append the offline exclusion with a colon when the limit contains no comma.

Scenario: Single group limit

  • WHEN A test in tests/infra/test_plan.py calls host_pattern('gpu_nodes', 'offline').
  • THEN The test asserts gpu_nodes:!offline, so the pattern excludes the offline group.

Requirement: Together run has one term for each host

An apply of hosts with no disruptive class SHALL pass a limit in which each host and the offline exclusion are separate terms.

Scenario: Together run with a fake runner

  • WHEN An apply test with a fake runner calls _apply_together for the hosts a and b, which have no disruptive class.
  • THEN The fake runner receives the limit a,b,!offline, and the test asserts that each host is one term.

Requirement: Dry-run text uses the fixed separator

The dry-run text of src/devops_cli/infra/infra_plans.py SHALL show the same separator rule that the real run uses.

Scenario: Dry run with two together hosts

  • WHEN A test of the dry-run text builds it for a together run of the hosts a and b.
  • THEN The text shows a,b,!<offline group> and not a,b:!<offline group>.

Requirement: Plan command uses the fixed pattern for a comma limit

devops infra plan --limit a,b SHALL pass a limit in which each host and the offline exclusion are separate terms.

Scenario: Plan command with a comma limit

  • WHEN A test in tests/commands/test_infra_plan.py invokes the plan command with --limit a,b and a fake runner.
  • THEN The fake runner receives a,b,!offline as its --limit value.

Existing Tool Considered

The alternatives check of 2026-11-19 in the issue body records the verdict none; it names no tool. The change edits the existing host_pattern helper and adds no dependency. The change builds no new component, so no separate build cost applies.

Key questions

  • Which separator should host_pattern append to the offline group?: Append , when the limit has a comma. Append : when the limit has no comma. (best practice) [sources: src/devops_cli/infra/plan.py:164, src/devops_cli/infra/apply.py:555]
    • Chosen: Comma when the limit has a comma, else colon. The appened term uses the separator that Ansible reads for that limit, so each host stays one term.
    • Rejected: Always colon. A comma limit ends with <last host>:!offline, which Ansible cannot match.
    • Rejected: Always comma. It changes the syntax for a limit with no comma and is wider than the defect.
  • Does devops infra plan --limit a,b use the same host_pattern function?: Yes. plan.py calls host_pattern(request.limit, ansible.offline_group) at line 592. [sources: src/devops_cli/infra/plan.py:592, src/devops_cli/infra/plan.py:164]
  • Does _apply_together pass its together host list through host_pattern?: Yes. _apply_together calls context.run.run(host_pattern(names, context.offline_group), check_mode=False) at line 555. [sources: src/devops_cli/infra/apply.py:551, src/devops_cli/infra/apply.py:555, src/devops_cli/infra/plan.py:164]
  • How should the dry-run text show the fixed pattern?: Use the same separator rule as host_pattern: , before the offline exclusion when the together list has a comma, else :. (best practice) [sources: src/devops_cli/infra/infra_plans.py:281, src/devops_cli/infra/plan.py:164]
    • Chosen: Use the same separator rule. The dry-run text then matches the command that the apply runs.
    • Rejected: Leave :! in the dry-run text. It shows a pattern that Ansible cannot match for a comma list.
  • Does the fix need a new dependency?: No. The fix edits the existing host_pattern helper and adds no dependency. [sources: src/devops_cli/infra/plan.py:164]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    scope/infra
    source/agent
    status/new
    effort/low
    on Nov 18, 2026
  2. dan-petty commented on Nov 18, 2026

    @dan-petty
    OwnerAuthor
    • Priority: P1-High. A host is silently skipped from an apply, leaving it without the intended change and creating inconsistent state.
    • Related: fix(infra): the apply gate leaves out alerts of offline nodes #5455, which asks for a different change. Both handle the offline group during devops infra apply, but 5455 fixes the health gate alert query while this fixes the host pattern separator.
  3. added
    value/high
    priority/p1-high
    on Nov 18, 2026
  4. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.

  5. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    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 (3)

    Searches run:

    • ansible host pattern comma colon separator split_host_pattern, results: 5
    • library build ansible --limit host pattern with exclusion group, results: 5
    • ansible patterns how to target hosts and groups documentation limit, results: 5
  6. added
    status/ready
    and removed
    status/new
    on Nov 19, 2026
  7. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 29e3a03 (see proposed design in issue body).

  8. added
    owner/service
    on Nov 19, 2026
  9. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Plan state: branch fix/6337-apply-skips-the-last-host-of, draft pull request #6387. The pull request plans the item and closes no issue. The stage job and the step fix-plan edit this comment, and a comment of each run tells what the run did.

    The task groups, with the tokens of the inputs of each step, for a budget of 64000 tokens:

    1. Fix the offline separator of host_pattern: 27836 tokens
    2. Show the fixed separator in the dry run of the plan command: 23362 tokens
    3. Show the fixed separator in the dry run of the apply command: 24584 tokens
    4. Read the hosts of a comma limit in the fake runner: 18521 tokens

    A model review of the plan found these points. They stop no draft, and a person judges them:

    • minor spec_delta_wrong at spec infra-apply (Each host of the together run is one term of the limit): The added requirement says every together run names each host and the offline exclusion as separate comma-separated terms, but the plan keeps a colon when the together run holds one host (decision 3 and the unchanged apply snapshot), so the archived requirement would be false for the existing one-host together run. Evidence: "The limit of the run of the hosts with no disruptive class SHALL name each host and the offline exclusion as separate comma-separated terms"
    • minor false_premise at proposal (feasibility): The feasibility note says the plan dry run shows the limit with !offline, but the dry run builds the pattern with the literal <offline group> placeholder, as the plan's own quote of infra_plans.py:182 shows. Evidence: "--dry-run must show --limit '<gpu-node-a>,<gpu-node-b>,!offline'"
  10. 4 remaining items

  11. added
    status/in-progress
    and removed
    owner/service
    on Nov 19, 2026
  12. added
    status/in-review
    and removed
    status/in-progress
    on Nov 19, 2026
  13. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Pull request #6387 is ready for review. The checks passed.

    Spend: 105 model requests, 5031253 input tokens, 87043 output tokens.

  14. removed
    status/in-review
    on Nov 19, 2026
  15. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-19 11:42 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/lowpriority/p1-highscope/infrasource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions