Repository: ansible-collections/community.general

Issue:
NMCLI issue with creating a wifi bridge-slave
### Summary

Attempting to create a wifi hotspot as part of a bridge. This is possible using the NMCLI. When attempting to do it using the NMCLI module the slave_type always defaults back to Bond.



### Issue Type

Bug Report

### Component Name

nmcli

### Ansible Version

```console
ansible [core 2.14.5]
  config file = None
  configured module search path = ['/home/rob/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/rob/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/rob/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/rob/.local/bin/ansible
  python version = 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True
```

### Community.general Version

```console
# /usr/local/lib/python3.10/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 7.4.0  

# /usr/lib/python3/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 1.3.6  

# /home/rob/.local/lib/python3.10/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 6.6.0  

# /home/rob/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 7.5.0 
```


### Configuration

```yaml (paste below)

      - name: Create a Bridge Interface connection
        community.general.nmcli:
          type: bridge
          conn_name: br0
          method4: auto
          # ip4: "{{ ip_address }}"
          stp: false
          autoconnect: true
          state: present


      - name: Add Wifi connection profile for Bridge interface br0
        community.general.nmcli:
          type: wifi
          conn_name: br0-hotspot
          slave_type: bridge
          master: br0
          ssid: HotSpot
          wifi:
            mode: ap
          wifi_sec:
            key-mgmt: wpa-psk
            psk: "{{ vault_wifi_psk }}"
          method4: link-local
          autoconnect: false
          state: present
```

not setting the slave_type to bridge. It sets it to bond

### OS / Environment

Host: Pop_OS! 22:04
Target: Ubuntu 22.04.4 server

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->

Bridge setup with DHCP
1 x Ethernet at bridge slave
1 x wifi adaptor setup as bridge slave

Run playbook and check the settings for the connection profile
```console
nmcli connection show br0-hotspot
```
Output shows the slave-type as bond not bridge as defined with the play book




Running the playbook with verbose -vvv shows the following config so it should be setting the slave-type to bridge
```console
ok: [172.25.40.195] => {
    "Exists": "Connections already exist and no changes made",
    "changed": false,
    "conn_name": "br0-hotspot",
    "invocation": {
        "module_args": {
            "addr_gen_mode6": null,
            "ageingtime": 300,
            "arp_interval": null,
            "arp_ip_target": null,
            "autoconnect": false,
            "conn_name": "br0-hotspot",
            "dhcp_client_id": null,
            "dns4": null,
            "dns4_ignore_auto": false,
            "dns4_options": null,
            "dns4_search": null,
            "dns6": null,
            "dns6_ignore_auto": false,
            "dns6_options": null,
            "dns6_search": null,
            "downdelay": null,
            "egress": null,
            "flags": null,
            "forwarddelay": 15,
            "gsm": null,
            "gw4": null,
            "gw4_ignore_auto": false,
            "gw6": null,
            "gw6_ignore_auto": false,
            "hairpin": false,
            "hellotime": 2,
            "ifname": "wlo1",
            "ignore_unsupported_suboptions": false,
            "ingress": null,
            "ip4": null,
            "ip6": null,
            "ip_privacy6": null,
            "ip_tunnel_dev": null,
            "ip_tunnel_input_key": null,
            "ip_tunnel_local": null,
            "ip_tunnel_output_key": null,
            "ip_tunnel_remote": null,
            "mac": null,
            "macvlan": null,
            "master": "br0",
            "maxage": 20,
            "may_fail4": true,
            "method4": "link-local",
            "method6": null,
            "miimon": null,
            "mode": "balance-rr",
            "mtu": null,
            "never_default4": false,
            "path_cost": 100,
            "primary": null,
            "priority": 128,
            "route_metric4": null,
            "route_metric6": null,
            "routes4": null,
            "routes4_extended": null,
            "routes6": null,
            "routes6_extended": null,
            "routing_rules4": null,
            "runner": "roundrobin",
            "runner_fast_rate": null,
            "runner_hwaddr_policy": null,
            "slave_type": "bridge",
            "slavepriority": 32,
            "ssid": "HotSpot",
            "state": "present",
            "stp": true,
            "transport_mode": null,
            "type": "wifi",
            "updelay": null,
            "vlandev": null,
            "vlanid": null,
            "vpn": null,
            "vxlan_id": null,
            "vxlan_local": null,
            "vxlan_remote": null,
            "wifi": {
                "mode": "ap"
            },
            "wifi_sec": {
                "key-mgmt": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "psk": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
            },
            "wireguard": null,
            "xmit_hash_policy": null,
            "zone": null
        }
    },
    "state": "present"
}
```

