You must restart database replicas one at a time but never the primary first.
AdvancedScenarioRolling Updates, Delegation and Orchestration
Answer
Situation read → Ordering matters and roles differ.
What I'd do → Two plays: replicas with serial: 1, then the primary after a controlled failover.
- hosts: db_replicas
serial: 1
tasks:
- ansible.builtin.include_role: { name: pg_upgrade }
- ansible.builtin.command: pg_isready
register: r
until: r.rc == 0
retries: 20
delay: 5
- hosts: db_primary
tasks:
- ansible.builtin.command: patronictl switchover --force --candidate "{{ new_primary }}"
run_once: true
- ansible.builtin.include_role: { name: pg_upgrade }
Why → Ansible plays run in order, so order is explicit and each stage is gated.
Interview tip → Check replication lag before moving on.
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 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.BeginnerA deployment should run strictly one host at a time, but fact gathering should not be slow.Intermediate