Ansible in a Minute · Ansible Core ·
Use serial to run a play against 20% of hosts at a time
Short answer
Use the serial keyword to limit how many hosts Ansible processes in each batch.
Request
check uptime and date on 20% of hosts at a time using the serial keyword; changed_when: false
Example
A quick heads-up: Every environment is different. Review and test this example before you run it on systems you care about.
YAML
---
- name: Check uptime and date on 20% of hosts at a time
hosts: all
gather_facts: true
serial: "20%"
tasks:
- name: Check uptime
ansible.builtin.command:
cmd: uptime
register: uptime_result
changed_when: false
- name: Check date
ansible.builtin.command:
cmd: date
register: date_result
changed_when: false
- name: Display uptime
ansible.builtin.debug:
msg: "{{ uptime_result.stdout }}"
- name: Display date
ansible.builtin.debug:
msg: "{{ date_result.stdout }}"How it works
serial accepts a number or a percentage. Ansible finishes one batch before it starts the next batch. Set changed_when to false on read-only command tasks so they do not report changed.
When to use it
- Use serial when you must update hosts in controlled batches.
- Do not use serial when every host must change in one wave.
- Rolling updates across a large inventory
Requirements
- Ansible: >=2.14
- An inventory with multiple hosts
Validation
- Syntax validated
- Execution passed
- Last verified 2026-09-03
Watch the embedded demo, then run the example against a multi-host inventory to confirm batching.
Try it with BacklogZero
Ask BacklogZero to generate this automation for your environment.