how to exit a sub-playbook tasks and continue with the next actions in the upper playbook ?

3,043 views
Skip to first unread message

Nicolas G

unread,
Jul 25, 2013, 8:56:02 AM7/25/13
to ansible...@googlegroups.com
Hi list,

I have a small playbook tasks file that is called and run from another main playbook task :

""""""
# roles/application/tasks/main.yml :
.
- include: ../../common/tasks/do_things.yml
.
.
- name: next action
 shell : echo "move to next action"
.



# /common/tasks/do_things.yml :
- name: do this
  shell: echo "do this" >> /root/output.txt creates=/root/output.txt

- name: do that
  shell: echo "do that"
 

- name: and that
  shell: echo "and that"

.
.
.
.
etc...
"""""""

Is it possible to stop the execution of the /common/tasks/do_things.yml if a condition is meet and continue to the next action where the playbook was called ? I know I can register a value and use the WHEN: statement under every tasks but I would like to avoid this as I have many tasks in the do_things.yml to include a WHEN statement on all of them..

Michael DeHaan

unread,
Jul 25, 2013, 10:11:27 AM7/25/13
to ansible...@googlegroups.com
You can attach a "when" statement to a role or include and that when statement will be added along to each task included.

- include: foo.yml
  when: bar == baz

etc

And of course this is also doable with roles.

Note this doesn't include conditionally, it applies the clause to all tasks therein.

That's one way to get this done.

Another way to do it would be to use the group_by module, where you say "this is the group of systems where this is true".

This is more applicable for saying things like "now of the systems in my Webserver group that have this property, let me talk to them together".  



--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



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

Nicolas G

unread,
Jul 25, 2013, 10:32:47 AM7/25/13
to ansible...@googlegroups.com
cheers, that's what Im looking for.
Reply all
Reply to author
Forward
0 new messages