BacklogZero®

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.

Ansible in a Minute — serial 20%

Subscribe for updates

Get an email whenever we publish new guides and blog posts. Unsubscribe anytime.

By subscribing you agree we may email you about Ansible in a Minute and related Level Up Labs updates. We store your address in the same lead sheet as our contact form.

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.

Reference

Built for every Ansible use case in every organization

BacklogZero can generate this kind of automation in your environment, just like it did here.

Get BacklogZero today →

Related guides

← Back to Ansible in a Minute

Use serial to run a play against 20% of hosts at a time · Level Up Labs