mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 06:31:23 -07: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:
parent
03abce2d39
commit
01b6c7c9c6
6 changed files with 64 additions and 19 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue