# Controlling parallelism at task level?

**URL:** <https://forum.ansible.com/t/controlling-parallelism-at-task-level/16883>\
**Category:** Ansible Project\
**Created:** [November 25, 2014, 8:10pm UTC](https://forum.ansible.com/t/controlling-parallelism-at-task-level/16883 "2014-11-25T20:10:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Hughes](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@Matt\_Hughes](https://forum.ansible.com/u/Matt_Hughes)\
**Post date:** [November 25, 2014, 8:10pm UTC](https://forum.ansible.com/t/controlling-parallelism-at-task-level/16883/1 "2014-11-25T20:10:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Matt\_Hughes](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@Matt\_Hughes](https://forum.ansible.com/u/Matt_Hughes)\
**Post date:** [November 25, 2014, 8:15pm UTC](https://forum.ansible.com/t/controlling-parallelism-at-task-level/16883/2 "2014-11-25T20:15:21Z")

</div>

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

`

```auto

- 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.

---

<div class="post-metadata">

**Author:** ![Nigel\_Metheringham](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nigel\_Metheringham](https://forum.ansible.com/u/Nigel_Metheringham)\
**Post date:** [November 25, 2014, 9:22pm UTC](https://forum.ansible.com/t/controlling-parallelism-at-task-level/16883/3 "2014-11-25T21:22:41Z")

</div>

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](http://docs.ansible.com/playbooks_delegation.html#rolling-update-batch-size)

&nbsp;&nbsp;Nigel.
