Skip to content

check vPC pair order and map the expected order dynamically#631

Open
ccoueffe wants to merge 1 commit intoCiscoDevNet:developfrom
ccoueffe:dynamically_map_vpc_peer
Open

check vPC pair order and map the expected order dynamically#631
ccoueffe wants to merge 1 commit intoCiscoDevNet:developfrom
ccoueffe:dynamically_map_vpc_peer

Conversation

@ccoueffe
Copy link
Copy Markdown
Collaborator

@ccoueffe ccoueffe commented Feb 2, 2026

When you reverse the order of switches in the playbook configuration and then update interface descriptions (or other properties), the interfaces end up being configured on the opposite vPC member than intended.

The vpc_pair_sn format returned by NDFC is FIXED and ORDERED based on how the vPC pair is configured in NDFC (typically ordered by vPC domain priority, role, or alphabetically by serial number). The format is always PEER1_SERIAL~PEER2_SERIAL.

Example Scenario:
From the test results above:

  • peerOneId: "94WN5222IZ3" (leaf1 @ 10.229.42.121)
  • peerTwoId: "9WOLPXTSUHB" (leaf2 @ 10.229.42.122)
  • serialNumber: "94WN5222IZ3~9WOLPXTSUHB" (NDFC fixed order)

Initial Configuration:

switch: ['10.229.42.122', '10.229.42.121']  # leaf2, leaf1
# vpc_pair_sn returned by NDFC: "94WN5222IZ3~9WOLPXTSUHB"
# NDFC mapping: PEER1 = 94WN5222IZ3 (leaf1), PEER2 = 9WOLPXTSUHB (leaf2)
peer1_members: ['Ethernet1/12']  # User expects this on leaf2 (switch[0])
peer2_members: ['Ethernet1/11']  # User expects this on leaf1 (switch[1])

# BUT ACTUALLY:
# PEER1_MEMBER_INTERFACES: Ethernet1/12 → Goes to 94WN5222IZ3 (leaf1) ❌
# PEER2_MEMBER_INTERFACES: Ethernet1/11 → Goes to 9WOLPXTSUHB (leaf2) ❌

When You Reverse the Order:

switch: ['10.229.42.121', '10.229.42.122']  # leaf1, leaf2 (reversed)
# vpc_pair_sn returned by NDFC: STILL "94WN5222IZ3~9WOLPXTSUHB" (NDFC determines this!)
peer1_members: ['Ethernet1/11']  # User expects this on leaf1 (switch[0])
peer2_members: ['Ethernet1/12']  # User expects this on leaf2 (switch[1])

# BUT ACTUALLY:
# PEER1_MEMBER_INTERFACES: Ethernet1/11 → Still goes to 94WN5222IZ3 (leaf1) ❌
# PEER2_MEMBER_INTERFACES: Ethernet1/12 → Still goes to 9WOLPXTSUHB (leaf2) ❌

The module does NOT verify which switch in your switch: [] list corresponds to PEER1 vs PEER2 according to NDFC's vpc_pair_sn ordering.

Result: When you change the switch order in your playbook, you're essentially swapping which interfaces you think are peer1_members vs peer2_members, but NDFC's PEER1/PEER2 assignment remains fixed to the serial number order.

Solution:

Implement Dynamic Peer Mapping. In function, dcnm_intf_get_vpc_payload we detect members an assign values based on SN.

Playbook

To reproduce issue, create vPC, then update vPC by changing the order. Finally configure vPC interface asymmetric or with description to see the issue.

---
- name: test inventory
  hosts: nac-ndfc1
  gather_facts: false

  tasks:
    - name: Query VPC switch pairs
      cisco.dcnm.dcnm_vpc_pair:
        src_fabric: "nac-ndfc1"
        state: query
        config:
          - peerOneId: 10.229.42.122
            peerTwoId: 10.229.42.121

    - name: Query VPC switch pairs - opposite order
      cisco.dcnm.dcnm_vpc_pair:
        src_fabric: "nac-ndfc1"
        state: query
        config:
          - peerOneId: 10.229.42.121 # 94WN5222IZ3 leaf1
            peerTwoId: 10.229.42.122 # 9WOLPXTSUHB leaf2

    - name: debug vpc11 Interface
      cisco.dcnm.dcnm_interface:
        fabric: "nac-ndfc1"
        state: query
        config:
          - switch:
             - 10.229.42.122 #leaf2 (1/12)
             - 10.229.42.121 #leaf1 (1/11)
            name: vpc11


    - name: update vpc11
      cisco.dcnm.dcnm_interface:
        fabric: "nac-ndfc1"
        state: replaced
        config:
          - name: vpc11
            type: vpc
            switch:
              - 10.229.42.122
              - 10.229.42.121
            deploy: false
            profile:
              admin_state: True
              mode: access
              peer1_pcid: 11
              peer2_pcid: 11
              port_type_fast: True
              mtu: jumbo
              speed: auto
              pc_mode: active
              peer1_members: ["ethernet1/12"]
              peer2_members: ["ethernet1/11"]
              peer1_cmds: |2-
                
              peer2_cmds: |2-
                
              peer1_description: "vPC to Server11"
              peer2_description: "vPC to Server11"
              bpdu_guard: True
              disable_lacp_suspend_individual: False
              enable_lacp_vpc_convergence: False
              lacp_port_priority: 32768
              lacp_rate: normal
              peer1_access_vlan: 1
              peer2_access_vlan: 1

    - name: debug vpc11 Interface
      cisco.dcnm.dcnm_interface:
        fabric: "nac-ndfc1"
        state: query
        config:
          - switch:
             - 10.229.42.122 #leaf2 (1/12)
             - 10.229.42.121 #leaf1 (1/11)
            name: vpc11
