Fix jinja2>=2.9 nested include vars (#35099)

This fixes a bug when parent's local vars where not available in nested
includes. The bug can only be seen with jinja>=2.9 which changes
how the variable scopes work.

Fixes #34886
This commit is contained in:
Martin Krizek 2018-02-07 10:58:29 +01:00 committed by GitHub
commit 63fdc3f08f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 22 deletions

View file

@ -121,4 +121,11 @@ class AnsibleJ2Vars(Mapping):
'''
if locals is None:
return self
return AnsibleJ2Vars(self._templar, self._globals, locals=locals, *self._extras)
# FIXME run this only on jinja2>=2.9?
# prior to version 2.9, locals contained all of the vars and not just the current
# local vars so this was not necessary for locals to propagate down to nested includes
new_locals = self._locals.copy()
new_locals.update(locals)
return AnsibleJ2Vars(self._templar, self._globals, locals=new_locals, *self._extras)