simplified invocation removal, added no_log awareness

This commit is contained in:
Brian Coca 2015-10-30 10:16:49 -04:00
parent 9f9655d3db
commit b97887ba41

View file

@ -49,25 +49,22 @@ class CallbackBase:
version = getattr(self, 'CALLBACK_VERSION', '1.0') version = getattr(self, 'CALLBACK_VERSION', '1.0')
self._display.vvvv('Loaded callback %s of type %s, v%s' % (name, ctype, version)) self._display.vvvv('Loaded callback %s of type %s, v%s' % (name, ctype, version))
def _dump_results(self, result, indent=None, sort_keys=True, keep_invocation=None): def _dump_results(self, result, indent=None, sort_keys=True, keep_invocation=False):
if result.get('_ansible_no_log', False): 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")) 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']: if not indent and '_ansible_verbose_always' in result and result['_ansible_verbose_always']:
indent = 4 indent = 4
# no_log trumps invocation
if '_ansible_no_log' in result and result['_ansible_no_log']:
keep_invocation = False
# All result keys stating with _ansible_ are internal, so remove them from the result before we output anything. # All result keys stating with _ansible_ are internal, so remove them from the result before we output anything.
abridged_result = strip_internal_keys(result) abridged_result = strip_internal_keys(result)
# Remove invocation unless verbosity is turned up or the specific # remove invocation unless specifically wanting it
# callback wants to keep it if not keep_invocation and self._display.verbosity < 3 and 'invocation' in result:
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'] del abridged_result['invocation']
return json.dumps(abridged_result, indent=indent, ensure_ascii=False, sort_keys=sort_keys) return json.dumps(abridged_result, indent=indent, ensure_ascii=False, sort_keys=sort_keys)