Any way to make a task serial (or set mutex so only 1 thread run it at a time)?

1,286 views
Skip to first unread message

Mike Sop

unread,
Jan 23, 2014, 6:53:50 PM1/23/14
to ansible...@googlegroups.com
Came across another ticket describing a change to make a "playbook" serial (I'm guessing that means all tasks in the playbook): https://groups.google.com/forum/#!searchin/ansible-project/task$20serial/ansible-project/ZrSuwsqv1m8/-o-bJTQuJnUJ

would like to have more granular control and just specify particular task(s) as serial, is that possible?  Perhaps the intended way of doing this is to create a new playbook for those particular tasks?  Seems like overkill but am willing to give it a shot (beats having to run ALL my tasks with forks 1 or serial 1)

Michael DeHaan

unread,
Jan 23, 2014, 8:06:38 PM1/23/14
to ansible...@googlegroups.com
That's a pretty old post.

You should read up on the "serial:" keyword in Ansible.


serial: 1


On Thu, Jan 23, 2014 at 6:53 PM, Mike Sop <michael...@gmail.com> wrote:
Came across another ticket describing a change to make a "playbook" serial (I'm guessing that means all tasks in the playbook): https://groups.google.com/forum/#!searchin/ansible-project/task$20serial/ansible-project/ZrSuwsqv1m8/-o-bJTQuJnUJ

would like to have more granular control and just specify particular task(s) as serial, is that possible?  Perhaps the intended way of doing this is to create a new playbook for those particular tasks?  Seems like overkill but am willing to give it a shot (beats having to run ALL my tasks with forks 1 or serial 1)

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Khaled Janania

unread,
Apr 4, 2014, 1:39:25 PM4/4/14
to ansible...@googlegroups.com
The documentation doesn't really answer the question though.  Does that mean there's no way to define one task as serial?  In other words, serial only applies for all tasks?

Paul Durivage

unread,
Apr 6, 2014, 11:10:58 AM4/6/14
to ansible...@googlegroups.com
Correct, a task does not allow the keyword serial to be defined on it.  There's no need to define an entirely new playbook, but you will have to declare a new play.


Michael DeHaan

unread,
Apr 9, 2014, 9:33:11 AM4/9/14
to ansible...@googlegroups.com
Yes, the play could just have one task in it.

A serial task in the middle of several non-serial ones would look like this in a single playbook file.

- hosts: webservers
  tasks:
    -
    -
    -

- hosts: webservers
  serial: 1
  tasks:
   -
 
- hosts: webservers




Roman Belyakovsky

unread,
May 20, 2015, 8:41:01 AM5/20/15
to ansible...@googlegroups.com
Looks like it's going to be possible in v2.0.

Move tasks that should be done in 'serial: 1' mode to a separate file. Include it with items iterating over hosts in a group and set some variable to a host name. Add to files in a separate task condition to check if hostname is similar to that variable.
Reply all
Reply to author
Forward
0 new messages