summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2015-10-23 11:08:55 -0700
committerToshio Kuratomi <toshio@fedoraproject.org>2015-10-23 11:11:34 -0700
commit3812ec8d1db78f5e6dcefdce112e10e3456cf541 (patch)
tree5f947595b00829a0a70e3abf9fc7cc8ad2236810
parent275764d4a5bd5ff9a10f581507f6275fb55caf3f (diff)
downloadansible-3812ec8d1db78f5e6dcefdce112e10e3456cf541.tar.gz
Implement invocation hiding for all callbacks if the verbosity is low
-rw-r--r--lib/ansible/plugins/callback/__init__.py24
-rw-r--r--lib/ansible/plugins/callback/minimal.py18
2 files changed, 22 insertions, 20 deletions
diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py
index 183895e5fd..5b3dc95be2 100644
--- a/lib/ansible/plugins/callback/__init__.py
+++ b/lib/ansible/plugins/callback/__init__.py
@@ -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
-
diff --git a/lib/ansible/plugins/callback/minimal.py b/lib/ansible/plugins/callback/minimal.py
index eaada8dd53..f855c1a6e5 100644
--- a/lib/ansible/plugins/callback/minimal.py
+++ b/lib/ansible/plugins/callback/minimal.py
@@ -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']: