Repository: ansible-collections/community.general

Issue:
nmcli not idempotent on german CentOS
### SUMMARY

When running a simple `nmcli`-Task on a CentOS7 machine that is using the german language pack, the task **always** returns `CHANGED`, although nothing has changed.

This is most likely due to the fact, that the `nmcli` with a german `$LANG` always returns `yes` as `ja` and `ansible` thinks that this means that the values don't match, although `yes` == `ja` in German.

I also provided a fix down below for all the people that might also come across this ~~issue~~ minor inconvenience.

##### ISSUE TYPE

- Bug Report

##### COMPONENT NAME

`community.general.nmcli `

##### ANSIBLE VERSION

```paste below
ansible 2.10.1
  config file = /Users/lukas/Developer/ansible/ansible.cfg
  configured module search path = ['/Users/lukas/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/lukas/Developer/ansible/venv/lib/python3.8/site-packages/ansible
  executable location = /Users/lukas/Developer/ansible/venv/bin/ansible
  python version = 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18) [Clang 6.0 (clang-600.0.57)]
```

##### CONFIGURATION

```paste below
COLLECTIONS_PATHS(/Users/lukas/Developer/ansible/ansible.cfg) = ['/Users/lukas/Developer/ansible/galaxy']
COMMAND_WARNINGS(/Users/lukas/Developer/ansible/ansible.cfg) = False
DEFAULT_HOST_LIST(/Users/lukas/Developer/ansible/ansible.cfg) = ['/Users/lukas/Developer/ansible/inventory.yml']
DEFAULT_ROLES_PATH(/Users/lukas/Developer/ansible/ansible.cfg) = ['/Users/lukas/Developer/ansible/galaxy', '/Users/lukas/Devel
DEFAULT_UNDEFINED_VAR_BEHAVIOR(/Users/lukas/Developer/ansible/ansible.cfg) = True
DEPRECATION_WARNINGS(/Users/lukas/Developer/ansible/ansible.cfg) = True
DIFF_ALWAYS(/Users/lukas/Developer/ansible/ansible.cfg) = True
DIFF_CONTEXT(/Users/lukas/Developer/ansible/ansible.cfg) = 3
HOST_KEY_CHECKING(/Users/lukas/Developer/ansible/ansible.cfg) = True
SYSTEM_WARNINGS(/Users/lukas/Developer/ansible/ansible.cfg) = True
```

##### OS / ENVIRONMENT

* `macOS 10.15.7` on master
* `CentOS Linux release 7.8.2003 (Core)` on target node
  * with `LANG=de_AT.UTF-8`

##### STEPS TO REPRODUCE

```yaml
    - name: Try nmcli add bond - conn_name only & ip4 gw4 mode
      nmcli:
        type: ethernet
        conn_name: '{{ item.conn_name }}'
        ifname: '{{ item.ifname }}'
        ip4: '{{ item.ip4 }}'
        gw4: '{{ item.gw4 }}'
        dns4: '{{ item.dns4 }}'
        state: present
      loop: '{{ common_nmcli_connections|default([]) }}'
      notify:
        - restart network
```


##### EXPECTED RESULTS

If nothing has changed, it should report the task as `OK`.

##### ACTUAL RESULTS

```paste below
TASK [common : Try nmcli add bond - conn_name only & ip4 gw4 mode] *************
--- before
+++ after
@@ -1,5 +1,5 @@
 {
-    "autoconnect": "ja",
+    "autoconnect": "yes",
     "ipv4.addresses": "xxxx/32 ...",
     "ipv4.dns": [
         "1.0.0.1",
changed: ...
```

##### POSSIBLE FIX

When I add the `environment` as stated below, it actually makes it idempotent again.

```paste below
    - name: Try nmcli add bond - conn_name only & ip4 gw4 mode
      nmcli:
        type: ethernet
        conn_name: '{{ item.conn_name }}'
        ifname: '{{ item.ifname }}'
        ip4: '{{ item.ip4 }}'
        gw4: '{{ item.gw4 }}'
        dns4: '{{ item.dns4 }}'
        state: present
      loop: '{{ common_nmcli_connections|default([]) }}'
      notify:
        - restart network
      environment:
        LANG: en_US.utf8
```



Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
!component =plugins/modules/net_tools/nmcli.py
Files identified in the description:
* [`plugins/modules/net_tools/nmcli.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/net_tools/nmcli.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @alcamie101 @nerzhul
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
A lot of modules do something like `module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C', LC_CTYPE='C')` to make sure that the C locale is set. That should probably also fix this issue.

Resolving patch:
diff --git a/plugins/modules/net_tools/nmcli.py b/plugins/modules/net_tools/nmcli.py
--- a/plugins/modules/net_tools/nmcli.py
+++ b/plugins/modules/net_tools/nmcli.py
@@ -1760,6 +1760,7 @@ def main():
         ),
         supports_check_mode=True,
     )
+    module.run_command_environ_update = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C', LC_CTYPE='C')
 
     if not HAVE_DBUS:
         module.fail_json(msg=missing_required_lib('dbus'), exception=DBUS_IMP_ERR)


Test patch: