From a1adff4ff00091741cd95301d66a33cac161ea9d Mon Sep 17 00:00:00 2001 From: Baptiste Mathus Date: Wed, 26 Nov 2014 10:35:45 +0100 Subject: [PATCH] Setting LC_MESSAGES: prevent unparseable messages This locale variable defines how tools should display their messages. This is for example gonna change the yum message from "Nothing to do" to "Rien a faire" in my case (french). As the yum module parses that string in err, if the message is not enforced in english this is gonna fail. So this commits just enriches a bit more the code that's already written for that enforcement. This commit fixes issue #9635. --- lib/ansible/module_utils/basic.py | 1 + lib/ansible/runner/shell_plugins/sh.py | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index cee6510f34..761725cea0 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -772,6 +772,7 @@ class AnsibleModule(object): locale.setlocale(locale.LC_ALL, 'C') os.environ['LANG'] = 'C' os.environ['LC_CTYPE'] = 'C' + os.environ['LC_MESSAGES'] = 'C' except Exception, e: self.fail_json(msg="An unknown error was encountered while attempting to validate the locale: %s" % e) diff --git a/lib/ansible/runner/shell_plugins/sh.py b/lib/ansible/runner/shell_plugins/sh.py index 95d48e9e7d..27512b2c59 100644 --- a/lib/ansible/runner/shell_plugins/sh.py +++ b/lib/ansible/runner/shell_plugins/sh.py @@ -29,6 +29,7 @@ class ShellModule(object): env = dict( LANG = C.DEFAULT_MODULE_LANG, LC_CTYPE = C.DEFAULT_MODULE_LANG, + LC_MESSAGES = C.DEFAULT_MODULE_LANG, ) env.update(kwargs) return ' '.join(['%s=%s' % (k, pipes.quote(unicode(v))) for k,v in env.items()])