Ansible - Set the number of nodes a task will run against simultaneously using Forks (Parallelism)

Forks determines how many managed nodes (e.g. the target systems) a task will be run against simultaneously. By default, ansible.cfg is setup with 5 forks.

forks = 5


Let's say you have the following playbook, which uses the files module to create /tmp/foo.txt on a managed node (e.g. the target system).

- hosts: all
    - name: create /tmp/foo.txt
        path: /tmp/foo.txt
        state: touch


Let's also say you have 10 managed nodes defined in your default hosts file or your own inventory file, through Since the default is 5 forks, the task to create /tmp/foo.txt will first be executed on through simultaneously, then through simultaneously.


Forks is not so much of a concern with the managed nodes. Instead, the concern is with the demand put on the control node (your Ansible server). Let's say you have 1000 managed nodes, and forks is set to 1000 (probably not a good idea). In this situation, each task in the playbook would be run against all 1000 managed nodes simultaneously. This could put too much demand on your Ansible server in the form of CPU utilization and memory usage, and also put a blast of packets on your network, which could impact network performance will the tasks are being executed. For this reason, a reasonable approach is to baseline the performance of your Ansible server and network, monitor the performance of your Ansible server and network while running a playbook with the default setting of 5 forks, monitor the performance of your Ansible server and network while running a playbook with some other forks settings (e.g. 100 forks), and then compare the performance to determine which fork setting is ideal.

There are two ways to define the number of forks that will be used.



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 12998 in the box below so that we can be sure you are a human.