mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-31 21:39:10 -07:00
parent
02c9f70898
commit
50d7483632
3 changed files with 42 additions and 0 deletions
|
@ -12,6 +12,7 @@ import types
|
|||
|
||||
from jinja2._compat import text_type
|
||||
|
||||
from jinja2.runtime import StrictUndefined
|
||||
from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode
|
||||
|
||||
|
||||
|
@ -37,6 +38,17 @@ def ansible_native_concat(nodes):
|
|||
if isinstance(out, AnsibleVaultEncryptedUnicode):
|
||||
return out.data
|
||||
|
||||
if isinstance(out, StrictUndefined):
|
||||
# A hack to raise proper UndefinedError/AnsibleUndefinedVariable exception.
|
||||
# We need to access the AnsibleUndefined(StrictUndefined) object by either of the following:
|
||||
# __iter__, __str__, __len__, __nonzero__, __eq__, __ne__, __bool__, __hash__
|
||||
# to actually raise the exception.
|
||||
# (see Jinja2 source of StrictUndefined to get up to date info)
|
||||
# Otherwise the undefined error would be raised on the next access which might not be properly handled.
|
||||
# See https://github.com/ansible/ansible/issues/52158
|
||||
# We do that only here because it is taken care of by text_type() in the else block below already.
|
||||
str(out)
|
||||
|
||||
# short circuit literal_eval when possible
|
||||
if not isinstance(out, list):
|
||||
return out
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue