Repository: ansible-collections/community.general

Issue:
nmcli fails to update DNS servers
### Summary

I'm trying to use the nmcli module to set DNS servers for a connection, but it's failing with an error message about the IPv4 gateway.

### Issue Type

Bug Report

### Component Name

nmcli

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.12.3]
  config file = /Users/anandb/repo/rootsorg/config/ansible/ansible.cfg
  configured module search path = ['/Users/anandb/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/anandb/.virtualenvs/ansible_latest/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/anandb/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/anandb/.virtualenvs/ansible_latest/bin/ansible
  python version = 3.10.2 (main, Feb  2 2022, 08:42:42) [Clang 13.0.0 (clang-1300.0.29.3)]
  jinja version = 3.0.3
  libyaml = True
```

### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general

# /Users/anandb/.virtualenvs/ansible_latest/lib/python3.10/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 4.6.0
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
DEFAULT_HOST_LIST(/Users/anandb/repo/rootsorg/config/ansible/ansible.cfg) = ['/Users/anandb/repo/rootsorg/config/ansible/hosts']
DEFAULT_TIMEOUT(env: ANSIBLE_TIMEOUT) = 60
```

### OS / Environment

The target OS is an up to date CentOS 7 system

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
ansible HOST -m nmcli -a "conn_name=em1 type=ethernet state=present dns6='::1 2620:fe::fe'"
```

### Expected Results

I expected the task to run successfully, and update the DNS servers if necessary.

### Actual Results

```console (paste below)
HOST | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "msg": "Error: Failed to modify connection 'em1': ipv4.gateway: gateway cannot be set if there are no addresses configured\n",
    "name": "em1",
    "rc": 1
}
```

### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/net_tools/nmcli.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/net_tools/nmcli.py)

If these files are incorrect, 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/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @alcamie101
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Able to reproduce the bug with community.general version 4.8.0 - target system Rocky 8.5
Any workaround for this yet?

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
@@ -1836,7 +1836,10 @@ def bool_to_string(boolean):
 
     @staticmethod
     def list_to_string(lst):
-        return ",".join(lst or [""])
+        if lst is None:
+            return None
+        else:
+            return ",".join(lst)
 
     @staticmethod
     def settings_type(setting):


Test patch:
diff --git a/tests/unit/plugins/modules/net_tools/test_nmcli.py b/tests/unit/plugins/modules/net_tools/test_nmcli.py
--- a/tests/unit/plugins/modules/net_tools/test_nmcli.py
+++ b/tests/unit/plugins/modules/net_tools/test_nmcli.py
@@ -455,6 +455,17 @@
 ipv6.ignore-auto-routes:                no
 """
 
+TESTCASE_GENERIC_ZONE_ONLY = [
+    {
+        'type': 'generic',
+        'conn_name': 'non_existent_nw_device',
+        'ifname': 'generic_non_existant',
+        'state': 'present',
+        'zone': 'public',
+        '_ansible_check_mode': False,
+    }
+]
+
 TESTCASE_BOND = [
     {
         'type': 'bond',
@@ -1888,6 +1899,30 @@ def test_generic_connection_zone_unchanged(mocked_generic_connection_zone_unchan
     assert not results['changed']
 
 
+@pytest.mark.parametrize('patch_ansible_module', TESTCASE_GENERIC_ZONE_ONLY, indirect=['patch_ansible_module'])
+def test_generic_connection_modify_zone_only(mocked_generic_connection_modify, capfd):
+    """
+    Test : Generic connection modified with zone only
+    """
+    with pytest.raises(SystemExit):
+        nmcli.main()
+
+    assert nmcli.Nmcli.execute_command.call_count == 1
+    arg_list = nmcli.Nmcli.execute_command.call_args_list
+    args, kwargs = arg_list[0]
+
+    assert 'connection.zone' in args[0]
+    assert 'ipv4.addresses' not in args[0]
+    assert 'ipv4.gateway' not in args[0]
+    assert 'ipv6.addresses' not in args[0]
+    assert 'ipv6.gateway' not in args[0]
+
+    out, err = capfd.readouterr()
+    results = json.loads(out)
+    assert not results.get('failed')
+    assert results['changed']
+
+
 @pytest.mark.parametrize('patch_ansible_module', TESTCASE_CONNECTION, indirect=['patch_ansible_module'])
 def test_zone_none(mocked_connection_exists, capfd):
     """