You can specify default values for both the dictionary in which you are 
trying to look something up, and the key you are looking up:

  with_dict: *(file_system_system_vg|default({})).lv|default({})*

The parentheses are important!


On Wednesday, August 12, 2015 at 5:54:12 PM UTC+2, Patrick McMahon wrote:
>
> I made a simple playbook to show the issue. It seems ansible evalutes all 
> variables regardless of the conditional result before ternary.
> If you run the playbook twice, once with "simpleDict" defined, and again 
> with it commented out. 
>
> ---
> #TESTING: ternary behaviour
> - name: Run - Testing ternary
>   sudo: yes
>   hosts: "{{hosts}}"
>   gather_facts: no
>
>   vars:
>     simpleDict:
>     #  name: 'A simple dictionary'
>     #  nestedDict: {}
>
>   tasks:
>     - set_fact: foo="{{ simpleDict is defined | 
> ternary(simpleDict.nestedDict|default({}),"simpleDict not defined") }}"
>
>     - debug: var=foo
>
> Thanks
> Patrick
>

-- 
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/33f0fcf0-0ade-44c2-8cc0-86149e3a8302%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to