Implemented the same config using CLI and NMCLI works every time.

```console
-$ sudo nmcli connection add con-name "br0-hotspot" type wifi slave-type bridge master br0 wifi.mode ap wifi.ssid HotSpot wifi-sec.key-mgmt wpa-psk wifi-sec.psk "password-wifi" autoconnect no
```
 
Seems like the slave-type is being ignored and default to bond for wifi.
It also seems to set a interface-name which is not required. nmcli will use the first available interface if not defined. it seems to set the interface name as the same as the connection name





### Expected Results

``` console
~$ nmcli connection show br0-hotspot 
connection.id:                          br0-hotspot
connection.uuid:                        0e2fa599-ba83-4253-ad0e-082e2d0c5fb2
connection.stable-id:                   --
connection.type:                        802-11-wireless
connection.interface-name:              --
connection.autoconnect:                 no
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.multi-connect:               0 (default)
connection.auth-retries:                -1
connection.timestamp:                   0
connection.read-only:                   no
connection.permissions:                 --
connection.zone:                        --
connection.master:                      br0
connection.slave-type:                  bridge
connection.autoconnect-slaves:          -1 (default)
connection.secondaries:                 --
connection.gateway-ping-timeout:        0
connection.metered:                     unknown
connection.lldp:                        default
connection.mdns:                        -1 (default)
connection.llmnr:                       -1 (default)
connection.dns-over-tls:                -1 (default)
connection.wait-device-timeout:         -1
802-11-wireless.ssid:                   HotSpot
802-11-wireless.mode:                   ap
802-11-wireless.band:                   --
802-11-wireless.channel:                0
802-11-wireless.bssid:                  --
802-11-wireless.rate:                   0
802-11-wireless.tx-power:               0
802-11-wireless.mac-address:            --
802-11-wireless.cloned-mac-address:     --
802-11-wireless.generate-mac-address-mask:--
802-11-wireless.mac-address-blacklist:  --
802-11-wireless.mac-address-randomization:default
802-11-wireless.mtu:                    auto
802-11-wireless.seen-bssids:            --
802-11-wireless.hidden:                 no
802-11-wireless.powersave:              0 (default)
802-11-wireless.wake-on-wlan:           0x1 (default)
802-11-wireless.ap-isolation:           -1 (default)
802-11-wireless-security.key-mgmt:      wpa-psk
802-11-wireless-security.wep-tx-keyidx: 0
802-11-wireless-security.auth-alg:      --
802-11-wireless-security.proto:         --
802-11-wireless-security.pairwise:      --
802-11-wireless-security.group:         --
802-11-wireless-security.pmf:           0 (default)
802-11-wireless-security.leap-username: --
802-11-wireless-security.wep-key0:      <hidden>
802-11-wireless-security.wep-key1:      <hidden>
802-11-wireless-security.wep-key2:      <hidden>
802-11-wireless-security.wep-key3:      <hidden>
802-11-wireless-security.wep-key-flags: 0 (none)
802-11-wireless-security.wep-key-type:  unknown
802-11-wireless-security.psk:           <hidden>
802-11-wireless-security.psk-flags:     0 (none)
802-11-wireless-security.leap-password: <hidden>
802-11-wireless-security.leap-password-flags:0 (none)
802-11-wireless-security.wps-method:    0x0 (default)
802-11-wireless-security.fils:          0 (default)
bridge-port.priority:                   32
bridge-port.path-cost:                  100
bridge-port.hairpin-mode:               no
bridge-port.vlans:                      --
```

### Actual Results

