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

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…

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

cheers, that’s what Im looking for.