DevOps / Ansible Interview questions
How does forking improve execution speed in Ansible?
By default, Ansible processes only 5 hosts at a time (forks = 5); for each task, it must finish running against all currently-active hosts (up to that limit) before starting the next batch, so with a large inventory, execution time scales roughly with (number of hosts / forks) rather than shrinking automatically as inventory grows.
# ansible.cfg [defaults] forks = 50
Increasing forks raises how many hosts the control node processes concurrently per task, which directly cuts total wall-clock time for large inventories, since more hosts are being worked on in parallel rather than queued waiting for a slot to free up. The practical ceiling is the control node's own resources: each fork consumes CPU, memory, and a network connection, so forks should be raised in proportion to what the control node (and target network/SSH capacity) can actually sustain, rather than set arbitrarily high, since an overloaded control node can end up slower overall from resource contention than a more conservative fork count.
More Related questions...