Reworking internal result flags and making sure include_vars hides vault data

Fixes #10194
This commit is contained in:
James Cammarata 2015-07-27 14:01:02 -04:00
commit cb262449c7
7 changed files with 30 additions and 27 deletions

View file

@ -23,6 +23,8 @@ import json
import difflib
import warnings
from six import string_types
from ansible import constants as C
from ansible.utils.unicode import to_unicode
@ -48,8 +50,20 @@ 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=4, sort_keys=True):
return json.dumps(result, indent=indent, ensure_ascii=False, sort_keys=sort_keys)
def _dump_results(self, result, indent=None, sort_keys=True):
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"))
else:
if '_ansible_verbose_always' in result:
indent = 4
# all result keys stating with _ansible_ are internal, so remove
# them from the result before we output anything. We have to save
# the keys off first, as we're modifying the dict (so iteritems()
# won't work here)
for k in result.keys():
if isinstance(k, string_types) and k.startswith('_ansible_'):
del result[k]
return json.dumps(result, indent=indent, ensure_ascii=False, sort_keys=sort_keys)
def _handle_warnings(self, res):
''' display warnings, if enabled and any exist in the result '''

View file

@ -63,24 +63,16 @@ class CallbackModule(CallbackBase):
msg = "ok: [%s]" % result._host.get_name()
color = 'green'
if (self._display.verbosity > 0 or 'verbose_always' in result._result) and result._task.action not in ('setup', 'include'):
indent = None
if 'verbose_always' in result._result:
indent = 4
del result._result['verbose_always']
msg += " => %s" % self._dump_results(result._result, indent=indent)
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and result._task.action not in ('setup', 'include'):
msg += " => %s" % self._dump_results(result._result)
self._display.display(msg, color=color)
self._handle_warnings(result._result)
def v2_runner_on_skipped(self, result):
msg = "skipping: [%s]" % result._host.get_name()
if self._display.verbosity > 0 or 'verbose_always' in result._result:
indent = None
if 'verbose_always' in result._result:
indent = 4
del result._result['verbose_always']
msg += " => %s" % self._dump_results(result._result, indent=indent)
if self._display.verbosity > 0 or '_ansible_verbose_always' in result._result:
msg += " => %s" % self._dump_results(result._result)
self._display.display(msg, color='cyan')
def v2_runner_on_unreachable(self, result):

View file

@ -63,12 +63,8 @@ class CallbackModule(CallbackBase):
msg = "ok: [%s]" % result._host.get_name()
color = 'green'
if (self._display.verbosity > 0 or 'verbose_always' in result._result) and result._task.action not in ('setup', 'include'):
indent = None
if 'verbose_always' in result._result:
indent = 4
del result._result['verbose_always']
msg += " => %s" % self._dump_results(result._result, indent=indent)
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and result._task.action not in ('setup', 'include'):
msg += " => %s" % self._dump_results(result._result)
self._display.display(msg, color=color)
self._handle_warnings(result._result)