Ansible Forks Calculator
Determine the optimal forks value for your control node based on host count, CPU cores and available memory.
Inputs
Total hosts targeted by the play.
vCPU cores available on the Ansible control node.
RAM available on the control node for the Ansible process.
Memory consumed per fork process (Python interpreter + module data) — 40-80MB is typical.
Optimal Forks Setting
8forks
Binding Constraint
CPU cores
CPU-Based Ceiling
8forks
Memory-Based Ceiling
136forks
Resulting Batches
38batches
Step by step
CPU-based ceiling: cores × 2
4 × 2
= 8 forks
Memory-based ceiling: memory ÷ per-fork memory
8192 ÷ 60
= 136 forks
Optimal forks: min(hosts, CPU ceiling, memory ceiling)
min(300, 8, 136)
= 8 forks (limited by CPU cores)
How it works
The forks setting controls how many hosts Ansible connects to and runs tasks against simultaneously. Setting it too low under-utilizes the control node and slows runs; setting it too high can exhaust CPU or memory on the control node, or overload the network/SSH capacity of target hosts. This calculator picks the largest safe value: the smaller of your total host count, a CPU-based ceiling (2× cores, since fork processes are largely I/O-bound waiting on SSH), and a memory-based ceiling (available memory ÷ per-fork footprint).
Formula
optimal_forks = min(hosts, cpu_cores × 2, available_memory_MB / per_fork_MB)
- hosts
- Total target hosts
- cpu_cores
- Control node vCPU cores
- available_memory_MB
- Control node RAM (MB)
- per_fork_MB
- Memory consumed per fork process (MB)
Frequently Asked Questions
Why 2× CPU cores as the ceiling instead of 1×?
Ansible forks spend most of their time waiting on network I/O (SSH round trips) rather than burning CPU continuously, so a control node can support more concurrent forks than raw core count without CPU becoming the bottleneck — 2× is a conservative multiplier for this I/O-bound pattern.
What if I set forks higher than my host count?
There's no benefit — Ansible can never run more concurrent connections than there are hosts in the current batch, so forks beyond your host count simply go unused.
How much memory does one fork really use?
It varies with module complexity and fact size, but 40-80MB per fork process is a reasonable planning number for typical playbooks; modules that gather large facts or process big data structures can use more.
Should I set forks globally in ansible.cfg?
Yes, for a baseline — most teams set a global default in `ansible.cfg` sized for their typical control node, then override with `--forks` for unusually large or resource-constrained runs.