diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index df91d133a07..020ffeb0c74 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -1015,6 +1015,18 @@ ENABLE_TASK_DEBUGGER: ini: - {key: enable_task_debugger, section: defaults} version_added: "2.5" +TASK_DEBUGGER_IGNORE_ERRORS: + name: Whether a failed task with ignore_errors=True will still invoke the debugger + default: True + description: + - This option defines whether the task debugger will be invoked on a failed task when ignore_errors=True + is specified. + - True specifies that the debugger wil honor ignore_errors, False will not honor ignore_errors. + type: boolean + env: [{name: ANSIBLE_TASK_DEBUGGER_IGNORE_ERRORS}] + ini: + - {key: task_debugger_ignore_errors, section: defaults} + version_added: "2.7" DEFAULT_STRATEGY: name: Implied strategy default: 'linear' diff --git a/lib/ansible/executor/task_result.py b/lib/ansible/executor/task_result.py index 40a492d7d8c..8d2eddf803a 100644 --- a/lib/ansible/executor/task_result.py +++ b/lib/ansible/executor/task_result.py @@ -7,6 +7,7 @@ __metaclass__ = type from copy import deepcopy +from ansible import constants as C from ansible.parsing.dataloader import DataLoader from ansible.vars.clean import strip_internal_keys @@ -66,16 +67,17 @@ class TaskResult: def needs_debugger(self, globally_enabled=False): _debugger = self._task_fields.get('debugger') + _ignore_errors = C.TASK_DEBUGGER_IGNORE_ERRORS and self._task_fields.get('ignore_errors') ret = False - if globally_enabled and (self.is_failed() or self.is_unreachable()): + if globally_enabled and ((self.is_failed() and not _ignore_errors) or self.is_unreachable()): ret = True if _debugger in ('always',): ret = True elif _debugger in ('never',): ret = False - elif _debugger in ('on_failed',) and self.is_failed(): + elif _debugger in ('on_failed',) and self.is_failed() and not _ignore_errors: ret = True elif _debugger in ('on_unreachable',) and self.is_unreachable(): ret = True