It works best to use standard hash key access such as:
foo['bar']['baz']|default('qux')
Jinja2 seems to be able to handle it better.
On Thursday, April 24, 2014, Kesten Broughton <[email protected]>
wrote:
>
> I have the need to template a yaml file using vars in another yaml file as
> input. There are often defaults.
>
> I'd like to do this
>
> in vars.yml
> parentvar:
> childvar:
> subvar1: val1
> # subvar2 is not even listed to keep user vars.yml file concise
>
> template.yml
> {{ parentvar.childvar.subvar1 }}
> {{ parentvar.childvar.subvar2 | default("default for subvar2") }}
>
> This fails with "dict object has no attribute 'subvar2'
>
> It would work fine if i had
> vars.yml
> parentvar_childvar_subvar1: val1
>
> and template.yml
> {{ parentvar_childvar_subvar1 }}
> {{ parentvar_childvar_subvar2 | default("default for subvar2") }}
>
> I presume this is a problem at the jinja2 level?
>
> I would like to avoid the '_' flattened solution as it becomes pretty
> unreadable for large config files.
> Any suggestions on how to work around this?
>
> thanks
>
> Kesten Broughton
> 512 701 4209
>
> --
> 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]<javascript:_e(%7B%7D,'cvml','ansible-project%[email protected]');>
> .
> To post to this group, send email to
> [email protected]<javascript:_e(%7B%7D,'cvml','[email protected]');>
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAO2fFsVRHaaqdZrJ2idE_JUR2HDOkcbuxP%3DjqkDUecBda%3DsbRA%40mail.gmail.com<https://groups.google.com/d/msgid/ansible-project/CAO2fFsVRHaaqdZrJ2idE_JUR2HDOkcbuxP%3DjqkDUecBda%3DsbRA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
Matt Martz
[email protected]
http://sivel.net/
--
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/CAD8N0v99ebqiq8cHWOH3UAUamupmdqmGY83yKuwNZLti56gDhQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.