Ansible parallell playbooks

74 views
Skip to first unread message

Marcus Karlsson

unread,
Jul 5, 2017, 6:54:11 PM7/5/17
to Ansible Project
Hi,

In my project, where we install Splunk with the help of terraform and ansible, we ran into some "errors" where we had the ansible playbook run on 3 hosts installing a search head in Splunk. On of the tasks were to configure one of these hosts as a captain. In this case, the task was given a list on members of a cluster if the count was 0, otherwise it was given an empty list. The problem was that since there is no garantuee that the playbooks will finish at the same time, that task got excecuted before the other cluster members were up and running (restarting them in some of the tasks). So, our solution was to break out that task into a new playbook (which seams like half arsed solution in a way, but it worked).

Have I missed something in ansible documentation about some task or module that handles this kind of problem? Like a hold_and_wait for condition? 
Is there a way to let playbooks run in parallell with each other, but with a condition to continue if all playbooks reach a specific task and then continue?

I dont know if this was the best explanation of the problem but, ask if there is any uncertanties in what I mean!

Kai Stian Olstad

unread,
Jul 6, 2017, 12:48:47 PM7/6/17
to ansible...@googlegroups.com
On 05. juli 2017 16:20, Marcus Karlsson wrote:
> In my project, where we install Splunk with the help of terraform and
> ansible, we ran into some "errors" where we had the ansible playbook run on
> 3 hosts installing a search head in Splunk.

I'm a bit confused.
Here you describe one playbook with 3 hosts, but you subject has
parallel paybooks, aka more than one playbook.


> On of the tasks were to
> configure one of these hosts as a captain. In this case, the task was given
> a list on members of a cluster if the count was 0, otherwise it was given
> an empty list. The problem was that since there is no garantuee that the
> playbooks will finish at the same time, that task got excecuted before the
> other cluster members were up and running (restarting them in some of the
> tasks). So, our solution was to break out that task into a new playbook
> (which seams like half arsed solution in a way, but it worked).

This is also somewhat confusing I think we need defined what is what.

A playbook is a yaml-file. This playbook can have multiple plays.

playbook.yml
--
- name: This is one play
hosts: all
tasks:
- debug: msg="Test"

- name: This is another play
hosts: all
tasks:
- debug: msg="Test"

This file is one playbook with two plays.

Default Ansible run first task on all the host, when that task is
finished it run the next task on all the hosts....


> Have I missed something in ansible documentation about some task or module
> that handles this kind of problem? Like a hold_and_wait for condition?
> Is there a way to let playbooks run in parallell with each other, but with
> a condition to continue if all playbooks reach a specific task and then
> continue?

Ansible has modules that does wait, but hard to recommend since I don't
understand you problem.


> I dont know if this was the best explanation of the problem but, ask if
> there is any uncertanties in what I mean!

Maybe it's time to show some code that might explain the problem more
easily.

--
Kai Stian Olstad

Marcus Karlsson

unread,
Aug 2, 2017, 2:01:30 PM8/2/17
to Ansible Project, ansible-pr...@olstad.com
I can see how my explanation of my problems seems a bit confusing. I'll try again:

As you said, my title is a bit of as well. We have several playbooks in our setup, but, my problem is only considering ONE playbooks with one role. The play run on more then one host.
One of the tasks in that play, is to only perform action on one of those hosts. We solved that by having a task in the play only perfoming the action and give that host a list of all the hosts if the count was 0, otherwise it would still perform the task but the host got an empty list.

Sadly,I dont have access to that specific code right now since im on a diffrent project. But the problem per say, is that the plays run simultaniously on all hosts but without garantuee on which play on the host will be done first. Since the task is give the host with count 0 a list of all the hosts, the play might fail if the play on that hosts reaches that task before all of the other hosts are done. 

We have done simple solution, but still dirty, where we split that playbook up in to two playbooks, where the second playbook start of with the task of assining the list of the hosts. Since we have to run the first playbook, we can garantuee that the första playbook will be done and the list of hosts exists. So, that is why my question arose: Is there any way to have condition on a tasks in a play, that runs on multiple hosts simultaniously, similar to "stop and wait for the other plays"?

I know that the answer to the question probably is NO, since the play is not aware of each other.

J Hawkesworth

unread,
Aug 14, 2017, 1:09:35 PM8/14/17
to Ansible Project, ansible-pr...@olstad.com
I suppose use you could modify your playbook so that after the task that all the other machines must wait for, ansible creates a file on the controller machine.  Then the next step in the playbook would use wait_for, delegated to the controller so the other machines would have to wait until the file was written before continuing to the next tasks.

Hope this helps,

Jon

Marcus Karlsson

unread,
Nov 1, 2017, 2:25:24 AM11/1/17
to Ansible Project
Took a long time to answer, but that might work. We have now found much better way of working with roles, so the dependency of the task that the playbook need to reach before, has been eliminated. But that does not mead we won't have the problem in the future. Thanks!
Reply all
Reply to author
Forward
0 new messages