Repository: ansible/ansible

Issue:
Error handling in parted module does not work when LANG is not set to en_US
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
`parted` module

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.3.0.0
  config file =
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
```

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->
N/A

##### SUMMARY
<!--- Explain the problem briefly -->
The module might fail when `LANG` is not set to `en_US`. The module checks stderr for output strings in english (e.g. [this line](https://github.com/ansible/ansible/blob/v2.3.0.0-1/lib/ansible/modules/system/parted.py#L421)). `parted` returns error messages in german when `LANG` is set to `de_DE`.

Maybe it is possible to set `LANG` to `en_US` when calling `module.run_command`. 

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
* Set `LANG` to `de_DE`.
* Create an empty disk without a partition table and and try to partition it with the `parted` module.

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Create partition on sdb
  parted:
    device: /dev/sdb
    number: 1
    state: present
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
A newly created partition /dev/sdb1

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
fatal: [machine01]: FAILED! => {
    "changed": false,
    "err": "Fehler: /dev/sdb: unbekannte Partitionstabelle\n",
    "failed": true,
    "invocation": {
        "module_args": {
            "align": "optimal",
            "device": "/dev/sdb",
            "flags": null,
            "label": null,
            "name": null,
            "number": 1,
            "part_end": "100%",
            "part_start": "0%",
            "part_type": "primary",
            "state": "present",
            "unit": "KiB"
        }
    },
    "msg": "Error while getting device information with parted script: '/sbin/parted -s -m /dev/sdb -- unit 'KiB' print'",
    "out": "BYT;\n/dev/sdb:524288000kiB:scsi:512:512:unknown:VMware Virtual disk:;\n",
    "rc": 1
}
```

##### WORKAROUND
```
- name: Create partition on sdb
  parted:
    device: /dev/sdb
    number: 1
    state: present
  environment:
    LANG: en_US.UTF-8
```



Discussion:
cc @ColOfAbRiX
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/system/parted.py b/lib/ansible/modules/system/parted.py
old mode 100755
new mode 100644
--- a/lib/ansible/modules/system/parted.py
+++ b/lib/ansible/modules/system/parted.py
@@ -590,6 +590,7 @@ def main():
         },
         supports_check_mode=True,
     )
+    module.run_command_environ_update = {'LANG': 'C', 'LC_ALL': 'C', 'LC_MESSAGES': 'C'}
 
     # Data extraction
     device = module.params['device']


Test patch: