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: