You rock, figured it had to be something like that but couldn't find any
docs on it.  Thanks!

On Nov 24, 2017 2:30 PM, "Matt Martz" <[email protected]> wrote:

> You have to default at every step, `default` is only applied to the
> deepest level specified, so if `dir` is undefined, you would have to apply
> `default` on `dir` directly too.
>
> Maybe something like:
>
> (dir|default({}))['owner']|default('root')
>
> or making some assumptions that dir will either be defined or not, and
> when defined it will have `owner`:
>
> (dir|default(dict(owner='root')))['owner']
>
> On Fri, Nov 24, 2017 at 1:20 PM, Evan Frey <[email protected]> wrote:
>
>> I am having an issue with the default value not being honored for an
>> undefined dictionary.  For example, if the setup is as follows
>>
>> *- name: something*
>> *  file:*
>> *    path: /somepath*
>> *    owner: "{{ dir['owner'] | default('root') }}"*
>>
>> and I have a variable of
>>
>> *dir:*
>> *  owner: someowner*
>>
>> when I run this, a file called* /somepath *is created with the owner
>> *someowner*, as expected.  However, if the dictionary dir does not
>> exist, I get an error of
>>
>> *"the field 'args' has an invalid value, which appears to include a
>> variable that is undefined.  The error was: 'dir' is undefined*
>>
>> instead of running with the default as I would have expected.  if I
>> flatten the variable structure to be
>>
>> *dir_owner: someowner*
>>
>> and change the task to be
>>
>> *- name: something*
>> *  file:*
>> *    path: /somepath*
>> *    owner: "{{ dir_owner | default('root') }}"*
>>
>> this works as expected.  The owner of the file is either someowner if
>> defined or root if not.
>>
>> --
>> 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/ms
>> gid/ansible-project/47e00d9e-5792-4144-9d3a-895d19b96cc6%
>> 40googlegroups.com
>> <https://groups.google.com/d/msgid/ansible-project/47e00d9e-5792-4144-9d3a-895d19b96cc6%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Matt Martz
> @sivel
> sivel.net
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/ansible-project/dvqxNBcexNc/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAD8N0v_u70Z21fODMUnkAm3NAA9uuVgAJvzYf
> hRZCBJ4ELsdFA%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAD8N0v_u70Z21fODMUnkAm3NAA9uuVgAJvzYfhRZCBJ4ELsdFA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAFH5sTAoieGnHS5J-HBmpAfayWTFco9Cue1CyVp8bK%2BA1O_VYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to