Repository: ansible-collections/community.general

Issue:
nmcli unable to create bridge slave
It appears this was reported here but closed with no resolution. 
https://github.com/ansible/ansible/issues/42460

##### SUMMARY
Attempting to add slave bridge results in error:
Error: invalid or not allowed setting 'ipv6': 'ipv6' not among [connection, 802-3-ethernet (ethernet), 802-1x, dcb, bridge-port].\n

```
- name: create bridge interface
  community.general.nmcli:
    conn_name: Bridge connection 1
    ifname: bridge0
    type: bridge
    state: present
    stp: no
  become: yes
- name: create bridge interface slave
  community.general.nmcli:
    conn_name: bridge0 slave 1
    ifname: enx00e04c05510f
    type: bridge-slave
    master: bridge0
    state: present
    stp: no
  become: yes
```

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
nmcli

##### ANSIBLE VERSION

```
2.9.6
```

##### CONFIGURATION
```
```
No output???

##### OS / ENVIRONMENT
Ubuntu 18.04 Desktop


##### STEPS TO REPRODUCE
```
- name: create bridge interface
  community.general.nmcli:
    conn_name: Bridge connection 1
    ifname: bridge0
    type: bridge
    state: present
    stp: no
  become: yes
- name: create bridge interface slave
  community.general.nmcli:
    conn_name: bridge0 slave 1
    ifname: enx00e04c05510f
    type: bridge-slave
    master: bridge0
    state: present
    stp: no
  become: yes
```

##### EXPECTED RESULTS
1. bridge gets created
2. bridge contains slave device

##### ACTUAL RESULTS
1. bridge gets created
2. slave fails with above error message
Here is the output of the above tasks, when passed to the wrapper I made for nmcli to capture the actual parameters that got passed to it.

Please note that second invocation contains ipv6 and ipv4 settings, although they were not explicitly specified. 

```
Executing: nmcli --fields name --terse con show
Exited: 0
Executing: nmcli con show Bridge connection 1
Exited: 10
Executing: nmcli con modify Bridge connection 1 connection.interface-name bridge0 ipv6.dns-search  ipv4.dns-search  bridge.ageing-time 300 connection.autoconnect yes bridge.forward-delay 15 bridge.stp no bridge.hello-time 2 bridge.priority 128 ipv6.dns  ipv4.dns  bridge.max-age 20
Exited: 10
Executing: nmcli --fields name --terse con show
Exited: 0
Executing: nmcli --fields name --terse con show
Exited: 0
Executing: nmcli con show bridge0 slave 1
Exited: 10
Executing: nmcli con modify bridge0 slave 1 connection.interface-name enx00e04c05510f ipv6.dns-search  connection.master bridge0 ipv4.dns-search  connection.autoconnect yes bridge-port.priority 32 bridge-port.path-cost 100 bridge-port.hairpin-mode yes ipv6.dns  ipv4.dns 
Exited: 10
Executing: nmcli --fields name --terse con show
Exited: 0
```


Discussion:
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 --->
Additional observation: it appears that the module is not able to handle connections with space in the connection profile name. (error code 10)
Dear Maintainer,
 
I have traced this issue to the way the default options are assembled for the ip based connections.
Even when no parameters are set related to IP protocols (in this case ipv6.dns and ipv4.dns), they still get injected into the command line although with no actual values. 

I have tracked the injection to the within update_connection function:
https://github.com/ansible-collections/community.general/blob/47b940fc63d084bf3b62e7f711d9c928e3a7b556/plugins/modules/net_tools/nmcli.py#L905

Although the following loop has a safe-guard not to add options without actual values, it is not effective for the settings that are of list type, which get translated into empty strings and as such pass the "scrutiny" of a safe-guard. 
https://github.com/ansible-collections/community.general/blob/47b940fc63d084bf3b62e7f711d9c928e3a7b556/plugins/modules/net_tools/nmcli.py#L908-L910

The conversion of the non-specified list occurs here: https://github.com/ansible-collections/community.general/blob/47b940fc63d084bf3b62e7f711d9c928e3a7b556/plugins/modules/net_tools/nmcli.py#L770-L772

I see 2 possibilities to solve this issue without going into a deeper redesign of the module:
1. provide more context sensitive safe-guard for empty list (this may affect other connection types, depending on how strictly nmcli implements them.)
2. consider if the bridge-slave really belongs to the IP based connections. My personal opinion(and apparently this is how nmcli sees it itself), is that it should be removed from this property. 

https://github.com/ansible-collections/community.general/blob/47b940fc63d084bf3b62e7f711d9c928e3a7b556/plugins/modules/net_tools/nmcli.py#L779-L791

I have tried the the solution 2 and it results in correct command being generated.

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
@@ -739,7 +739,6 @@ def ip_conn_type(self):
         return self.type in (
             'bond',
             'bridge',
-            'bridge-slave',
             'ethernet',
             'generic',
             'team',


Test patch: