From 57e48824da055606db5dffbefb0bde03e88a53f5 Mon Sep 17 00:00:00 2001 From: Katerina Pilatova Date: Mon, 14 Nov 2016 13:44:12 +0100 Subject: [PATCH] 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 --- .../callback_plugins/validation_output.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/validations/callback_plugins/validation_output.py b/validations/callback_plugins/validation_output.py index 9a051d045..b660cc519 100644 --- a/validations/callback_plugins/validation_output.py +++ b/validations/callback_plugins/validation_output.py @@ -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()