From cf4a9fcd0f18d384dbad035bcc418da9cfdec1e1 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Thu, 15 Apr 2021 15:52:08 -0500 Subject: [PATCH] Prevent traceback when task depth exceeds python recursion depth (#73999) --- changelogs/fragments/73996-recursion-depth.yml | 3 +++ lib/ansible/playbook/base.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/73996-recursion-depth.yml diff --git a/changelogs/fragments/73996-recursion-depth.yml b/changelogs/fragments/73996-recursion-depth.yml new file mode 100644 index 00000000000..35af5aa534e --- /dev/null +++ b/changelogs/fragments/73996-recursion-depth.yml @@ -0,0 +1,3 @@ +bugfixes: +- Task depth - Prevent exception when the task depth exceeds Pythons recursion depth + (https://github.com/ansible/ansible/issues/73996) diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index 5fc050895f4..9fa84d14730 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -15,6 +15,7 @@ from jinja2.exceptions import UndefinedError from ansible import constants as C from ansible import context +from ansible.errors import AnsibleError from ansible.module_utils.six import iteritems, string_types, with_metaclass from ansible.module_utils.parsing.convert_bool import boolean from ansible.errors import AnsibleParserError, AnsibleUndefinedVariable, AnsibleAssertionError @@ -315,7 +316,10 @@ class FieldAttributeBase(with_metaclass(BaseMeta, object)): Create a copy of this object and return it. ''' - new_me = self.__class__() + try: + new_me = self.__class__() + except RuntimeError as e: + raise AnsibleError("Exceeded maximum object depth. This may have been caused by excessive role recursion", orig_exc=e) for name in self._valid_attrs.keys(): if name in self._alias_attrs: