From 35321ec642b5f4f1148d5621c6d76d0527a220e9 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Tue, 27 Jan 2015 14:18:06 -0800 Subject: [PATCH] ansible.utils to_unicode/to_bytes isn't robust in the face of non-strings. Do some value checking in the calling code --- lib/ansible/callbacks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py index 6a409b0a2f2..c2d811bb8f7 100644 --- a/lib/ansible/callbacks.py +++ b/lib/ansible/callbacks.py @@ -27,6 +27,7 @@ import fcntl import constants import locale from ansible.color import stringc +from ansible.module_utils import basic import logging if constants.DEFAULT_LOG_PATH != '': @@ -456,8 +457,12 @@ class PlaybookRunnerCallbacks(DefaultRunnerCallbacks): item = None if type(results) == dict: item = results.get('item', None) + if isinstance(item, unicode): + item = utils.to_bytes(item) + results = basic.json_dict_unicode_to_bytes(results) + else: + results = utils.to_bytes(results) host = utils.to_bytes(host) - results = utils.to_bytes(results) if item: msg = "fatal: [%s] => (item=%s) => %s" % (host, item, results) else: