From 079318bf4a36f0dd151bd209f3de04b6988584d4 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Thu, 31 May 2018 10:14:26 -0500 Subject: [PATCH] Honor ignore_errors when invoking the debugger, add config to disable this behavior (#39868) * Honor ignore_errors when invoking the debugger, add config to disable this behavior. Fixes #39863 * Limit ignore_errors logic to failed --- lib/ansible/config/base.yml | 12 ++++++++++++ lib/ansible/executor/task_result.py | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index df91d133a0..020ffeb0c7 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 40a492d7d8..8d2eddf803 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