diff --git a/changelogs/fragments/nxos_l2_interfaces_replaced.yaml b/changelogs/fragments/nxos_l2_interfaces_replaced.yaml new file mode 100644 index 00000000000..ef67e399ec6 --- /dev/null +++ b/changelogs/fragments/nxos_l2_interfaces_replaced.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Fix issue with nxos_l2_interfaces where replaced doesn't remove superfluous config (https://github.com/ansible-collections/cisco.nxos/pull/55) diff --git a/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py b/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py index 707ffd95dbc..6bc3d6cac40 100644 --- a/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py +++ b/lib/ansible/module_utils/network/nxos/config/l2_interfaces/l2_interfaces.py @@ -161,7 +161,7 @@ class L2_interfaces(ConfigBase): del diff[k] replaced_commands = self.del_attribs(diff) - if merged_commands: + if merged_commands or replaced_commands: cmds = set(replaced_commands).intersection(set(merged_commands)) for cmd in cmds: merged_commands.remove(cmd) diff --git a/test/integration/targets/nxos_l2_interfaces/tests/cli/replaced.yaml b/test/integration/targets/nxos_l2_interfaces/tests/cli/replaced.yaml index 275ce8b6e71..764c911f36d 100644 --- a/test/integration/targets/nxos_l2_interfaces/tests/cli/replaced.yaml +++ b/test/integration/targets/nxos_l2_interfaces/tests/cli/replaced.yaml @@ -39,6 +39,10 @@ vlan: 8 trunk: allowed_vlans: "10-12" + + - name: '{{ test_int2 }}' + trunk: + allowed_vlans: 25-27 state: replaced register: result @@ -48,7 +52,9 @@ - "'interface {{ test_int1 }}' in result.commands" - "'switchport access vlan 8' in result.commands" - "'switchport trunk allowed vlan 10,11,12' in result.commands" - - "result.commands|length == 3" + - "'interface {{ test_int2 }}' in result.commands" + - "'no switchport trunk native vlan' in result.commands" + - result.commands|length == 5 - name: Gather l2_interfaces post facts nxos_facts: *facts