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
tasks:
- name: mkdir /tmp/foo
file:
path: /tmp/foo
state: directory
- name: mkdir /tmp/bar
file:
path: /tmp/bar
state: directory
...
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.
The debug strategy is also linear, except that the debug strategy will include debug output if there is some issue with the playbook.
To use the debug strategy, you could include strategy: debug in your playbook.
---
- hosts: all
strategy: debug
Or you could set the the strategy to debug in ansible.cfg, which would make debug the default strategy for all playbooks.
strategy = debug
Or you could set the ANSIBLE_STRATEGY environmental variable to debug for your current shell.
export ANSIBLE_STRATEGY=debug
Notice in this example that strategy: debug and state: bogus are used.
---
- hosts: all
strategy: debug
tasks:
- name: mkdir /tmp/foo
file:
path: /tmp/foo
state: bogus
- name: mkdir /tmp/bar
file:
path: /tmp/bar
state: directory
...
When running this playbook, debug output should be returned.
[john.doe@ansible1 ~]$ ansible-playbook testing.yml
PLAY [all]
TASK [create /tmp/foo.txt]
fatal: [dns1.software.eng.us]: FAILED! => {"changed": false, "msg": "value of state must be one of: absent, directory, file, hard, link, touch, got: bogus"}
[server1.example.com] TASK: create /tmp/foo.txt (debug)>
Did you find this article helpful?
If so, consider buying me a coffee over at