validation_output.py: Provided output for ansible debug module.

- prints both variables and messages provided to the module
- template for printing debug module results created
- output contains module name, host and the result

Change-Id: I5854256542951d09bd48fa0e9415b90fd67abce8
This commit is contained in:
Katerina Pilatova
2016-11-14 13:44:12 +01:00
parent cda69b09e2
commit 57e48824da

View File

@@ -34,6 +34,12 @@ Host: {}
Warnings:
"""
DEBUG_TEMPLATE = """\
Task: Debug
Host: {}
{}
"""
def indent(text):
'''Indent the given text by four spaces.'''
@@ -114,6 +120,28 @@ class CallbackModule(CallbackBase):
for warning in warnings:
print("*", warning)
# Print the result of debug module
if (('invocation' in results) and
('module_name' in results['invocation'])):
if ((results['invocation']['module_name'] == 'debug') and
('module_args' in results['invocation'])):
output = ""
# Variable and its value
if 'var' in results['invocation']['module_args']:
variable = results['invocation']['module_args']['var']
value = results[variable]
output = "{}: {}".format(variable, str(value))
# Debug message
elif 'msg' in results['invocation']['module_args']:
output = "Message: {}".format(
results['invocation']['module_args']['msg'])
print(DEBUG_TEMPLATE.format(host_name, output))
def v2_runner_on_failed(self, result, **kwargs):
host_name = result._host
task_name = result._task.get_name()