From c1229468ad784495d8e8f4edabde85d66879d939 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 21 Jul 2017 07:05:31 +0900 Subject: [PATCH] Log items in loops better If the loop item has a result msg - we should display it. If the loop item doens't have a result msg - there is no other identifying feature than the loop variable - which may be a full dict or other json-object. In that case, pretty print it rather than one-lining it. This may not be perfect - but let's give it a try. Change-Id: Ib9a4dc0ac7783559151f12996144941e534633ee --- zuul/ansible/callback/zuul_stream.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/zuul/ansible/callback/zuul_stream.py b/zuul/ansible/callback/zuul_stream.py index 0461d0cfa4..9622f240cb 100644 --- a/zuul/ansible/callback/zuul_stream.py +++ b/zuul/ansible/callback/zuul_stream.py @@ -358,10 +358,15 @@ class CallbackModule(default.CallbackModule): status = 'ok' if result._task.action not in ('command', 'shell'): - self._log_message( - result=result, - msg="Item: {item}".format(item=result_dict['item']), - status=status) + if 'msg' in result_dict: + self._log_message( + result=result, msg=result_dict['msg'], status=status) + else: + self._log_message( + result=result, + msg=json.dumps(result_dict['item'], + indent=2, sort_keys=True), + status=status) else: self._log_message( result, @@ -481,7 +486,8 @@ class CallbackModule(default.CallbackModule): host=hostname, msg="Output suppressed because no_log was given")) return - if not msg and set(result_dict.keys()) == set(['msg', 'failed']): + if (not msg and result_dict + and set(result_dict.keys()) == set(['msg', 'failed'])): msg = result_dict['msg'] result_dict = None if msg: