From 3194fbd36577d1612513cff2b9bfa72052877a92 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 25 Mar 2014 16:07:05 -0400 Subject: [PATCH] Fixes #6655 catch unicode encoding errors before sending to syslog --- lib/ansible/module_utils/basic.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 4bdb3fc2cc5016..7f7054fc478e52 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -804,6 +804,12 @@ def _log_invocation(self): else: msg = 'Invoked' + # 6655 - allow for accented characters + try: + msg = unicode(msg).encode('utf8') + except UnicodeDecodeError, e: + pass + if (has_journal): journal_args = ["MESSAGE=%s %s" % (module, msg)] journal_args.append("MODULE=%s" % os.path.basename(__file__)) @@ -814,10 +820,10 @@ def _log_invocation(self): 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, unicode(msg).encode('utf8')) + syslog.syslog(syslog.LOG_NOTICE, msg) #1 else: syslog.openlog(str(module), 0, syslog.LOG_USER) - syslog.syslog(syslog.LOG_NOTICE, unicode(msg).encode('utf8')) + syslog.syslog(syslog.LOG_NOTICE, msg) #2 def _set_cwd(self): try: