OK, I found a workaround. My task actually is inside a role. Therefore I
was able to define a default value for *some_dict*.
myRole/defaults/main.yml:
some_dict: {}
The condition still is ignored, but with no elements nothing is processed,
obviously.
Is there another solution to this? If this task would not be inside a role
(yes, I know you always should work with roles ;)) I wouldn't be able to
define a default value.
Cheers,
Daniel
Am Montag, 22. September 2014 12:44:54 UTC+2 schrieb Daniel Schroeder:
>
> Hello list,
>
> I'm having a problem with adding a condition before a lookup plugin.
>
> A simplified example that everyone can reproduce is this:
>
> - debug: msg="This debug message should not be triggerd since some_dict
> is not defined"
> when: some_dict is defined
> with_dict: some_dict
>
> That doesn't work because *with_dict* is processed before the condition
> is checked. That's not wrong, that's a good feature, because it enables you
> to do things like this:
>
> - debug: msg="Only process item a"
> when: item == "a"
> with_items:
> - a
> - b
>
> How could I solve my problem with having a condition before the task
> fails, because some_dict is not defined in my first example?
>
> Not even an *ignore_errors: yes* helps in this case. I guess because it
> is a fatal error raised by the plugin and not simply a failed task.
>
> TASK: [debug msg="This debug message should not be triggerd since
> some_dict is not defined"] ***
> fatal: [test1.local] => with_dict expects a dict
>
>
> FATAL: all hosts have already failed -- aborting
>
>
> Thanks,
> Daniel
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5a05fb43-3d59-422c-8b71-209433ace700%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.