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
This commit is contained in:
Monty Taylor 2017-07-21 07:05:31 +09:00
parent e60af64c1b
commit c1229468ad
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
1 changed files with 11 additions and 5 deletions

View File

@ -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: