This is the expected behavior, and ChainableUndefined doesn't change that.
`AnsibleUndefined` inherits from `StrictUndefined`, and in the end, you
cannot simply loop over undefined values. Both ChainableUndefined and
AnsibleUndefined allow something like this to work:
foo.bar.baz|default('qux')
Where `foo` is undefined. Prior to this you needed to insert `|default` at
every level, instead of just at the end.
On Tue, Jul 14, 2020 at 3:16 PM Baeschtu <[email protected]> wrote:
> Thanks for this reply. To simplify tests for existing variables I now use
> builtin jinja2 filter "*default()*" such as "*{% for person in persons |
> default('') %}*" to do not first have to test if the variable "*persons*"
> is defined. If I remove the part "* | default('')*" from the for-loop and
> the variable is not defined ansible will raise an error.
>
> Matt Martz schrieb am Montag, 13. Juli 2020 um 15:57:53 UTC+2:
>
>> Ansible actually has a feature that predates the jinja2 change that works
>> exactly the same. We already have an AnsibleUndefined that performs the
>> exact same functionality:
>> https://github.com/ansible/ansible/blob/devel/lib/ansible/template/__init__.py#L274
>>
>> This functionality has been in place since Ansible 2.8.
>>
>> Due to the above, you need to do nothing, and you already get this
>> functionality in Ansible
>>
>> On Sun, Jul 12, 2020 at 4:43 AM Baeschtu <[email protected]> wrote:
>>
>>> According to the release notes of Jinja2 Version 2.11.0 (released on
>>> 2020-01-27) there is a new class named "ChainableUndefined" to handle
>>> undefined variables on multiple levels in Jinja2 templates. Currently, I
>>> use a ansible task using the module "template" to render jinja2 templates.
>>> However, I don't know how to pass this new "ChainableUndefined" class to
>>> the parameter "undefined" in the Jinja2 environment via the ansible module.
>>>
>>> Does anyone know how to set the parameter "undefined" to
>>> ChainableUndefined through the ansible "template" module?
>>> Does the module "template" only support the "StrictUndefined" class,
>>> currently?
>>>
>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/55390a3d-6fe7-40f4-8fcb-c8b9a4fa4a88o%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/55390a3d-6fe7-40f4-8fcb-c8b9a4fa4a88o%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>> Matt Martz
>> @sivel
>> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/aa025896-9f90-4ccd-88d0-b59103baaa36n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/aa025896-9f90-4ccd-88d0-b59103baaa36n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
Matt Martz
@sivel
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAD8N0v-4%2BAUAnE6GSdzPNjmgDEK7rCQ6i6xS-to9njQ-ZfFE7Q%40mail.gmail.com.