← Back to list

Ansible: Fork and Serial

Did you ever get confused about when to use Fork and when to use Serial in Ansible? If yes, don’t worry. Most beginners (and even…

Aishwary Prakash · 2026-02-21 20:03 · 0 claps · 1.6 min read
#ansible #serial #fork
Open on Medium ↗
Wiki topics: ☁️ · DevOps & Cloud

Ansible: Fork and Serial

Photo by Anoir Chafik on Unsplash

Photo by Anoir Chafik on Unsplash

Did you ever get confused about when to use Fork and when to use Serial in Ansible? If yes, don’t worry. Most beginners (and even intermediates) face this confusion.

Fork —

Fork controls how many hosts(worker) Ansible connects to in parallel at one time.

  • Default value: 5
  • You can change it using the “-f” flag.

Example:

ansible-playbook site.yml -f 20

This means: → Ansible can open 20 SSH connections in parallel → Up to 20 hosts can be processed simultaneously

When to use high forks?

  • You want faster execution
  • Large infrastructure (100+ servers)
  • Simple tasks- Package installation, File copy, Running commands

Higher forks = More CPU + Network usage

Serial —

Serial controls how many hosts are processed in one batch.

Example:

serial: 10

This means: → Run tasks on 10 hosts at a time → Then move to the next batch of 10 hosts

When to use serial?

  • Production deployments
  • Rolling updates
  • Zero-downtime upgrades
  • Controlled rollout

Actual parallel connections = min(serial, forks)

Now let’s understand both together —

Example: In playbook, you mentioned serial: 10

In CLI, we are using -f 20 ansible-playbook site.yml -f 20

What happens?

Note: batch size = Number of batches = ceil(total hosts / serial), means “round up”

If there are 100 hosts, serial = 10 , fork = 20

batch size = ceil( 100/ 10) = 10, so we will have batch-1 to batch-10 fork = 20, means max. parallel connections allowed = 20

Actual parallel connections = min(serial, forks) = min(10,20) = Only 10 parallel connections will be used.

Execution flow:

Batch 1 → hosts 1–10

Batch 2 → hosts 11–20

Batch 3 → hosts 21–30

Batch 4 → hosts 31–40

so on Batch 10 → host 91–100

Each batch will have 10 hosts , meaning 10 parallel ssh connection. Ansible will open SSH connections equal to the number of hosts in the current batch, capped by forks.

  • Fork → Controls how many hosts can be executed in parallel
  • Serial → Controls how many hosts are deployed at a time (batch size)
  • Actual parallelism = min(serial, forks)

Until next time — keep questioning, keep learning, and keep growing.


메타데이터
post_id
18dd2ea0a048
slug
ansible-fork-and-serial-18dd2ea0a048
url
https://medium.com/@aishwaryprakash98/ansible-fork-and-serial-18dd2ea0a048
canonical_url
https://medium.com/@aishwaryprakash98/ansible-fork-and-serial-18dd2ea0a048
author_url
https://medium.com/@aishwaryprakash98
status
ok
fetched_at
2026-06-17 08:20:12