Sanitize validations output

Ensure the output module methods call _dump_results() in order to
sanitize validations output.

Change-Id: I5fbb92474d1e3ed19251e615c883f6d889865bab
(cherry picked from commit 81e7fcec29)
This commit is contained in:
Ana Krivokapic 2018-01-10 14:36:03 +01:00
parent 97ae1217df
commit 04f4638ca1
1 changed files with 7 additions and 3 deletions

View File

@ -46,7 +46,7 @@ def indent(text):
return ''.join(' {}\n'.format(line) for line in text.splitlines())
def print_failure_message(host_name, task_name, results):
def print_failure_message(host_name, task_name, results, abridged_result):
'''Print a human-readable error info from Ansible result dictionary.'''
def is_script(results):
return ('rc' in results and
@ -85,7 +85,7 @@ def print_failure_message(host_name, task_name, results):
print(indent(stderr))
if display_full_results:
print("Could not get an error message. Here is the Ansible output:")
pprint.pprint(results, indent=4)
pprint.pprint(abridged_result, indent=4)
warnings = results.get('warnings', [])
if warnings:
print("Warnings:")
@ -113,6 +113,7 @@ class CallbackModule(CallbackBase):
host_name = result._host
task_name = result._task.get_name()
results = result._result # A dict of the module name etc.
self._dump_results(results)
warnings = results.get('warnings', [])
# Print only tasks that produced some warnings:
if warnings:
@ -147,6 +148,8 @@ class CallbackModule(CallbackBase):
task_name = result._task.get_name()
result_dict = result._result # A dict of the module name etc.
abridged_result = self._dump_results(result_dict)
if 'results' in result_dict:
# The task is a list of items under `results`
for item in result_dict['results']:
@ -154,7 +157,8 @@ class CallbackModule(CallbackBase):
print_failure_message(host_name, task_name, item)
else:
# The task is a "normal" module invocation
print_failure_message(host_name, task_name, result_dict)
print_failure_message(host_name, task_name, result_dict,
abridged_result)
def v2_runner_on_skipped(self, result, **kwargs):
pass # No need to print skipped tasks