Skip to content

Print Diff for DCNM_Inventory Results, Fix for Issue #90 #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2025

Conversation

AKDRG
Copy link
Collaborator

@AKDRG AKDRG commented Jul 8, 2025

Issue:
#90

Fix:
Add function to read through the create, delete, rma and poap diff and populate the list of dictionaries containing the switches that are modified in the operation corresponding to each type of operation.

Output:

[WARNING]: Managing fabric switches can take a while.  Please be patient...
changed: [ndfc] => {
    "changed": true,
    "diff": [
        {
            "action": "create",
            "switches": [
                {
                    "hostname": "spine",
                    "ip_address": "192.168.1.2",
                    "platform": "N9K-C9300v",
                    "preserve_config": false,
                    "role": "leaf",
                    "serial_number": "1ABCDEF0A12C",
                    "version": "10.3(1)"
                },
                {
                    "hostname": "leaf1",
                    "ip_address": "192.168.1.3",
                    "platform": "N9K-C9300v",
                    "preserve_config": false,
                    "role": "spine",
                    "serial_number": "2ABCDFF0A12C",
                    "version": "10.3(1)"
                }
            ]
        },
     {
            "action": "delete",
            "switches": [
                {
                    "hostname": "leaf1",
                    "ip_address": "192.168.1.3",
                    "platform": "N9K-C9300v",
                    "role": "leaf",
                    "serial_number": "2ABCDFF0A12C",
                    "version": "10.3(1)"
                },
                {
                    "hostname": "spine",
                    "ip_address": "192.168.1.2",
                    "platform": "N9K-C9300v",
                    "role": "spine",
                    "serial_number": "1ABCDEF0A12C",
                    "version": "10.3(1)"
                }
            ]
        }
    ]

@mikewiebe
Copy link
Collaborator

mikewiebe commented Jul 14, 2025

@AKDRG Format looks good overall but I did notice that if I add pre-provisioned switches they get added twice.

Sample Playbook:

    - name: Add NDFC Fabric Devices
      cisco.dcnm.dcnm_inventory:
        fabric: "{{ fabric_name }}"
        config:
          - seed_ip: 10.122.84.57
            auth_proto: MD5
            user_name: admin
            password: password
            max_hops: 0 # this is the default value as it is not defined into the data model
            role: spine
            preserve_config: false
          - seed_ip: 10.122.84.62
            auth_proto: MD5
            user_name: admin
            password: password
            max_hops: 0 # this is the default value as it is not defined into the data model
            role: spine
            preserve_config: false
          - seed_ip: 10.122.84.55
            auth_proto: MD5
            user_name: admin
            password: password
            max_hops: 0 # this is the default value as it is not defined into the data model
            role: leaf
            preserve_config: false
          - seed_ip: 10.122.84.56
            auth_proto: MD5
            user_name: admin
            password: password
            max_hops: 0 # this is the default value as it is not defined into the data model
            role: leaf
            preserve_config: false
          - seed_ip: 10.122.84.58
            auth_proto: MD5
            user_name: admin
            password: password
            max_hops: 0 # this is the default value as it is not defined into the data model
            role: leaf
            preserve_config: false
          - seed_ip: 10.122.84.59
            auth_proto: MD5
            user_name: admin
            password: password
            max_hops: 0 # this is the default value as it is not defined into the data model
            role: leaf
            preserve_config: false
          - seed_ip: 10.122.84.63
            auth_proto: MD5
            user_name: admin
            password: password
            max_hops: 0 # this is the default value as it is not defined into the data model
            role: border
            preserve_config: false
          - seed_ip: 192.168.22.55
            auth_proto: MD5
            user_name: admin
            password: password
            max_hops: 0 # this is the default value as it is not defined into the data model
            role: leaf
            preserve_config: false
            poap:
              - preprovision_serial: 550K4YPFFFF
                model: N9K-C9300v
                version: 15.5(2)
                config_data:
                  modulesModel: ['N9K-X9364v', 'N9K-vSUP']
                  gateway: 192.168.22.1/24
                hostname: preprov-leaf55
          - seed_ip: 192.168.22.56
            auth_proto: MD5
            user_name: admin
            password: idgeR09!
            max_hops: 0 # this is the default value as it is not defined into the data model
            role: leaf
            preserve_config: false
            poap:
              - preprovision_serial: 560K4YPFFFF
                model: N9K-C9300v
                version: 15.5(2)
                config_data:
                  modulesModel: ['N9K-X9364v', 'N9K-vSUP']
                  gateway: 192.168.22.1/24
                hostname: preprov-leaf56
        deploy: false
        save: false
        state: merged
      vars:
        ansible_command_timeout: 3000
        ansible_connect_timeout: 3000

Diff Output

changed: [nac-fabric1] => {
    "changed": true,
    "diff": [
        {
            "action": "create",
            "switches": [
                {
                    "hostname": "netascode-spine1",
                    "ip_address": "10.122.84.57",
                    "platform": "N9K-C9500v",
                    "preserve_config": false,
                    "role": "spine",
                    "serial_number": "99H2TUPCVFK",
                    "version": "10.4(1)"
                },
                {
                    "hostname": "netascode-spine2",
                    "ip_address": "10.122.84.62",
                    "platform": "N9K-C9500v",
                    "preserve_config": false,
                    "role": "spine",
                    "serial_number": "941L30Q8ZYI",
                    "version": "10.4(1)"
                },
                {
                    "hostname": "netascode-leaf1",
                    "ip_address": "10.122.84.55",
                    "platform": "N9K-C9500v",
                    "preserve_config": false,
                    "role": "leaf",
                    "serial_number": "94HIZLNUVCI",
                    "version": "10.4(1)"
                },
                {
                    "hostname": "netascode-leaf2",
                    "ip_address": "10.122.84.56",
                    "platform": "N9K-C9500v",
                    "preserve_config": false,
                    "role": "leaf",
                    "serial_number": "90SRMMW6APK",
                    "version": "10.4(1)"
                },
                {
                    "hostname": "netascode-leaf3",
                    "ip_address": "10.122.84.58",
                    "platform": "N9K-C9500v",
                    "preserve_config": false,
                    "role": "leaf",
                    "serial_number": "9M2TXMZ7D3N",
                    "version": "10.4(1)"
                },
                {
                    "hostname": "netascode-leaf4",
                    "ip_address": "10.122.84.59",
                    "platform": "N9K-C9500v",
                    "preserve_config": false,
                    "role": "leaf",
                    "serial_number": "982YGMKUY2B",
                    "version": "10.4(1)"
                },
                {
                    "hostname": "netascode-border1",
                    "ip_address": "10.122.84.63",
                    "platform": "N9K-C9500v",
                    "preserve_config": false,
                    "role": "border",
                    "serial_number": "9AH5QNPD6XG",
                    "version": "10.4(1)"
                }
            ]
        },
        {
            "hostname": "preprov-leaf55",
            "ip_address": "192.168.22.55",
            "platform": "N9K-C9300v",
            "preprovision_serial": "550K4YPFFFF",
            "role": "leaf",
            "version": "15.5(2)"
        },
        {
            "hostname": "preprov-leaf56",
            "ip_address": "192.168.22.56",
            "platform": "N9K-C9300v",
            "preprovision_serial": "560K4YPFFFF",
            "role": "leaf",
            "version": "15.5(2)"
        },
        {
            "action": "preprovision",
            "preprovision_switches": [
                {
                    "hostname": "preprov-leaf55",
                    "ip_address": "192.168.22.55",
                    "platform": "N9K-C9300v",
                    "preprovision_serial": "550K4YPFFFF",
                    "role": "leaf",
                    "version": "15.5(2)"
                },
                {
                    "hostname": "preprov-leaf56",
                    "ip_address": "192.168.22.56",
                    "platform": "N9K-C9300v",
                    "preprovision_serial": "560K4YPFFFF",
                    "role": "leaf",
                    "version": "15.5(2)"
                }
            ]
        }
    ],

Looks like you are adding here and then again below?

https://github.com/CiscoDevNet/ansible-dcnm/pull/465/files#diff-4f3abb252d10a75703f25b3f9c1d42b4e73289781c5aa15fdf51aa9a7e87f546R1864

Specifically:

for poap in self.want_create_poap:
    item = {...}
    if poap.get("preprovisionSerial"):
        item["preprovision_serial"] = poap.get("preprovisionSerial")
        preprovision_list.append(item)
    diff.append(item)  # <-- This adds the individual item
...
if preprovision_list:
    diff.append({
        "action": "preprovision",
        "preprovision_switches": preprovision_list
    })  # <-- This adds the grouped entry

@mikewiebe mikewiebe self-assigned this Jul 14, 2025
@AKDRG
Copy link
Collaborator Author

AKDRG commented Jul 15, 2025

Hi Mike,
The diff append with the item in POAP and Bootstrap was erroneous and should have not been there, have removed it now. Thank you for catching it!

Thanks,
Akshay

@mikewiebe mikewiebe merged commit dd6da07 into CiscoDevNet:develop Jul 15, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants