Controlling parallelism at task level?

The only way I’ve seen to control the parallelism of a task is with the --fork flag. Is there any way to control this at the task level?

First three tasks can occur fully concurrently

  • task 1
  • task 2
  • task 3

Then I want to perform this block one host at a time to perform a rolling upgrade

-task 4
-task 5

In my case, the first three tasks take a long time but are not a risk when performing an upgrade. Task 4/5 actually take services down so I want to only perform them one host at a time.

The closest I’ve come to this has been by using wait_for, but I’m not sure what the guarantees are here:

`


- local_action wait_for: path=/tmp/ansible.lock state=absent
// touch /tmp/ansible.lock
// perform task4/5
// delete /tmp/ansible.lock

`

If I run with --fork=5, isn’t it possible that more than one fork will see the lock being absent at the same time and perform tasks 4/5 concurrently.

Matt Hughes wrote:

The only way I've seen to control the parallelism of a task is with the
--fork flag. Is there any way to control this at the task level?

Split your tasks into separate plays for the parallelisable, and single host sections.

On the single host section add a "serial: 1" to the play setup parameters.

See
http://docs.ansible.com/playbooks_delegation.html#rolling-update-batch-size

  Nigel.