Bootstrap FreeKB - Ansible - Complete each task on each node before moving onto next task using Linear Strategy (Parallelism)
Ansible - Complete each task on each node before moving onto next task using Linear Strategy (Parallelism)

Updated:   |  Ansible articles

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 linear

 

With the linear strategy, each task is performed against all of the managed nodes (e.g. target systems) before moving onto the next task. For example, let's say the file module is being used to create two directories, /tmp/foo and /tmp/bar. linear is the default strategy, thus there is no need to define linear as the strategy in the playbook.

---
- hosts: all
  tasks:
    - name: mkdir /tmp/foo
      file:
        path: /tmp/foo
        state: directory

    - name: mkdir /tmp/bar
      file:
        path: /tmp/bar
        state: directory
...

 

Let's say you have 5 managed nodes in your inventory, server1 through server5. In this example, this means 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.

 

Optionally, you can define linear as the strategy in ansible.cfg. But this is not required, since linear is the default strategy.

strategy = linear

 




Did you find this article helpful?

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



Comments


Add a Comment


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