Handle debug messages cleanly
This changes from:
2017-09-06 18:17:37.173853 | TASK [debug]
2017-09-06 18:17:37.216661 | localhost | ok:
2017-09-06 18:17:37.216882 | localhost | {
2017-09-06 18:17:37.216967 | localhost | "msg": "Job triggered from https://review.openstack.org/#/c/501485"
2017-09-06 18:17:37.217047 | localhost | }
to:
2017-09-06 18:20:34.383995 | TASK [debug]
2017-09-06 18:20:34.429648 | Job triggered from https://review.openstack.org/#/c/501485
Change-Id: Iac39124c2a3b286215d175f98742d00ec5a12778
diff --git a/playbooks/zuul-stream/fixtures/test-stream.yaml b/playbooks/zuul-stream/fixtures/test-stream.yaml
index 29bbf47..bcbc3ff 100644
--- a/playbooks/zuul-stream/fixtures/test-stream.yaml
+++ b/playbooks/zuul-stream/fixtures/test-stream.yaml
@@ -10,6 +10,10 @@
debug:
var: setupvar
+ - name: Output a debug sentence
+ debug:
+ msg: This is a debug message
+
- name: Run a shell task
command: ip addr show
diff --git a/zuul/ansible/callback/zuul_stream.py b/zuul/ansible/callback/zuul_stream.py
index eadca68..b5c6fae 100644
--- a/zuul/ansible/callback/zuul_stream.py
+++ b/zuul/ansible/callback/zuul_stream.py
@@ -374,9 +374,20 @@
for key in [k for k in result_dict.keys()
if k.startswith('_ansible')]:
del result_dict[key]
- self._log_message(
- msg=json.dumps(result_dict, indent=2, sort_keys=True),
- status=status, result=result)
+ keyname = next(iter(result_dict.keys()))
+ # If it has msg, that means it was like:
+ #
+ # debug:
+ # msg: Some debug text the user was looking for
+ #
+ # So we log it with self._log to get just the raw string the
+ # user provided.
+ if keyname == 'msg':
+ self._log(msg=result_dict['msg'])
+ else:
+ self._log_message(
+ msg=json.dumps(result_dict, indent=2, sort_keys=True),
+ status=status, result=result)
elif result._task.action not in ('command', 'shell'):
if 'msg' in result_dict:
self._log_message(msg=result_dict['msg'],