mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 05:42:50 +00:00
better cleanup on task results display (#27175)
* better cleanup on task results display callbacks get 'clean' copy of result objects moved cleanup into result object itself removed now redundant callback cleanup moved no_log tests * moved import as per feedback
This commit is contained in:
@@ -27,6 +27,7 @@ from ansible import constants as C
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.executor.play_iterator import PlayIterator
|
||||
from ansible.executor.stats import AggregateStats
|
||||
from ansible.executor.task_result import TaskResult
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.playbook.block import Block
|
||||
@@ -371,9 +372,20 @@ class TaskQueueManager:
|
||||
if gotit is not None:
|
||||
methods.append(gotit)
|
||||
|
||||
# send clean copies
|
||||
new_args = []
|
||||
for arg in args:
|
||||
# FIXME: add play/task cleaners
|
||||
if isinstance(arg, TaskResult):
|
||||
new_args.append(arg.clean_copy())
|
||||
# elif isinstance(arg, Play):
|
||||
# elif isinstance(arg, Task):
|
||||
else:
|
||||
new_args.append(arg)
|
||||
|
||||
for method in methods:
|
||||
try:
|
||||
method(*args, **kwargs)
|
||||
method(*new_args, **kwargs)
|
||||
except Exception as e:
|
||||
# TODO: add config toggle to make this fatal or not?
|
||||
display.warning(u"Failure using method (%s) in callback plugin (%s): %s" % (to_text(method_name), to_text(callback_plugin), to_text(e)))
|
||||
|
||||
@@ -5,7 +5,12 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
from ansible.parsing.dataloader import DataLoader
|
||||
from ansible.vars.manager import strip_internal_keys
|
||||
|
||||
_IGNORE = ('changed', 'failed', 'skipped')
|
||||
|
||||
|
||||
class TaskResult:
|
||||
@@ -69,3 +74,32 @@ class TaskResult:
|
||||
if isinstance(res, dict):
|
||||
flag |= res.get(key, False)
|
||||
return flag
|
||||
|
||||
def clean_copy(self):
|
||||
|
||||
''' returns 'clean' taskresult object '''
|
||||
|
||||
# FIXME: clean task_fields, _task and _host copies
|
||||
result = TaskResult(self._host, self._task, {}, self._task_fields)
|
||||
|
||||
# statuses are already reflected on the event type
|
||||
if result._task and result._task.action in ['debug']:
|
||||
# debug is verbose by default to display vars, no need to add invocation
|
||||
ignore = _IGNORE + ('invocation',)
|
||||
else:
|
||||
ignore = _IGNORE
|
||||
|
||||
if self._result.get('_ansible_no_log', False):
|
||||
result._result = {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result"}
|
||||
elif self._result:
|
||||
result._result = deepcopy(self._result)
|
||||
|
||||
# actualy remove
|
||||
for remove_key in ignore:
|
||||
if remove_key in result._result:
|
||||
del result._result[remove_key]
|
||||
|
||||
# remove almost ALL internal keys, keep ones relevant to callback
|
||||
strip_internal_keys(result._result, exceptions=('_ansible_verbose_always', '_ansible_item_label', '_ansible_no_log'))
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user