From 6af5693dc2fd17d8035a25bd86c0a3130a40966a Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 20 Feb 2018 08:41:18 -0500 Subject: [PATCH] hide uneeded fields for callbacks (#36259) * hide uneeded fields for callbacks fix selective instead of pushing uneeded fields to the methods * piipii --- lib/ansible/executor/task_result.py | 4 ++-- lib/ansible/plugins/callback/selective.py | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/ansible/executor/task_result.py b/lib/ansible/executor/task_result.py index 9b295cc8a5..40a492d7d8 100644 --- a/lib/ansible/executor/task_result.py +++ b/lib/ansible/executor/task_result.py @@ -10,8 +10,8 @@ from copy import deepcopy from ansible.parsing.dataloader import DataLoader from ansible.vars.clean import strip_internal_keys -_IGNORE = tuple() -_PRESERVE = ('attempts', 'changed', 'retries', 'failed', 'unreachable', 'skipped') +_IGNORE = ('failed', 'skipped') +_PRESERVE = ('attempts', 'changed', 'retries') class TaskResult: diff --git a/lib/ansible/plugins/callback/selective.py b/lib/ansible/plugins/callback/selective.py index 1c015fe5af..3535a46030 100644 --- a/lib/ansible/plugins/callback/selective.py +++ b/lib/ansible/plugins/callback/selective.py @@ -178,13 +178,10 @@ class CallbackModule(CallbackBase): self.last_task_name = task.get_name() self.printed_last_task = False - def v2_runner_on_ok(self, result, **kwargs): + def _print_task_result(self, result, error=False, **kwargs): """Run when a task finishes correctly.""" - failed = result._result.get("failed") - unreachable = result._result.get("unreachable") - if 'print_action' in result._task.tags or failed or unreachable or \ - self._display.verbosity > 1: + if 'print_action' in result._task.tags or error or self._display.verbosity > 1: self._print_task() self.last_skipped = False msg = to_text(result._result.get('msg', '')) or\ @@ -199,7 +196,7 @@ class CallbackModule(CallbackBase): msg, result._result.get('diff', None), is_host=True, - error=failed or unreachable, + error=error, stdout=result._result.get('module_stdout', None), stderr=stderr.strip(), ) @@ -267,6 +264,13 @@ class CallbackModule(CallbackBase): print(self._indent_text(reason, 8)) print(reason) + def v2_runner_on_ok(self, result, **kwargs): + self._print_task_result(result, error=False, **kwargs) + + def v2_runner_on_failed(self, result, **kwargs): + self._print_task_result(result, error=True, **kwargs) + + def v2_runner_on_unreachable(self, result, **kwargs): + self._print_task_result(result, error=True, **kwargs) + v2_playbook_on_handler_task_start = v2_playbook_on_task_start - v2_runner_on_failed = v2_runner_on_ok - v2_runner_on_unreachable = v2_runner_on_ok