Interview Prep/Ansible/Rolling Updates, Delegation and Orchestration

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.

All Ansible questions Roadmap: Ansible

More on Rolling Updates, Delegation and Orchestration