Lab Task 4.2 - Scenario 1 (Nexus Dashboard Fabric Controller)
Cisco Nexus Dashboard Fabric Controller (NDFC) is a comprehensive management tool designed for data center networks. It offers:
- Centralized Management: Simplifies the management of Cisco Nexus data center switches.
- Automation: Automates provisioning, troubleshooting, and policy management.
- Visibility and Monitoring: Provides real-time network insights and analytics.
- Scalability: Supports large-scale data center deployments efficiently.
In this task, you will learn how to create Ansible playbooks and automate Nexus Dashboard Fabric Controller (NDFC).
This task is separated into the following steps:
- Add the switches to the already created Fabric
Step 1: Create folder/file structure
First, you need to create the folder/file structure. Everything marked as a star needs to be created:
1Repository folder pod01 (Folder)
2
3├── ndfc (Folder)
4
5├──── data (Folder)
6
7│ └── 01_add-devices.yaml (*File)
8
9└──── playbooks (Folder)
10
11 └── 01_add-devices.yml (*File)
1201_add-devices.yml
Change in line 13 the path to the fabric (middle part of the URL) and use your POD Number. In cases of adding the switches, we need to rely on the REST module as the inventory module supports mainly BGP EPVN-based fabrics. The BU is working to support all kinds of fabrics.
1---
2- hosts: ndfc_servers
3 gather_facts: false
4 tasks:
5 - name: Load variables
6 ansible.builtin.include_vars:
7 file: ../data/01_add-devices.yaml
8 name: switch_data
9
10 - name: Add devices via REST call to NDFC
11 cisco.dcnm.dcnm_rest:
12 method: POST
13 path: /appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/pod01/inventory/discover?setAndUseDiscoveryCredForLan=false
14 json_data: "{{ item.inventory | from_yaml | to_json }}"
15 with_items: "{{ switch_data.fabric_data.switches }}"01_add-devices.yaml
Build your data model and change the highlighted lines accordingly to your POD. To get the serial number, log in to your NXOS9KV-01 using CML.
Please run show inventory via CLI on both devices to get the serial number and copy&paste it to the data model file.
1---
2fabric_data:
3 switches:
4 - inventory: '{
5 "maxHops": "0",
6 "seedIP": "198.18.1.12",
7 "cdpSecondTimeout": 5,
8 "snmpV3AuthProtocol": 0,
9 "username": "",
10 "password": "",
11 "preserveConfig": true,
12 "discoveryCredForLan": false,
13 "switches": [
14 {
15 "ipaddr": "198.18.1.12",
16 "sysName": "POD01-N9KV-01",
17 "deviceIndex": "POD01-N9KV-01(93575FOI1YA)",
18 "platform": "N9K-C9300v",
19 "version": "10.3(1)",
20 "serialNumber": "93575FOI1YA",
21 "vdcId": 0,
22 "vdcMac": null
23 }
24 ]
25 }'Step 2: Run the pipeline
Adjust the pipeline file and check the validation of the switches and if the switches have been added to NDFC.
.gitlab-ci.yml
1stages:
2 - add_device
3
4add_device:
5 stage: add_device
6 tags:
7 - docker-runner
8 image: cbeye592/ltrato-2600:ndfc
9 id_tokens:
10 VAULT_ID_TOKEN:
11 aud: https://198.18.133.99:8200
12 secrets:
13 ansible_user:
14 vault: NDFC/ansible_user@pod01
15 file: false
16 token: $VAULT_ID_TOKEN
17 ansible_password:
18 vault: NDFC/ansible_password@pod01
19 file: false
20 token: $VAULT_ID_TOKEN
21 DEVICE_USER:
22 vault: NDFC/DEVICE_USER@pod01
23 file: false
24 token: $VAULT_ID_TOKEN
25 DEVICE_PASSWORD:
26 vault: NDFC/DEVICE_PASSWORD@pod01
27 file: false
28 token: $VAULT_ID_TOKEN
29 before_script:
30 - source /root/ansible/bin/activate
31 - chmod -R 700 ndfc
32 - cd ndfc
33 - echo "" >> hosts
34 - echo "ansible_user=$ansible_user" >> hosts
35 - echo "ansible_password=$ansible_password" >> hosts
36 script:
37 - "sed -i 's/\"username\": \"\",/\"username\": \"'${DEVICE_USER}'\",/g' data/01_add-devices.yaml"
38 - "sed -i 's/\"password\": \"\",/\"password\": \"'${DEVICE_PASSWORD}'\",/g' data/01_add-devices.yaml"
39 - ansible-playbook playbooks/01_add-devices.ymlValidation
Log in to NDFC, select your fabric, and choose the switch category to view the device inventory.