jinja2_native behavior

73 views
Skip to first unread message

Rowe, Walter P. (Fed)

unread,
Mar 4, 2024, 12:59:02 PM3/4/24
to Ansible Project
Is this expected behavior?


% ANSIBLE_JINJA2_NATIVE=true ansible -i localhost, localhost -m debug -a var=this -e "this='None'"

localhost | SUCCESS => {

    "this": null

}


% ANSIBLE_JINJA2_NATIVE=false ansible -i localhost, localhost -m debug -a var=this -e "this='None'"

localhost | SUCCESS => {

    "this": "None"

}


Just making sure that jinja2_native=True should convert a string value of "None" to value null when evaluated.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services Division
Mobile: 202.355.4123

Matt Martz

unread,
Mar 4, 2024, 1:17:18 PM3/4/24
to ansible...@googlegroups.com
As of now, yes.  Non-native jinja only runs things that look like a `list`, `dict`, `set`, `bool` through `ast.literal_eval`, leaving everything else as a `str`.  Native sends everything through `ast.literal_eval`.

If instead you used `-e "this='[None]'"` you would notice that it becomes `[null]` on both, due to it appearing as a list.

However, this may be changing in 2.17 or 2.18, as changes are being made to how native jinja works, by making it native through the whole jinja process.  As such, it would leave the string 'None' as a string.  Also, non-native will go away at that point, since it will more closely act like most expect.

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2BA2FDC8-1CA3-4C93-B702-FA5F0B77248B%40nist.gov.


--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages