summaryrefslogtreecommitdiffstats
path: root/test/integration
diff options
context:
space:
mode:
authorAndrew Gaffney <andrew@agaffney.org>2019-02-12 21:04:00 +0100
committerSam Doran <sdoran@redhat.com>2019-02-12 21:04:00 +0100
commit9c35f18dd6904345f65bad116876964a7a8816c9 (patch)
treec9b6f56716f8fd51f3c20e303d3bf4dac89df41a /test/integration
parentdocs: update docs about pipelining (#51856) (diff)
downloadansible-9c35f18dd6904345f65bad116876964a7a8816c9.tar.xz
ansible-9c35f18dd6904345f65bad116876964a7a8816c9.zip
Custom jinja Undefined class for handling nested undefined attributes (#51768)
This commit creates a custom Jinja2 Undefined class that returns Undefined for any further accesses, rather than raising an exception
Diffstat (limited to 'test/integration')
-rw-r--r--test/integration/targets/template/tasks/main.yml25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/integration/targets/template/tasks/main.yml b/test/integration/targets/template/tasks/main.yml
index 87e2e7d16f..33e985da25 100644
--- a/test/integration/targets/template/tasks/main.yml
+++ b/test/integration/targets/template/tasks/main.yml
@@ -642,5 +642,30 @@
register: encoding_1252_diff_result
loop: '{{ template_encoding_1252_encodings }}'
+- name: Check that nested undefined values return Undefined
+ vars:
+ dict_var:
+ bar: {}
+ list_var:
+ - foo: {}
+ assert:
+ that:
+ - 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'
+
# aliases file requires root for template tests so this should be safe
- include: backup_test.yml