From f77f605115cb6a56faccacec9113db4f208f7b90 Mon Sep 17 00:00:00 2001 From: Adrian Lopez Date: Thu, 19 Apr 2018 00:04:15 +0200 Subject: [PATCH] chkconfig localizes messages, ansible fails to recognise In the particular case of executin "chkconfig --list NAME", ansible checks the stderr looking for a particular english message. This message is different in other languages, Spanish for example (although it have been corrected in the latests versions) Fixes #29818 (cherry picked from commit e7db3c0eba95f6c2accd2c8ce99031dbb1b3925e) --- changelogs/fragments/service_local_fix.yml | 2 ++ lib/ansible/modules/system/service.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/service_local_fix.yml diff --git a/changelogs/fragments/service_local_fix.yml b/changelogs/fragments/service_local_fix.yml new file mode 100644 index 00000000000..85fcd207b0c --- /dev/null +++ b/changelogs/fragments/service_local_fix.yml @@ -0,0 +1,2 @@ +bugfixes: + ensure C locale for chkconfig to allow sane screen scraping https://github.com/ansible/ansible/pull/38980 diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index b2ff5e11a8e..e6a719988bb 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -248,7 +248,10 @@ class Service(object): cmd = [to_bytes(c, errors='surrogate_or_strict') for c in shlex.split(cmd)] # In either of the above cases, pass a list of byte strings to Popen - p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=lambda: os.close(pipe[1])) + # chkconfig localizes messages and we're screen scraping so make + # sure we use the C locale + lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C') + p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=lang_env, preexec_fn=lambda: os.close(pipe[1])) stdout = b("") stderr = b("") fds = [p.stdout, p.stderr]