summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMartin Krizek <martin.krizek@gmail.com>2023-05-09 21:26:28 +0200
committerGitHub <noreply@github.com>2023-05-09 14:26:28 -0500
commit4008335f41d0645a544a6fd9031a1f2a19b6f82a (patch)
tree6bbc00ffc4598af139f921685465b12bbf1e778e /lib
parent55b0b6954553392bf43d0ebbd4e2be0f51b02df8 (diff)
downloadansible-4008335f41d0645a544a6fd9031a1f2a19b6f82a.tar.gz
Account for overlays when interacting with Jinja envs (#80705) (#80717)
Instead of using Templar.environment in Templar.do_template for accessing/mutating the environment, myenv local variable should be used because it is the environment used for actual templating. It can either point to Templar.environment or newly created environment overlay. Fixes #80605 (cherry picked from commit 8cd95a8e664ccd634dc3a95642ef7ad41f007169)
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/template/__init__.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py
index 1498d3f813..17bee10489 100644
--- a/lib/ansible/template/__init__.py
+++ b/lib/ansible/template/__init__.py
@@ -970,7 +970,7 @@ class Templar:
# In case this is a recursive call and we set different concat
# function up the stack, reset it in case the value of convert_data
# changed in this call
- self.environment.concat = self.environment.__class__.concat
+ myenv.concat = myenv.__class__.concat
# the concat function is set for each Ansible environment,
# however for convert_data=False we need to use the concat
# function that avoids any evaluation and set it temporarily
@@ -978,13 +978,13 @@ class Templar:
# the concat function is called internally in Jinja,
# most notably for macro execution
if not self.jinja2_native and not convert_data:
- self.environment.concat = ansible_concat
+ myenv.concat = ansible_concat
self.cur_context = t.new_context(jvars, shared=True)
rf = t.root_render_func(self.cur_context)
try:
- res = self.environment.concat(rf)
+ res = myenv.concat(rf)
unsafe = getattr(self.cur_context, 'unsafe', False)
if unsafe:
res = wrap_var(res)
@@ -1012,7 +1012,7 @@ class Templar:
# "Hello world\n!\n" instead of "Hello world!\n".
res_newlines = _count_newlines_from_end(res)
if data_newlines > res_newlines:
- res += self.environment.newline_sequence * (data_newlines - res_newlines)
+ res += myenv.newline_sequence * (data_newlines - res_newlines)
if unsafe:
res = wrap_var(res)
return res