help with conditional inside of a loop

Hi, I think this might be an easy one, but I’m unsure of how to use a loop variable inside of the ‘when’ condition.

Here’s what I thought would work, but ansible complains of a syntax error:
https://gist.github.com/davidbirdsong/5725778

Perhaps there’s another way to create a filtered list using set_facts, which I toyed with here, but no amount of debug showed me a list of mount points:
https://gist.github.com/davidbirdsong/5725936

Here’s the relavent output from setup for one of the nodes:
https://gist.github.com/davidbirdsong/5725944

When you start a YAML line with a “{” it thinks it is a dictionary, so you have to quote the line.

So like:

when: “{{ blarg }}”

When you start a YAML line with a “{” it thinks it is a dictionary, so you have to quote the line.

So like:

when: “{{ blarg }}”

Do you see anything wrong with:
when: “{{ item[‘mount’].endswith(‘da3’) }}”

I get:
fatal: [10.100.1.43] => Conditional expression must evaluate to True or False: {% if {{item[‘mount’].endswith(‘da3’)}} %} True {% else %} False {% endif %}

Right, you can’t do conditionals on with_items, the conditional is there to decide whether to evaluate the task at all or not.

Right, you can’t do conditionals on with_items, the conditional is there to decide whether to evaluate the task at all or not.

Not to be contrary, but I hacked this into working last night. I think the output shows that the debug module was not executed for loop iterations where the when clause returned false, which is what I was hoping to achieve:

https://gist.github.com/davidbirdsong/5733337

I’d love to know if there’s a better way since this is meant to drive a few steps ie.

for each mount point ending in ‘da3’:
create and verify directory under the mount point where the dirname is constructed by ip address + some number (unique id)
verify a symlink originating from the previous directory to another directory

kick off a command to register the directory

i just realized in typing that the loop filter actually needs to be a regex ‘^/export/hd{a-z}3$’ not a simple .endswith.

do i need to write a module or is there another way to do this natively that i’m not seeing?

Hacked this into working means there’s a patch I can look at?

I’m open to it, but be sure to deal with the special casing for the package modules where it uses with_items to produce a single transaction command.

Hacked this into working means there’s a patch I can look at?

No, sorry wrong use of the word hacked; I ‘fiddled’ with the with_items + where to satisfy syntax errors and noticed that a simple debug test showed that items that returned False in the ‘where’ clause were skipped.