Controlling parallelism at task level?

42 views
Skip to first unread message

Matt Hughes

unread,
Nov 25, 2014, 3:10:39 PM11/25/14
to ansible...@googlegroups.com
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.

Matt Hughes

unread,
Nov 25, 2014, 3:15:22 PM11/25/14
to ansible...@googlegroups.com
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.

Nigel Metheringham

unread,
Nov 25, 2014, 4:22:52 PM11/25/14
to ansible...@googlegroups.com


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.
--
[ Nigel Metheringham ------------------------------ ni...@dotdot.it ]
[ Ellipsis Intangible Technologies ]
Reply all
Reply to author
Forward
0 new messages