From 254f87e7ddd0a3562764325640dde1f74e3f5541 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 12 Feb 2014 11:26:58 -0600 Subject: [PATCH] Fix log handling of unicode output to syslog in modules --- lib/ansible/module_utils/basic.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 75e50831a71..8f630b98972 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -777,7 +777,10 @@ class AnsibleModule(object): module = 'ansible-%s' % os.path.basename(__file__) msg = '' for arg in log_args: - msg = msg + arg + '=' + str(log_args[arg]) + ' ' + if isinstance(log_args[arg], unicode): + msg = msg + arg + '=' + log_args[arg] + ' ' + else: + msg = msg + arg + '=' + str(log_args[arg]) + ' ' if msg: msg = 'Invoked with %s' % msg else: @@ -793,10 +796,10 @@ class AnsibleModule(object): except IOError, e: # fall back to syslog since logging to journal failed syslog.openlog(str(module), 0, syslog.LOG_USER) - syslog.syslog(syslog.LOG_NOTICE, msg) + syslog.syslog(syslog.LOG_NOTICE, msg.encode('utf8')) else: syslog.openlog(str(module), 0, syslog.LOG_USER) - syslog.syslog(syslog.LOG_NOTICE, msg) + syslog.syslog(syslog.LOG_NOTICE, msg.encode('utf8')) def get_bin_path(self, arg, required=False, opt_dirs=[]): '''