You need to patch hosts in a specific order, lowest-traffic first, and the order is stored as a variable.
AdvancedScenarioRolling Updates, Delegation and Orchestration
Answer
Situation read → Custom host ordering that order: cannot express.
What I'd do → Define explicit numeric tiers per host and run one play per tier, or give serial a fixed ordering through group membership.
# host_vars: patch_wave: 1 / 2 / 3
- hosts: all
gather_facts: false
tasks:
- ansible.builtin.group_by:
key: "wave_{{ patch_wave }}"
- import_playbook: patch.yml
vars: { wave_group: wave_1 }
- import_playbook: patch.yml
vars: { wave_group: wave_2 }
with hosts: "{{ wave_group }}" and serial inside patch.yml.
Why → Play order only supports inventory, reverse_inventory, sorted, reverse_sorted and shuffle; anything else needs explicit grouping.
Interview tip → If you cannot do it simply, ask whether the ordering is truly required.
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