elway: add register: to capture step output into playbook vars #4

Open
opened 2026-04-24 10:40:43 -07:00 by vh · 0 comments
Owner

Follow-up to elway's tier 1 + tier 2 idempotency. Would pair well with when: and changed_when:.

steps:
  - name: Probe for container
    shell: docker inspect --format '{{"{{"}}.State.Status{{"}}"}}' comfyui
    register: container_state
    changed_when: "false"   # probe — never counts as a change

  - name: Start container
    shell: docker compose -f /opt/docker/compose/comfyui/compose.yaml up -d
    when: "echo {{ container_state.stdout }} | grep -vq running"

Semantics

  • register: <var_name> captures the step's exit code + stdout + stderr into the playbook vars namespace under that name.
  • Exposed fields: {{ var.stdout }}, {{ var.stderr }}, {{ var.rc }}, {{ var.state }}.
  • Only populated for shell steps (uploads don't have meaningful output).
  • Subsequent steps can reference the var in when: / shell: / etc. via the regular templating.

Implementation impact

  • _stream_process currently streams output directly and doesn't capture. Would need to tee: stream to terminal AND buffer for registered variables.
  • substitute() needs to resolve dotted attribute access ({{ var.field }}) in addition to simple {{ var }}.
  • Output buffer sizes worth capping (e.g. 64 KiB per step) so a chatty step doesn't blow up memory.

LOE

~60-100 LOC. Blocked on no external dep; just a tee + a nested-attribute templater.

Why file separately

Same reason as #3 (handlers): valuable but not urgent. Tier 1+2 covers the common case, and you can always register by tee-ing to a file on the remote and cating it in a later step's when:.

Follow-up to elway's tier 1 + tier 2 idempotency. Would pair well with `when:` and `changed_when:`. ```yaml steps: - name: Probe for container shell: docker inspect --format '{{"{{"}}.State.Status{{"}}"}}' comfyui register: container_state changed_when: "false" # probe — never counts as a change - name: Start container shell: docker compose -f /opt/docker/compose/comfyui/compose.yaml up -d when: "echo {{ container_state.stdout }} | grep -vq running" ``` ### Semantics - `register: <var_name>` captures the step's exit code + stdout + stderr into the playbook vars namespace under that name. - Exposed fields: `{{ var.stdout }}`, `{{ var.stderr }}`, `{{ var.rc }}`, `{{ var.state }}`. - Only populated for shell steps (uploads don't have meaningful output). - Subsequent steps can reference the var in `when:` / `shell:` / etc. via the regular templating. ### Implementation impact - `_stream_process` currently streams output directly and doesn't capture. Would need to tee: stream to terminal AND buffer for registered variables. - `substitute()` needs to resolve dotted attribute access (`{{ var.field }}`) in addition to simple `{{ var }}`. - Output buffer sizes worth capping (e.g. 64 KiB per step) so a chatty step doesn't blow up memory. ### LOE ~60-100 LOC. Blocked on no external dep; just a tee + a nested-attribute templater. ### Why file separately Same reason as #3 (handlers): valuable but not urgent. Tier 1+2 covers the common case, and you can always register by tee-ing to a file on the remote and `cat`ing it in a later step's `when:`.
vh added the enhancement label 2026-04-24 10:40:43 -07:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vh/esh-pfi-infrastructure#4