From a3b954e5c96bbdb48241e4d4ed632cb445750461 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Thu, 3 Sep 2020 09:01:34 +0200 Subject: [PATCH] Force template module to use non-native Jinja2 (#68560) Fixes #46169 --- .../46169-non-native-template-module.yml | 2 + .../porting_guide_base_2.11.rst | 2 +- lib/ansible/plugins/action/template.py | 21 ++-- lib/ansible/plugins/lookup/template.py | 43 +++++-- lib/ansible/template/__init__.py | 114 ++++++++++++++---- lib/ansible/template/native_helpers.py | 5 +- lib/ansible/utils/native_jinja.py | 13 ++ lib/ansible/utils/unsafe_proxy.py | 7 ++ .../template_jinja2_non_native/46169.yml | 32 +++++ .../template_jinja2_non_native/aliases | 1 + .../template_jinja2_non_native/runme.sh | 7 ++ .../templates/46169.json.j2 | 3 + 12 files changed, 204 insertions(+), 46 deletions(-) create mode 100644 changelogs/fragments/46169-non-native-template-module.yml create mode 100644 lib/ansible/utils/native_jinja.py create mode 100644 test/integration/targets/template_jinja2_non_native/46169.yml create mode 100644 test/integration/targets/template_jinja2_non_native/aliases create mode 100755 test/integration/targets/template_jinja2_non_native/runme.sh create mode 100644 test/integration/targets/template_jinja2_non_native/templates/46169.json.j2 diff --git a/changelogs/fragments/46169-non-native-template-module.yml b/changelogs/fragments/46169-non-native-template-module.yml new file mode 100644 index 00000000000..7d004a62968 --- /dev/null +++ b/changelogs/fragments/46169-non-native-template-module.yml @@ -0,0 +1,2 @@ +minor_changes: + - Force the template module to use non-native Jinja2 (https://github.com/ansible/ansible/issues/46169) diff --git a/docs/docsite/rst/porting_guides/porting_guide_base_2.11.rst b/docs/docsite/rst/porting_guides/porting_guide_base_2.11.rst index 912e9f6ff0c..e554aa2ab5f 100644 --- a/docs/docsite/rst/porting_guides/porting_guide_base_2.11.rst +++ b/docs/docsite/rst/porting_guides/porting_guide_base_2.11.rst @@ -20,7 +20,7 @@ The complete list of porting guides can be found at :ref:`porting guides =') diff --git a/test/integration/targets/template_jinja2_non_native/aliases b/test/integration/targets/template_jinja2_non_native/aliases new file mode 100644 index 00000000000..b59832142f2 --- /dev/null +++ b/test/integration/targets/template_jinja2_non_native/aliases @@ -0,0 +1 @@ +shippable/posix/group3 diff --git a/test/integration/targets/template_jinja2_non_native/runme.sh b/test/integration/targets/template_jinja2_non_native/runme.sh new file mode 100755 index 00000000000..fe9d495a3eb --- /dev/null +++ b/test/integration/targets/template_jinja2_non_native/runme.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -eux + +export ANSIBLE_JINJA2_NATIVE=1 +ansible-playbook 46169.yml -v "$@" +unset ANSIBLE_JINJA2_NATIVE diff --git a/test/integration/targets/template_jinja2_non_native/templates/46169.json.j2 b/test/integration/targets/template_jinja2_non_native/templates/46169.json.j2 new file mode 100644 index 00000000000..a4fc3f67172 --- /dev/null +++ b/test/integration/targets/template_jinja2_non_native/templates/46169.json.j2 @@ -0,0 +1,3 @@ +{ + "key": "bar" +}