Looking for a way execute tasks in included file based on condition

22 views
Skip to first unread message

Joseph Djomeda

unread,
Sep 2, 2015, 2:38:40 PM9/2/15
to Ansible Project
Hello Guys,

This has been probably solved before so apologies if this is a repeat. I was confused about tasks in a include file being run even though the condition for the include itself is not true.

so in my main.yml I have an include system like a switch kind of logique: say

- include: this.yml
  when: include_this_enable|default(false)

- include: that.yml
  when: include_that_enable|default(false)

To my surprise I needed to also add the when conditions to this.yml and that.yml for it to work before everything would run otherwise as shown in here http://pastie.org/10392488

when this.yml has a lot of tasks this become difficult to do. How to strictly run tasks in this.yml only base on a condition?

Thanks in advance

Best Regads,
--
Joseph Kodjo-Kuma Djomeda
check out my pains at : www.mycodingpains.com
We become what we think about ourselves........

Brian Coca

unread,
Sep 2, 2015, 4:42:34 PM9/2/15
to Ansible Project
The when conditions will not avoid issues with a undefined or
incorrectly typed var in a with_ , as they get executed for each item
inside the with_.



--
Brian Coca

Joseph Djomeda

unread,
Sep 2, 2015, 5:15:54 PM9/2/15
to Ansible Project
Hello Brian,

Thanks for the email. So there is no way to skip the inclusion of the file in the first place?

Best Regards,

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJ5XC8%3DvBEXox7J5MbAXDUwsNjHCeixskay0P7oETW2QAPu1BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages