Interview Prep/Ansible/Rolling Updates, Delegation and Orchestration

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.

All Ansible questions Roadmap: Ansible

More on Rolling Updates, Delegation and Orchestration