diff options
author | Martin Krizek <martin.krizek@gmail.com> | 2022-08-03 18:58:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-03 09:58:19 -0700 |
commit | 2aa3cc9e40f46aa9071060052a68c2e82605a9e4 (patch) | |
tree | 18f380bb4fee994466e11e85cf15b390b4849fb4 /test/integration/targets | |
parent | bf1e031eb23256ffedddeba17cb3afa11476a6ae (diff) | |
download | ansible-2aa3cc9e40f46aa9071060052a68c2e82605a9e4.tar.gz |
2.13: template module/lookup: fix convert_data for macros (#78259) (#78269)
* template module/lookup: fix convert_data for macros (#78259)
Fixes #78141
(cherry picked from commit 9afdb7fec199c16b33d356ef8c6ab2a1ef812323)
* Fix templating nested vars with convert_data=False (#78273)
Regression introduced in #78259.
(cherry picked from commit d070b03ad89d6384f26314c53098bf006f703a3f)
Diffstat (limited to 'test/integration/targets')
3 files changed, 19 insertions, 0 deletions
diff --git a/test/integration/targets/template/tasks/main.yml b/test/integration/targets/template/tasks/main.yml index e8a2b9a82a..04919f1830 100644 --- a/test/integration/targets/template/tasks/main.yml +++ b/test/integration/targets/template/tasks/main.yml @@ -761,3 +761,19 @@ - test vars: test: "{{ lookup('file', '{{ output_dir }}/empty_template.templated')|length == 0 }}" + +- assert: + that: + - data_not_converted | type_debug == 'NativeJinjaUnsafeText' + - data_converted | type_debug == 'dict' + vars: + data_not_converted: "{{ lookup('template', 'json_macro.j2', convert_data=False) }}" + data_converted: "{{ lookup('template', 'json_macro.j2') }}" + +- name: Test convert_data is correctly set to True for nested vars evaluation + debug: + msg: "{{ lookup('template', 'indirect_dict.j2', convert_data=False) }}" + vars: + d: + foo: bar + v: "{{ d }}" diff --git a/test/integration/targets/template/templates/indirect_dict.j2 b/test/integration/targets/template/templates/indirect_dict.j2 new file mode 100644 index 0000000000..3124371f48 --- /dev/null +++ b/test/integration/targets/template/templates/indirect_dict.j2 @@ -0,0 +1 @@ +{{ v.foo }} diff --git a/test/integration/targets/template/templates/json_macro.j2 b/test/integration/targets/template/templates/json_macro.j2 new file mode 100644 index 0000000000..080f164876 --- /dev/null +++ b/test/integration/targets/template/templates/json_macro.j2 @@ -0,0 +1,2 @@ +{% macro m() %}{{ {"foo":"bar"} }}{% endmacro %} +{{ m() }} |