Serial determines the number or percentage of managed nodes (e.g. the target systems) that all of the tasks in a playbook will be run against simultaneously.
Let's say you have the following playbook, which contains 2 tasks. The first task will create /tmp/foo.txt on the managed nodes. The second task will create /tmp/bar.txt on the managed nodes.
---
- hosts: all
tasks:
- name: create /tmp/foo.txt
file:
path: /tmp/foo.txt
state: touch
- name: create /tmp/bar.txt
file:
path: /tmp/bar.txt
state: touch
...
Let's also say you have 4 managed nodes defined in your default hosts file or your own inventory file, server1.example.com through server4.example.com. Without defining serial, all of the tasks in the playbook will be run against all 4 servers simultaneously. The play recap should look something like this.
PLAY [all]
TASK [create /tmp/foo.txt]
changed: [server1.example.com]
changed: [server2.example.com]
changed: [server3.example.com]
changed: [server4.example.com]
TASK [create /tmp/bar.txt]
changed: [server1.example.com]
changed: [server2.example.com]
changed: [server3.example.com]
changed: [server4.example.com]
PLAY RECAP
server1.example.com : ok=2 changed=2 unreachable=0 failed=0
server2.example.com : ok=2 changed=2 unreachable=0 failed=0
server3.example.com : ok=2 changed=2 unreachable=0 failed=0
server4.example.com : ok=2 changed=2 unreachable=0 failed=0
Now let's include serial: 2 in the playbook.
---
- hosts: all
serial: 2
tasks:
- name: create /tmp/foo.txt
file:
path: /tmp/foo.txt
state: touch
- name: create /tmp/bar.txt
file:
path: /tmp/bar.txt
state: touch
...
The play recap should look something like this. Notice that both tasks were first run against server1.example.com and server.example.com only, because serial was set to 2. Then the tasks were again run, against server3.example.com and server4.example.com.
PLAY [all]
TASK [create /tmp/foo.txt]
changed: [server1.example.com]
changed: [server2.example.com]
TASK [create /tmp/bar.txt]
changed: [server1.example.com]
changed: [server2.example.com]
PLAY [all]
TASK [create /tmp/foo.txt]
changed: [server3.example.com]
changed: [server4.example.com]
TASK [create /tmp/bar.txt]
changed: [server3.example.com]
changed: [server4.example.com]
PLAY RECAP
server1.example.com : ok=2 changed=2 unreachable=0 failed=0
server2.example.com : ok=2 changed=2 unreachable=0 failed=0
server3.example.com : ok=2 changed=2 unreachable=0 failed=0
server4.example.com : ok=2 changed=2 unreachable=0 failed=0
Additionally, serial can also take a percentage.
---
- hosts: all
serial: 25%