PLAY [test inventory] ***********************************************************************************************************************************************************************************************

TASK [Query VPC switch pairs] ***************************************************************************************************************************************************************************************
Monday 02 February 2026  10:15:37 +0100 (0:00:00.049)       0:00:00.049 ******* 
Monday 02 February 2026  10:15:37 +0100 (0:00:00.048)       0:00:00.048 ******* 
ok: [nac-ndfc1] => {"changed": false, "response": [{"nvPairs": {}, "peerOneDbId": 202060, "peerOneId": "94WN5222IZ3", "peerTwoDbId": 204090, "peerTwoId": "9WOLPXTSUHB", "templateName": "", "useVirtualPeerlink": false}]}

TASK [Query VPC switch pairs - opposite order] **********************************************************************************************************************************************************************
Monday 02 February 2026  10:15:42 +0100 (0:00:05.042)       0:00:05.091 ******* 
Monday 02 February 2026  10:15:42 +0100 (0:00:05.042)       0:00:05.091 ******* 
ok: [nac-ndfc1] => {"changed": false, "response": [{"nvPairs": {}, "peerOneDbId": 202060, "peerOneId": "94WN5222IZ3", "peerTwoDbId": 204090, "peerTwoId": "9WOLPXTSUHB", "templateName": "", "useVirtualPeerlink": false}]}

TASK [debug vpc11 Interface] ****************************************************************************************************************************************************************************************
Monday 02 February 2026  10:15:47 +0100 (0:00:04.524)       0:00:09.615 ******* 
Monday 02 February 2026  10:15:47 +0100 (0:00:04.524)       0:00:09.615 ******* 
ok: [nac-ndfc1] => {"changed": false, "response": [{"interfaces": [{"ifName": "vpc11", "nvPairs": {"ADMIN_STATE": "true", "BANDWIDTH": "", "BPDUFILTER_ENABLED": "no", "BPDUGUARD_ENABLED": "true", "CDP_ENABLE": "true", "COPY_DESC": "false", "DISABLE_LACP_SUSPEND": "false", "ENABLE_LACP_VPC_CONV": "false", "ENABLE_MIRROR_CONFIG": "false", "ENABLE_NETFLOW": "false", "ENABLE_PFC": "false", "ENABLE_QOS": "false", "ENABLE_STORM_CONTROL": "false", "FABRIC_NAME": "nac-ndfc1", "INHERIT_BW": "", "INTF_NAME": "vPC11", "LACP_PORT_PRIO": "32768", "LACP_RATE": "normal", "LINK_TYPE": "auto", "MTU": "jumbo", "NEGOTIATE_AUTO": "true", "NETFLOW_MONITOR": "", "NETFLOW_SAMPLER": "", "PC_MODE": "active", "PEER1_ACCESS_VLAN": "1", "PEER1_MEMBER_INTERFACES": "ethernet1/12", "PEER1_PCID": "11", "PEER1_PO_CONF": "", "PEER1_PO_DESC": "vPC to Server11", "PEER2_ACCESS_VLAN": "1", "PEER2_MEMBER_INTERFACES": "ethernet1/11", "PEER2_PCID": "11", "PEER2_PO_CONF": "", "PEER2_PO_DESC": "vPC to Server11", "POLICY_DESC": "", "POLICY_ID": "POLICY-252450", "PORTTYPE_FAST_ENABLED": "true", "PORT_DUPLEX_MODE": "auto", "PRIORITY": "500", "PTP": "false", "QOS_POLICY": "", "QUEUING_POLICY": "", "SERIAL_NUMBER": "", "SPEED": "Auto", "STORM_CONTROL_ACTION": "no", "STORM_CONTROL_BCAST_LEVEL_PERCENT": "", "STORM_CONTROL_BCAST_LEVEL_PPS": "", "STORM_CONTROL_MCAST_LEVEL_PERCENT": "", "STORM_CONTROL_MCAST_LEVEL_PPS": "", "STORM_CONTROL_UCAST_LEVEL_PERCENT": "", "STORM_CONTROL_UCAST_LEVEL_PPS": "", "createVpc": "true"}, "serialNumber": "94WN5222IZ3~9WOLPXTSUHB"}], "policy": "int_vpc_access_host"}]}

