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.
More on Rolling Updates, Delegation and Orchestration
You must deploy a new app version to 40 web servers behind a load balancer with zero downtime.AdvancedWhat does `serial: [1, 5, "50%"]` do?BeginnerDuring a rolling update, 3 of 10 hosts in a batch fail. Does the play continue?IntermediateYou must restart database replicas one at a time but never the primary first.AdvancedYou need a task to run on the LB for every web host, without logging into each web host.IntermediateA shell command must run on localhost for each remote host, e.g. a CLI call to a cloud API.Beginner