ansible-collections/cisco.nxos

nxos_l2_interfaces : No VLANs can be removed with state 'deleted'

Rico29 opened this issue · 3 comments

SUMMARY

Removing of specific VLAN from trunk layer 2 interface is not possible. see ansible-collections/cisco.ios#698

ISSUE TYPE
  • Bug Report
COMPONENT NAME
cisco.nxos.nxos_l2_interfaces:
ANSIBLE VERSION
2.10.8
COLLECTION VERSION
cisco.nxos           4.0.1  
CONFIGURATION
none
OS / ENVIRONMENT
# cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
STEPS TO REPRODUCE

switch initial config :

LAB(config-if)# show running-config int po 11

!Command: show running-config interface port-channel11
!Running configuration last done at: Thu Dec  8 12:02:06 2022
!Time: Thu Dec  8 12:48:32 2022

version 7.0(3)I7(7) Bios:version 4.5.0 

interface port-channel11
  switchport mode trunk
  switchport trunk allowed vlan 50-52,55
  spanning-tree port type edge trunk
  vpc 11

# cat playbooks/n3k-lab.yml 
- name: test
  hosts: cisco-lab
  gather_facts: true
  tasks:
  - name: Merge provided configuration with device configuration.
    cisco.nxos.nxos_l2_interfaces:
      config:
      - name: port-channel11
        trunk:
          allowed_vlans: 55
      state: deleted

EXPECTED RESULTS

vlan 55 is removed from allowed vlan list

LAB(config-if)# show running-config int po 11

!Command: show running-config interface port-channel11
!Running configuration last done at: Thu Dec  8 12:02:06 2022
!Time: Thu Dec  8 12:48:32 2022

version 7.0(3)I7(7) Bios:version 4.5.0 

interface port-channel11
  switchport mode trunk
  switchport trunk allowed vlan 50-52
  spanning-tree port type edge trunk
  vpc 11

ACTUAL RESULTS

vlan config is removed from interface

LAB(config-if)# show running-config int po 11

!Command: show running-config interface port-channel11
!Running configuration last done at: Thu Dec  8 12:50:28 2022
!Time: Thu Dec  8 12:50:32 2022

version 7.0(3)I7(7) Bios:version 4.5.0 

interface port-channel11
  description vers vers bgp-rtr1-pa3 bond0
  spanning-tree port type edge trunk
  vpc 11

Hey @Rico29,
Looking at your usecase you should be using the replaced state for the configuration you intend to achieve.
We do not encourage granular deletion and most of our modules don't support that.
The deleted state would always try to delete the configuration attributes specified in your playbook.

{
   "after": [
       {
           "name": "port-channel11",
           "trunk": {
               "allowed_vlans": "55"
           }
       },
       {
           "name": "mgmt0"
       }
   ],
   "before": [
       {
           "name": "port-channel11",
           "trunk": {
               "allowed_vlans": "50,51,52,55,66,77"
           }
       },
       {
           "name": "mgmt0"
       }
   ],
   "changed": true,
   "commands": [
       "interface port-channel11",
       "switchport trunk allowed vlan 55"
   ],
   "invocation": {
       "module_args": {
           "config": [
               {
                   "access": null,
                   "mode": null,
                   "name": "port-channel11",
                   "trunk": {
                       "allowed_vlans": "55",
                       "native_vlan": null
                   }
               }
           ],
           "running_config": null,
           "state": "replaced"
       }
   }
}

Whereas, the replaced state would replace the appliance's configuration with the configuration you have provided in your playbook.
Regards

@Rico29 Please let us know if the above comment resolves your issue.