Discussion:
[ansible-project] when and with on same variable
Alexander Popov
2015-07-15 13:52:22 UTC
Permalink
- debug: msg="test for items" # skip because condition is not
fullfiled
when: groups.unexisting is defined

- debug: msg="test for items"
when: groups.unexisting is defined
with_items: unexisting #failed here with with_items expects a list
or a set
--
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-project+***@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/30e95805-0301-42aa-b7a2-5a1a3ab3b625%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Martin
2015-07-15 14:04:45 UTC
Permalink
- debug: msg="test for items"
when: groups.unexisting is defined
with_items: groups.unexisting #might work if you reference the same
variable?
Post by Alexander Popov
- debug: msg="test for items" # skip because condition is not
fullfiled
when: groups.unexisting is defined
- debug: msg="test for items"
when: groups.unexisting is defined
with_items: unexisting #failed here with with_items expects a list
or a set
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/30e95805-0301-42aa-b7a2-5a1a3ab3b625%40googlegroups.com
<https://groups.google.com/d/msgid/ansible-project/30e95805-0301-42aa-b7a2-5a1a3ab3b625%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
--
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher
Mobil: +43 / 660 / 62 45 103
UID: ATU68801424
--
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-project+***@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/CAK1mKERc0q_-7dK%2BD%3DWEzDSKORLsyrDuGSm1iVGjnbZE_rUmyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Brian Coca
2015-07-15 14:10:54 UTC
Permalink
when gets evaluated INSIDE the with loop, so it cannot condition the
executing of with, this is done so you can do when: item == 'blah' for
example to condition each iteration in the loop.

to deal with undeinfed with_ vars, do the following:

with_ : "{{ myvar|default([])}}"

^ the empty [] will skip the task as there is nothing to loop over.

some times you need more complex conditions, ternary filter can help:

with_ : "{{ unexisting is defined|ternary( groups['unexisting'], []) }}"
--
Brian Coca
--
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-project+***@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%3DSMroeHAGR%3DqfGq8mOK6k4Q-8a6H5phsXja%3DqDRExRPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...