Repository: ansible-collections/community.general

Issue:
nmcli bridge not idempotent
### Summary

When configuring a bridge with stp disabled, the bridge's stp priority changes from 32768 to 128 on every run (also the type conversion is broken, but that's more a cosmetic issue).

### Issue Type

Bug Report

### Component Name

nmcli

### Ansible Version

```console (paste below)
$ ansible --version
ansible [core 2.12.5]
  config file = /home/phil/projects/ansible/ansible.cfg
  configured module search path = ['/home/phil/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.10/site-packages/ansible
  ansible collection location = /home/phil/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.4 (main, Mar 25 2022, 00:00:00) [GCC 11.2.1 20220127 (Red Hat 11.2.1-9)]
  jinja version = 3.0.1
  libyaml = True
```


### Community.general Version

```console (paste below)
$ ansible-galaxy collection list community.general
# /home/phil/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 4.8.1
```


### Configuration

```console (paste below)
$ ansible-config dump --only-changed
(empty)
```


### OS / Environment

OracleLinux 8.6

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)
    - community.general.nmcli:
        conn_name: br0 
        ifname: br0 
        type: bridge
        stp: no                                                                                                        
        ip4: '10.0.200.1/24'
        state: present
    - community.general.nmcli:
        conn_name: eth1
        ifname: eth1
        type: bridge-slave
        master: br0 
        hairpin: false
        stp: no
        state: present
```

### Expected Results

no changes on consecutive runs

### Actual Results

```console (paste below)
TASK [community.general.nmcli] ****************************************************************************************
--- before
+++ after
@@ -1,9 +1,9 @@
 {
-    "bridge.ageing-time": "300",
-    "bridge.forward-delay": "15",
-    "bridge.hello-time": "2",
-    "bridge.max-age": "20",
-    "bridge.priority": "32768",
+    "bridge.ageing-time": 300,
+    "bridge.forward-delay": 15,
+    "bridge.hello-time": 2,
+    "bridge.max-age": 20,
+    "bridge.priority": 128,
     "bridge.stp": "no",
     "connection.autoconnect": "yes",
     "connection.interface-name": "br0",
```


### 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 --->
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 --->

Resolving patch:
diff --git a/plugins/modules/nmcli.py b/plugins/modules/nmcli.py
--- a/plugins/modules/nmcli.py
+++ b/plugins/modules/nmcli.py
@@ -1615,6 +1615,10 @@ def connection_options(self, detect_change=False):
                 'bridge.priority': self.priority,
                 'bridge.stp': self.stp,
             })
+            # priority make sense when stp enabed, otherwise nmcli keeps bridge-priority to 32768 regrdless of input.
+            # force ignoring to save idempotency
+            if self.stp:
+                options.update({'bridge.priority': self.priority})
         elif self.type == 'team':
             options.update({
                 'team.runner': self.runner,


Test patch: