There are 4 strategies that can be used.
- debug (same as linear except debug info will be returned)
- free (each managed node will go through the tasks independently, with the goal of completing the playbook as quickly as possible)
- host_pinned (set a limit on the number of managed hosts that will execute the tasks in a playbook simultaneously)
- linear (complete each task on each managed node before moving onto next task)
The ansible-doc command can be used to display documentation on the each strategy.
ansible-doc -t strategy --snippet free
Let's consider the scenario where Ansible is being used to perform two (or more) tasks on managed nodes (e.g. target systems). For example, let's say the file module is being used to create two directories, /tmp/foo and /tmp/bar.
- hosts: all
- name: mkdir /tmp/foo
- name: mkdir /tmp/bar
By default, Ansible uses the linear strategy, which means that each task is performed against all of the managed nodes before moving onto the next task. Let's say you have 5 managed nodes in your inventory, server1 through server5. In this example, this would mean that the /tmp/foo directory would be created on server1 through server5 before moving onto the task to create the /tmp/bar directory on server1 through server5.
With the free strategy, each managed node will go through each task in the playbook independently, with the goal being for each managed node to complete the playbook as quickly as possible.
To use the free strategy, you could include strategy: free in your playbook.
- hosts: all
Or you could set the the strategy to free in ansible.cfg, which would make free the default strategy for all playbooks.
strategy = free
Or you could set the ANSIBLE_STRATEGY environmental variable to free for your current shell.