```console (paste below)
~$ nmcli connection show br0-hotspot 
connection.id:                          br0-hotspot
connection.uuid:                        5f1710d9-df02-4664-a9d1-d32c0a9bf160
connection.stable-id:                   --
connection.type:                        802-11-wireless
connection.interface-name:              br0-hotspot
connection.autoconnect:                 no
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.multi-connect:               0 (default)
connection.auth-retries:                -1
connection.timestamp:                   0
connection.read-only:                   no
connection.permissions:                 --
connection.zone:                        --
connection.master:                      br0
connection.slave-type:                  bond
connection.autoconnect-slaves:          -1 (default)
connection.secondaries:                 --
connection.gateway-ping-timeout:        0
connection.metered:                     unknown
connection.lldp:                        default
connection.mdns:                        -1 (default)
connection.llmnr:                       -1 (default)
connection.dns-over-tls:                -1 (default)
connection.wait-device-timeout:         -1
802-11-wireless.ssid:                   HotSpot
802-11-wireless.mode:                   ap
802-11-wireless.band:                   --
802-11-wireless.channel:                0
802-11-wireless.bssid:                  --
802-11-wireless.rate:                   0
802-11-wireless.tx-power:               0
802-11-wireless.mac-address:            --
802-11-wireless.cloned-mac-address:     --
802-11-wireless.generate-mac-address-mask:--
802-11-wireless.mac-address-blacklist:  --
802-11-wireless.mac-address-randomization:default
802-11-wireless.mtu:                    auto
802-11-wireless.seen-bssids:            --
802-11-wireless.hidden:                 no
802-11-wireless.powersave:              0 (default)
802-11-wireless.wake-on-wlan:           0x1 (default)
802-11-wireless.ap-isolation:           -1 (default)
802-11-wireless-security.key-mgmt:      wpa-psk
802-11-wireless-security.wep-tx-keyidx: 0
802-11-wireless-security.auth-alg:      --
802-11-wireless-security.proto:         --
802-11-wireless-security.pairwise:      --
802-11-wireless-security.group:         --
802-11-wireless-security.pmf:           0 (default)
802-11-wireless-security.leap-username: --
802-11-wireless-security.wep-key0:      <hidden>
802-11-wireless-security.wep-key1:      <hidden>
802-11-wireless-security.wep-key2:      <hidden>
802-11-wireless-security.wep-key3:      <hidden>
802-11-wireless-security.wep-key-flags: 0 (none)
802-11-wireless-security.wep-key-type:  unknown
802-11-wireless-security.psk:           <hidden>
802-11-wireless-security.psk-flags:     0 (none)
802-11-wireless-security.leap-password: <hidden>
802-11-wireless-security.leap-password-flags:0 (none)
802-11-wireless-security.wps-method:    0x0 (default)
802-11-wireless-security.fils:          0 (default)
bond-port.queue-id:                     0

```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
* [`plugins/modules/nmcli.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/modules/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 --->
Looking at the module file i assume its something do do with this on lines 1819. looks like it uses the default of bond. Regardless of defining it as bridge
nmcli does allow you to define wifi interfaces as part of a bridge

```
        elif self.type == 'wifi':
            options.update({
                '802-11-wireless.ssid': self.ssid,
                'connection.slave-type': 'bond' if self.master else None,
```
Hi, found the same behavior in Raspberry PI OS Bookworm arm64, the wifi has connection.slave-type: bond instead of bridge, thanks

Resolving patch:
diff --git a/plugins/modules/nmcli.py b/plugins/modules/nmcli.py
--- a/plugins/modules/nmcli.py
+++ b/plugins/modules/nmcli.py
@@ -1832,7 +1832,7 @@ def connection_options(self, detect_change=False):
         elif self.type == 'wifi':
             options.update({
                 '802-11-wireless.ssid': self.ssid,
-                'connection.slave-type': 'bond' if self.master else None,
+                'connection.slave-type': ('bond' if self.slave_type is None else self.slave_type) if self.master else None,
             })
             if self.wifi:
                 for name, value in self.wifi.items():


Test patch: