Ansible - Host Pinned Strategy (Parallelism)

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 host_pinned


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
        path: /tmp/foo
        state: directory

    - name: mkdir /tmp/bar
        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 host_pinned strategy is also linear, except that once a certain number of managed nodes are processing the tasks in the playbook, additional managed nodes will need to wait (like their in queue) for one of the managed nodes to complete all of the tasks in the playbook to free up a slot for the next managed host to start processing the tasks in the playbook.

To use the host_pined strategy, you could include strategy: host_pinned in your playbook.

- hosts: all
  strategy: debug


Or you could set the the strategy to host_pinned in ansible.cfg, which would make host_pinned the default strategy for all playbooks.

strategy = debug


Or you could set the ANSIBLE_STRATEGY environmental variable to host_pinned for your current shell.

export ANSIBLE_STRATEGY=host_pinned


Let's say you invoke your playbook with 3 forks using the --forks command line option. In this scenario, 3 managed nodes will start to go through the tasks in the playbook, and the remaining managed nodes will not start processing the tasks in the playbook until one of the prior managed nodes completes all of the tasks in the playbook.

ansible-playbook example.yml --forks 3


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 f29a3 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |