mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Implement invocation hiding for all callbacks if the verbosity is low
This commit is contained in:
parent
275764d4a5
commit
3812ec8d1d
2 changed files with 22 additions and 20 deletions
|
@ -48,19 +48,28 @@ class CallbackBase:
|
|||
version = getattr(self, 'CALLBACK_VERSION', '1.0')
|
||||
self._display.vvvv('Loaded callback %s of type %s, v%s' % (name, ctype, version))
|
||||
|
||||
def _dump_results(self, result, indent=None, sort_keys=True):
|
||||
|
||||
no_log = result.get('_ansible_no_log', False):
|
||||
if no_log:
|
||||
def _dump_results(self, result, indent=None, sort_keys=True, keep_invocation=None):
|
||||
if result.get('_ansible_no_log', False):
|
||||
return json.dumps(dict(censored="the output has been hidden due to the fact that 'no_log: true' was specified for this result"))
|
||||
|
||||
if not indent and '_ansible_verbose_always' in result and result['_ansible_verbose_always']:
|
||||
indent = 4
|
||||
|
||||
# All result keys stating with _ansible_ are internal, so remove them from the result before we output anything.
|
||||
for k in result.keys():
|
||||
abridged_result = result.copy()
|
||||
for k in abridged_result.keys():
|
||||
if isinstance(k, string_types) and k.startswith('_ansible_'):
|
||||
del result[k]
|
||||
del abridged_result[k]
|
||||
|
||||
# Remove invocation unless verbosity is turned up or the specific
|
||||
# callback wants to keep it
|
||||
if keep_invocation is None:
|
||||
if self._display.verbosity < 3:
|
||||
keep_invocation = False
|
||||
else:
|
||||
keep_invocation = True
|
||||
if not keep_invocation and 'invocation' in result:
|
||||
del abridged_result['invocation']
|
||||
|
||||
# remove invocation info unless its very very verbose
|
||||
if 'invocation' in result and (self._display.verbosity < 3 or no_log):
|
||||
|
@ -222,7 +231,7 @@ class CallbackBase:
|
|||
def v2_runner_on_async_poll(self, result):
|
||||
host = result._host.get_name()
|
||||
jid = result._result.get('ansible_job_id')
|
||||
#FIXME, get real clock
|
||||
#FIXME, get real clock
|
||||
clock = 0
|
||||
self.runner_on_async_poll(host, result._result, jid, clock)
|
||||
|
||||
|
@ -297,4 +306,3 @@ class CallbackBase:
|
|||
|
||||
def v2_playbook_on_include(self, included_file):
|
||||
pass #no v1 correspondance
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class CallbackModule(CallbackBase):
|
|||
CALLBACK_TYPE = 'stdout'
|
||||
CALLBACK_NAME = 'minimal'
|
||||
|
||||
def _command_generic_msg(self, host, result, caption):
|
||||
def _command_generic_msg(self, host, result, caption):
|
||||
''' output the result of a command run '''
|
||||
|
||||
buf = "%s | %s | rc=%s >>\n" % (host, caption, result.get('rc',0))
|
||||
|
@ -59,28 +59,22 @@ class CallbackModule(CallbackBase):
|
|||
del result._result['exception']
|
||||
|
||||
if result._task.action in C.MODULE_NO_JSON:
|
||||
self._display.display(self._command_generic_msg(result._host.get_name(), result._result,"FAILED"), color='red')
|
||||
self._display.display(self._command_generic_msg(result._host.get_name(), result._result, "FAILED"), color='red')
|
||||
else:
|
||||
abridged_result = result._result.copy()
|
||||
abridged_result.pop('invocation', None)
|
||||
self._display.display("%s | FAILED! => %s" % (result._host.get_name(), self._dump_results(abridged_result, indent=4)), color='red')
|
||||
self._display.display("%s | FAILED! => %s" % (result._host.get_name(), self._dump_results(result._result, indent=4)), color='red')
|
||||
|
||||
def v2_runner_on_ok(self, result):
|
||||
if result._task.action in C.MODULE_NO_JSON:
|
||||
self._display.display(self._command_generic_msg(result._host.get_name(), result._result,"SUCCESS"), color='green')
|
||||
self._display.display(self._command_generic_msg(result._host.get_name(), result._result, "SUCCESS"), color='green')
|
||||
else:
|
||||
abridged_result = result._result.copy()
|
||||
abridged_result.pop('invocation', None)
|
||||
self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(abridged_result, indent=4)), color='green')
|
||||
self._display.display("%s | SUCCESS => %s" % (result._host.get_name(), self._dump_results(result._result, indent=4)), color='green')
|
||||
self._handle_warnings(result._result)
|
||||
|
||||
def v2_runner_on_skipped(self, result):
|
||||
self._display.display("%s | SKIPPED" % (result._host.get_name()), color='cyan')
|
||||
|
||||
def v2_runner_on_unreachable(self, result):
|
||||
abridged_result = result._result.copy()
|
||||
abridged_result.pop('invocation', None)
|
||||
self._display.display("%s | UNREACHABLE! => %s" % (result._host.get_name(), self._dump_results(abridged_result, indent=4)), color='yellow')
|
||||
self._display.display("%s | UNREACHABLE! => %s" % (result._host.get_name(), self._dump_results(result._result, indent=4)), color='yellow')
|
||||
|
||||
def v2_on_file_diff(self, result):
|
||||
if 'diff' in result._result and result._result['diff']:
|
||||
|
|
Loading…
Reference in a new issue