Repository: ansible/ansible

Issue:
"service: enable=yes/no" with spanish CentOS6 servers is broken
From @vicendominguez on 2016-04-14T16:46:43Z
##### ISSUE TYPE
- Documentation Report
##### COMPONENT NAME

service core module
##### ANSIBLE VERSION

```
ansible 2.0.1.0 
(but I wouldn't discard other versions)

```
##### OS / ENVIRONMENT

CentOS 6.7 
(at least)
##### SUMMARY

On CentOS6 at least, a spanish translator did a bad translating in some  error messages returned to the command line by the chkconfig tool which break the "service enable=yes / no" option in Ansible.
It 's not a direct Ansible issue but Ansible is affected.
##### STEPS TO REPRODUCE

```
- name: Start myservice and enable it
  service: name=myservice state=started enabled=yes
```
##### EXPECTED RESULTS

```
TASK [role : Start myservice and enable it ] ***********************************************
ok: [myservice]
```
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with high verbosity (-vvvv) -->

```
TASK [role : Start myservice and enable it ] ***********************************************
fatal: [myservice]: FAILED! => {"changed": false, "failed": true, "msg": "service myservice does not support chkconfig"}
```
##### WHY

Line https://github.com/ansible/ansible-modules-core/blob/devel/system/service.py#L702 waits a concrete answer to do the regexp but, in Spanish, that line is bad translated changing the "--add" statement to "--añada" (doesn't make sense), so you see something like:

"El servicio myservice soporta chkconfig, pero no está registrado (ejecute \n'chkconfig -- añada myservice')\n"

the sentence "chkconfig --add" doesn't appear there and that breaks the "if". So the "enable" feature is broken.
##### WORKAROUND

`export LANG="en"` 

in the terminal, before starting to work with any sofware which uses Ansible inside.

Copied from original issue: ansible/ansible-modules-core#3438



Discussion:
From @ansibot on 2016-04-14T16:46:43Z

<!-- @vicendominguez: Thanks for filing this documentation report! -->

@grossws ping, this issue is waiting for your response.
[click here for bot help](https://github.com/jctanner/ansibullbot/blob/ISSUE_TRIAGE_CLASS/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->

[service.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/system/service.py#L734) should force the locale before checking the stdout/err of the chkconfig command as suggested by the deprecation message in DEFAULT_MODULE_LANG: ``Modules are coded to set their own locale if needed for screenscraping``

Resolving patch:
diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py
--- a/lib/ansible/modules/system/service.py
+++ b/lib/ansible/modules/system/service.py
@@ -248,7 +248,10 @@ def execute_command(self, cmd, daemonize=False):
                 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]


Test patch: