summaryrefslogtreecommitdiff
path: root/zuul/ansible
diff options
context:
space:
mode:
Diffstat (limited to 'zuul/ansible')
-rw-r--r--zuul/ansible/base/callback/zuul_stream.py44
1 files changed, 31 insertions, 13 deletions
diff --git a/zuul/ansible/base/callback/zuul_stream.py b/zuul/ansible/base/callback/zuul_stream.py
index 39d3aa953..b5c14691b 100644
--- a/zuul/ansible/base/callback/zuul_stream.py
+++ b/zuul/ansible/base/callback/zuul_stream.py
@@ -43,13 +43,18 @@ import threading
import time
from ansible.plugins.callback import default
+from ansible.module_utils._text import to_text
from zuul.ansible import paths
from zuul.ansible import logconfig
-LOG_STREAM_PORT = int(os.environ.get("ZUUL_CONSOLE_PORT", 19885))
LOG_STREAM_VERSION = 0
+# This is intended to be only used for testing where we change the
+# port so we can run another instance that doesn't conflict with one
+# setup by the test environment
+LOG_STREAM_PORT = int(os.environ.get("ZUUL_CONSOLE_PORT", 19885))
+
def zuul_filter_result(result):
"""Remove keys from shell/command output.
@@ -319,13 +324,13 @@ class CallbackModule(default.CallbackModule):
hosts = self._get_task_hosts(task)
for host, inventory_hostname in hosts:
port = LOG_STREAM_PORT
- if host in ('localhost', '127.0.0.1'):
+ if (host in ('localhost', '127.0.0.1')):
# Don't try to stream from localhost
continue
ip = play_vars[host].get(
'ansible_host', play_vars[host].get(
'ansible_inventory_host'))
- if ip in ('localhost', '127.0.0.1'):
+ if (ip in ('localhost', '127.0.0.1')):
# Don't try to stream from localhost
continue
if play_vars[host].get('ansible_connection') in ('winrm',):
@@ -499,8 +504,7 @@ class CallbackModule(default.CallbackModule):
if result._task.loop and 'results' in result_dict:
# items have their own events
pass
-
- elif result_dict.get('msg', '').startswith('MODULE FAILURE'):
+ elif to_text(result_dict.get('msg', '')).startswith('MODULE FAILURE'):
self._log_module_failure(result, result_dict)
elif result._task.action == 'debug':
# this is a debug statement, handle it special
@@ -519,7 +523,7 @@ class CallbackModule(default.CallbackModule):
# user provided. Note that msg may be a multi line block quote
# so we handle that here as well.
if keyname == 'msg':
- msg_lines = result_dict['msg'].rstrip().split('\n')
+ msg_lines = to_text(result_dict['msg']).rstrip().split('\n')
for msg_line in msg_lines:
self._log(msg=msg_line)
else:
@@ -542,10 +546,18 @@ class CallbackModule(default.CallbackModule):
elif result_dict.get('msg') == 'All items completed':
self._log_message(result, result_dict['msg'])
else:
- self._log_message(
- result,
- "Runtime: {delta}".format(
- **result_dict))
+ if 'delta' in result_dict:
+ self._log_message(
+ result,
+ "Runtime: {delta}".format(
+ **result_dict))
+ else:
+ # NOTE(ianw) 2022-08-24 : *Fairly* sure that you only
+ # fall into here when the call actually fails (and has
+ # not start/end time), but it is ignored by
+ # failed_when matching.
+ self._log_message(result, msg='ERROR (ignored)',
+ result_dict=result_dict)
def v2_runner_item_on_ok(self, result):
result_dict = dict(result._result)
@@ -561,7 +573,7 @@ class CallbackModule(default.CallbackModule):
# changes.
loop_var = result_dict.get('ansible_loop_var', 'item')
- if result_dict.get('msg', '').startswith('MODULE FAILURE'):
+ if to_text(result_dict.get('msg', '')).startswith('MODULE FAILURE'):
self._log_module_failure(result, result_dict)
elif result._task.action not in ('command', 'shell',
'win_command', 'win_shell'):
@@ -604,7 +616,7 @@ class CallbackModule(default.CallbackModule):
# changes.
loop_var = result_dict.get('ansible_loop_var', 'item')
- if result_dict.get('msg', '').startswith('MODULE FAILURE'):
+ if to_text(result_dict.get('msg', '')).startswith('MODULE FAILURE'):
self._log_module_failure(result, result_dict)
elif result._task.action not in ('command', 'shell',
'win_command', 'win_shell'):
@@ -737,7 +749,13 @@ class CallbackModule(default.CallbackModule):
msg = result_dict['msg']
result_dict = None
if msg:
- msg_lines = msg.rstrip().split('\n')
+ # ensure msg is a string; e.g.
+ #
+ # debug:
+ # msg: '{{ var }}'
+ #
+ # may not be!
+ msg_lines = to_text(msg).rstrip().split('\n')
if len(msg_lines) > 1:
self._log("{host} | {status}:".format(
host=hostname, status=status))