From 1c5ac5cac843b461138420d4c82077e4b3cf2663 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Thu, 1 Nov 2012 13:22:34 -0400 Subject: [PATCH] Pretty-print "msg" when task fails Several modules (e.g., pip) return stdout and stderr together in a "msg" variable (and the module development docs seem to suggest that the standard practice is to return status in this variable). This change ensures that it is printed out with correct formatting (most importantly, with newlines appearing as newlines instead of \n). --- lib/ansible/callbacks.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py index b8b8e9d47e9..c2bf2911c19 100644 --- a/lib/ansible/callbacks.py +++ b/lib/ansible/callbacks.py @@ -46,8 +46,8 @@ elif os.path.exists("/usr/local/bin/cowsay"): def call_callback_module(method_name, *args, **kwargs): for callback_plugin in callbacks: - methods = [ - getattr(callback_plugin, method_name, None), + methods = [ + getattr(callback_plugin, method_name, None), getattr(callback_plugin, 'on_any', None) ] for method in methods: @@ -314,6 +314,7 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks): module_msg = results2.pop('msg', None) stderr = results2.pop('stderr', None) stdout = results2.pop('stdout', None) + returned_msg = results2.pop('msg', None) if item: msg = "failed: [%s] => (item=%s) => %s" % (host, item, utils.jsonify(results2)) @@ -325,6 +326,8 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks): print stringc("stderr: %s" % stderr, 'red') if stdout: print stringc("stdout: %s" % stdout, 'red') + if returned_msg: + print stringc("msg: %s" % returned_msg, 'red') if not parsed and module_msg: print stringc("invalid output was: %s" % module_msg, 'red') if ignore_errors: @@ -457,7 +460,7 @@ class PlaybookCallbacks(object): while True: result = prompt(msg, private) second = prompt("confirm " + msg, private) - if result == second: + if result == second: break print "***** VALUES ENTERED DO NOT MATCH ****" else: