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

**URL:** <https://forum.ansible.com/t/how-to-exit-a-sub-playbook-tasks-and-continue-with-the-next-actions-in-the-upper-playbook/13193>\
**Category:** Ansible Project\
**Created:** [July 25, 2013, 12:56pm UTC](https://forum.ansible.com/t/how-to-exit-a-sub-playbook-tasks-and-continue-with-the-next-actions-in-the-upper-playbook/13193 "2013-07-25T12:56:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [July 25, 2013, 12:56pm UTC](https://forum.ansible.com/t/how-to-exit-a-sub-playbook-tasks-and-continue-with-the-next-actions-in-the-upper-playbook/13193/1 "2013-07-25T12:56:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 25, 2013, 2:11pm UTC](https://forum.ansible.com/t/how-to-exit-a-sub-playbook-tasks-and-continue-with-the-next-actions-in-the-upper-playbook/13193/2 "2013-07-25T14:11:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nicolas\_G](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Nicolas\_G](https://forum.ansible.com/u/Nicolas_G)\
**Post date:** [July 25, 2013, 2:32pm UTC](https://forum.ansible.com/t/how-to-exit-a-sub-playbook-tasks-and-continue-with-the-next-actions-in-the-upper-playbook/13193/3 "2013-07-25T14:32:47Z")

</div>

cheers, that’s what Im looking for.
