From 419766617956440512f8c32d2fd278fae9799c1e Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 30 Sep 2020 09:15:28 +0200 Subject: [PATCH] Only apply the unroll wrapper once (#72003) Co-authored-by: Matt Martz Fixes #71920 --- changelogs/fragments/71920-fix-templating-recursion-error.yml | 2 ++ lib/ansible/template/__init__.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/71920-fix-templating-recursion-error.yml diff --git a/changelogs/fragments/71920-fix-templating-recursion-error.yml b/changelogs/fragments/71920-fix-templating-recursion-error.yml new file mode 100644 index 00000000000..b7ee60af993 --- /dev/null +++ b/changelogs/fragments/71920-fix-templating-recursion-error.yml @@ -0,0 +1,2 @@ +bugfixes: + - Fix ``RecursionError`` when templating large vars structures (https://github.com/ansible/ansible/issues/71920) diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index bfc02514081..a5392d708fb 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -257,6 +257,7 @@ def _unroll_iterator(func): return list(ret) return ret + wrapper.__UNROLLED__ = True return _update_wrapper(wrapper, func) @@ -1086,7 +1087,8 @@ class Templar: # Adds Ansible custom filters and tests myenv.filters.update(self._get_filters()) for k in myenv.filters: - myenv.filters[k] = _unroll_iterator(myenv.filters[k]) + if not getattr(myenv.filters[k], '__UNROLLED__', False): + myenv.filters[k] = _unroll_iterator(myenv.filters[k]) myenv.tests.update(self._get_tests()) if escape_backslashes: