mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Extend jinja2 nested undefined support to keys/indices (#55094)
This commit is contained in:
parent
877ce12970
commit
e89f8bae86
3 changed files with 24 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- jinja2 - accesses to keys/indices on an undefined value now return further undefined values rather than throwing an exception
|
|
@ -207,6 +207,10 @@ class AnsibleUndefined(StrictUndefined):
|
||||||
# Return original Undefined object to preserve the first failure context
|
# Return original Undefined object to preserve the first failure context
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
# Return original Undefined object to preserve the first failure context
|
||||||
|
return self
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'AnsibleUndefined'
|
return 'AnsibleUndefined'
|
||||||
|
|
||||||
|
|
|
@ -666,6 +666,24 @@
|
||||||
- list_var.0.foo.bar | default('DEFAULT') == 'DEFAULT'
|
- list_var.0.foo.bar | default('DEFAULT') == 'DEFAULT'
|
||||||
- list_var.1.foo is not defined
|
- list_var.1.foo is not defined
|
||||||
- list_var.1.foo | default('DEFAULT') == 'DEFAULT'
|
- list_var.1.foo | default('DEFAULT') == 'DEFAULT'
|
||||||
|
- dict_var is defined
|
||||||
|
- dict_var['bar'] is defined
|
||||||
|
- dict_var['bar']['baz'] is not defined
|
||||||
|
- dict_var['bar']['baz'] | default('DEFAULT') == 'DEFAULT'
|
||||||
|
- dict_var['bar']['baz']['abc'] is not defined
|
||||||
|
- dict_var['bar']['baz']['abc'] | default('DEFAULT') == 'DEFAULT'
|
||||||
|
- dict_var['baz'] is not defined
|
||||||
|
- dict_var['baz']['abc'] is not defined
|
||||||
|
- dict_var['baz']['abc'] | default('DEFAULT') == 'DEFAULT'
|
||||||
|
- list_var[0] is defined
|
||||||
|
- list_var[1] is not defined
|
||||||
|
- list_var[0]['foo'] is defined
|
||||||
|
- list_var[0]['foo']['bar'] is not defined
|
||||||
|
- list_var[0]['foo']['bar'] | default('DEFAULT') == 'DEFAULT'
|
||||||
|
- list_var[1]['foo'] is not defined
|
||||||
|
- list_var[1]['foo'] | default('DEFAULT') == 'DEFAULT'
|
||||||
|
- dict_var['bar'].baz is not defined
|
||||||
|
- dict_var['bar'].baz | default('DEFAULT') == 'DEFAULT'
|
||||||
|
|
||||||
- template:
|
- template:
|
||||||
src: template_destpath_test.j2
|
src: template_destpath_test.j2
|
||||||
|
|
Loading…
Reference in a new issue