diff --git a/changelogs/fragments/67429-jinja2-caching.yml b/changelogs/fragments/67429-jinja2-caching.yml new file mode 100644 index 00000000000..cd081050855 --- /dev/null +++ b/changelogs/fragments/67429-jinja2-caching.yml @@ -0,0 +1,2 @@ +bugfixes: +- "Templating - Ansible was caching results of Jinja2 expressions in some cases where these expressions could have dynamic results, like password generation (https://github.com/ansible/ansible/issues/34144)." diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index d3c57276f0b..54b84b670eb 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -596,7 +596,7 @@ class Templar: # we only cache in the case where we have a single variable # name, to make sure we're not putting things which may otherwise # be dynamic in the cache (filters, lookups, etc.) - if cache: + if cache and only_one: self._cached_result[sha1_hash] = result return result