TASK [update vpc11] *************************************************************************************************************************************************************************************************
Monday 02 February 2026  10:15:50 +0100 (0:00:02.947)       0:00:12.563 ******* 
Monday 02 February 2026  10:15:50 +0100 (0:00:02.947)       0:00:12.563 ******* 
changed: [nac-ndfc1] => {"changed": true, "response": [{"DATA": {}, "MESSAGE": "OK", "METHOD": "PUT", "REQUEST_PATH": "https://x.x.x.x:443/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/interface", "RETURN_CODE": 200}]}

TASK [debug vpc11 Interface] ****************************************************************************************************************************************************************************************
Monday 02 February 2026  10:15:58 +0100 (0:00:08.627)       0:00:21.190 ******* 
Monday 02 February 2026  10:15:58 +0100 (0:00:08.627)       0:00:21.190 ******* 
ok: [nac-ndfc1] => {"changed": false, "response": [{"interfaces": [{"ifName": "vpc11", "nvPairs": {"ADMIN_STATE": "true", "BANDWIDTH": "", "BPDUFILTER_ENABLED": "no", "BPDUGUARD_ENABLED": "true", "CDP_ENABLE": "true", "COPY_DESC": "false", "DISABLE_LACP_SUSPEND": "false", "ENABLE_LACP_VPC_CONV": "false", "ENABLE_MIRROR_CONFIG": "false", "ENABLE_NETFLOW": "false", "ENABLE_PFC": "false", "ENABLE_QOS": "false", "ENABLE_STORM_CONTROL": "false", "FABRIC_NAME": "nac-ndfc1", "INHERIT_BW": "", "INTF_NAME": "vPC11", "LACP_PORT_PRIO": "32768", "LACP_RATE": "normal", "LINK_TYPE": "auto", "MARK_DELETED": "false", "MTU": "jumbo", "NEGOTIATE_AUTO": "true", "NETFLOW_MONITOR": "", "NETFLOW_SAMPLER": "", "PC_MODE": "active", "PEER1_ACCESS_VLAN": "1", "PEER1_MEMBER_INTERFACES": "ethernet1/11", "PEER1_PCID": "11", "PEER1_PO_CONF": "", "PEER1_PO_DESC": "vPC to Server11", "PEER2_ACCESS_VLAN": "1", "PEER2_MEMBER_INTERFACES": "ethernet1/12", "PEER2_PCID": "11", "PEER2_PO_CONF": "", "PEER2_PO_DESC": "vPC to Server11", "POLICY_DESC": "", "POLICY_ID": "POLICY-252450", "PORTTYPE_FAST_ENABLED": "true", "PORT_DUPLEX_MODE": "auto", "PRIORITY": "500", "PTP": "false", "QOS_POLICY": "", "QUEUING_POLICY": "", "SPEED": "Auto", "STORM_CONTROL_ACTION": "no", "STORM_CONTROL_BCAST_LEVEL_PERCENT": "", "STORM_CONTROL_BCAST_LEVEL_PPS": "", "STORM_CONTROL_MCAST_LEVEL_PERCENT": "", "STORM_CONTROL_MCAST_LEVEL_PPS": "", "STORM_CONTROL_UCAST_LEVEL_PERCENT": "", "STORM_CONTROL_UCAST_LEVEL_PPS": "", "createVpc": "false"}, "serialNumber": "94WN5222IZ3~9WOLPXTSUHB"}], "policy": "int_vpc_access_host"}]}

PLAY RECAP **********************************************************************************************************************************************************************************************************
nac-ndfc1                  : ok=5    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   


PLAYBOOK RECAP ******************************************************************************************************************************************************************************************************
Playbook run took 0 days, 0 hours, 0 minutes, 24 seconds


TASKS RECAP *********************************************************************************************************************************************************************************************************
Monday 02 February 2026  10:16:02 +0100 (0:00:03.481)       0:00:24.672 ******* 
=============================================================================== 
Query VPC switch pairs --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 5.04s
Query VPC switch pairs - opposite order ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- 4.52s
debug vpc11 Interface ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2.95s
update vpc11 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 8.63s
debug vpc11 Interface ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 3.48s

ROLES RECAP *********************************************************************************************************************************************************************************************************
Monday 02 February 2026  10:16:02 +0100 (0:00:03.481)       0:00:24.671 ******* 
=============================================================================== 
cisco.dcnm.dcnm_interface ---------------------------------------------- 15.06s
cisco.dcnm.dcnm_vpc_pair ------------------------------------------------ 9.57s
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
total ------------------------------------------------------------------ 24.62s

@ccoueffe ccoueffe self-assigned this Feb 2, 2026
@ccoueffe ccoueffe marked this pull request as ready for review February 2, 2026 09:49
@ccoueffe ccoueffe added the ready for review PR is ready to be reviewed label Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant