You must deploy a new app version to 40 web servers behind a load balancer with zero downtime.
AdvancedScenarioRolling Updates, Delegation and Orchestration
Answer
Situation read → Rolling update: take a few nodes out, update, verify, put back.
What I'd do →
- Use
serialto limit the batch size. - Drain each node from the LB with
delegate_to. - Deploy, health check, re-enable.
- hosts: web
serial: [1, "10%", "25%"]
max_fail_percentage: 10
pre_tasks:
- community.general.haproxy: { backend: web, host: "{{ inventory_hostname }}", state: disabled, wait: true }
delegate_to: lb01
roles: [app]
post_tasks:
- ansible.builtin.uri: { url: "http://{{ inventory_hostname }}:8080/health" }
register: h
until: h.status == 200
retries: 15
delay: 4
- community.general.haproxy: { backend: web, host: "{{ inventory_hostname }}", state: enabled }
delegate_to: lb01
Why → The canary-first serial list limits risk, and the health gate stops the roll before it spreads.
Interview tip → Mention max_fail_percentage and any_errors_fatal as stop conditions.
More on Rolling Updates, Delegation and Orchestration
What 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.BeginnerA deployment should run strictly one host at a time, but fact gathering should not be slow.Intermediate