Interview Prep/Ansible/Rolling Updates, Delegation and Orchestration

A task on host A needs data produced by host B in the same play.

AdvancedScenarioRolling Updates, Delegation and Orchestration
Answer

Situation read → Cross-host data flow.

What I'd do → Register on B, read with hostvars from A, and make sure B's task ran first (strategy linear guarantees that per task).

- hosts: db_primary
  tasks:
    - ansible.builtin.command: pg_current_wal_lsn
      register: lsn
- hosts: db_replica
  tasks:
    - ansible.builtin.debug: { msg: "{{ hostvars[groups['db_primary'][0]].lsn.stdout }}" }

Why → hostvars exposes registered variables from earlier plays in the same run.

Interview tip → In a single play with free strategy ordering is not guaranteed.

All Ansible questions Roadmap: Ansible

More on Rolling Updates, Delegation and Orchestration