You need to check a condition on all hosts first and only then change any of them.
AdvancedScenarioRolling Updates, Delegation and Orchestration
Answer
Situation read → All-or-nothing gate.
What I'd do → Use a preflight play with any_errors_fatal.
- hosts: db
any_errors_fatal: true
tasks:
- ansible.builtin.assert:
that: ansible_facts['mounts'] | selectattr('mount','equalto','/') | map(attribute='size_available') | first > 5000000000
fail_msg: "Less than 5 GB free on /"
- hosts: db
roles: [upgrade]
Why → Failing in the first play means no host has changed yet.
Interview tip → A strong answer includes a rollback strategy, not only a gate.
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