Let's review what you have done so far in this Ansible lab section
In this part of the lab you will add leaf3 as a border leaf using the NXOS Power On Auto Provisioning Feature (POAP)
Now you are going to start populating other task files that are included in the roles that you already created to extend the functionality and make the roles more powerful and complete.
The first task will focus on adding a new leaf device to your fabric but this time you are going to use the NXOS Power On Auto Provisioning (POAP) feature. This allows a NXOS device to be powered on and NDFC will automatically discover the device and add it to the fabric.
Later in this lab, leaf3 acting as the border leaf will be used to extend the fabric to an external fabric.
On the keyword press Ctrl + K + W
. This should close all open tabs to clear your workspace for the next section.
roles/add_inventory/tasks/add_fabric_devices_poap.yml
subtask file
Over the next two sections, you will start populating the placeholer files and clearing up the [WARNING]
messages seen when you have been executing your Ansible playbook.
You're going to revisit your add_inventory
role and update the add_fabric_devices_poap.yml
tasks to allow for POAPing switches into the fabric.
Open the add_fabric_devices_poap.yml
file in the roles/add_inventory/tasks
directory.
code-server -r ~/workspace/ndfclab/ansible/roles/add_inventory/tasks/add_fabric_devices_poap.yml
- name: Query Until POAP Switch Becomes Available
cisco.dcnm.dcnm_rest:
method: GET
path: "/appcenter/cisco/ndfc/api/v1/lan-fabric/rest/control/fabrics/{{ fabric_settings.FABRIC_NAME }}/inventory/poap"
register: result
until: result.response.DATA | length > 0
retries: 10
delay: 1
ignore_errors: true
- ansible.builtin.debug:
msg: "Serial Number - {{ result.response.DATA[0].serialNumber }}"
when: result.response.DATA | length > 0
- name: Set Switch Serial Number
ansible.builtin.set_fact:
leaf3_serial_number: "{{ result.response.DATA[0].serialNumber }}"
when: result.response.DATA | length > 0
- name: Add Switches to {{ fabric_settings.FABRIC_NAME }} Using POAP
cisco.dcnm.dcnm_inventory:
fabric: "{{ fabric_settings.FABRIC_NAME }}"
config: >-
{%- set poap_inventory = fabric_inventory | selectattr('poap', 'defined') | list -%}
{%- set _ = poap_inventory[0]['poap'][0].update({'serial_number': leaf3_serial_number}) -%}
{{ poap_inventory }}
state: merged
when: result.response.DATA | length > 0
# This is what the poap_config variable data looks like:
# - seed_ip: 10.15.1.14
# user_name: admin
# password: cisco.123
# role: border
# poap:
# - serial_number: {{ leaf3_serial_number }}
# model: N9K-C9300v
# version: 9.3(8)
# hostname: staging-leaf3
# config_data:
# modulesModel: [N9K-X9364v, N9K-vSUP]
# gateway: 10.15.1.1/24
Take note that the role we are assigning to leaf3 is border since this leaf is a border leaf.
After successfully populating the file above, save the file using Ctrl+s on the Windows keyboard or by clicking File then Save.
Be sure to save your file! Not saving will result in your code not executing.
build_fabric.yml
Ansible PlaybookMake sure you are in the root Ansible directory and execute the bulid_fabric.yml playbook to query NDFC for the new serial number of the device you are adding to the fabric using POAP and then add the device to the fabric.
cd ~/workspace/ndfclab/ansible
From the root ansible project directory execute the following command.
ansible-playbook -i hosts.stage.yml build_fabric.yml --tags ai_poap
You playbook that includes POAP now should be running and look similar to the below:
[WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/create_fabric/tasks/manage_external_fabric.yml is empty and had no tasks to include [WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/add_inventory/tasks/add_fabric_external_devices.yml is empty and had no tasks to include [WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/manage_interfaces/tasks/loopback_interfaces.yml is empty and had no tasks to include [WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/manage_overlay/tasks/resync_fabric.yml is empty and had no tasks to include [WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/manage_overlay/tasks/add_vrf_lite_vrfs.yml is empty and had no tasks to include [WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/manage_overlay/tasks/add_policies.yml is empty and had no tasks to include PLAY [Build VXLAN EVPN Fabric on NDFC] ******************************************************************************************************************************************************************** TASK [add_inventory : ansible.builtin.debug] ************************************************************************************************************************************************************** ok: [10.15.0.98] => { "msg": [ "----------------------------------------------------------------", "+ Calling Role - [add_inventory] +", "----------------------------------------------------------------" ] } TASK [add_inventory : Query Until POAP Switch Becomes Available] ****************************************************************************************************************************************** ok: [10.15.0.98] TASK [add_inventory : ansible.builtin.debug] ************************************************************************************************************************************************************** ok: [10.15.0.98] => { "msg": "Serial Number - 9LYWYN8UWG7" } TASK [add_inventory : Set Switch Serial Number] *********************************************************************************************************************************************************** ok: [10.15.0.98] TASK [add_inventory : Add Switches to fabric-stage Using POAP] ******************************************************************************************************************************************** [WARNING]: Managing fabric switches can take a while. Please be patient...
This add_inventory
role for POAP is doing the following:
Go ahead try the next step while the Ansible Script is running so you can see leaf3 getting added into NDFC.
In NDFC, check the POAP process and switch inventory:
This is another good time for a cup of coffee or tea while the switch is added using POAP!
Upon a successful run of the playbook your output should look as follows:
[WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/create_fabric/tasks/manage_external_fabric.yml is empty and had no tasks to include [WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/add_inventory/tasks/add_fabric_external_devices.yml is empty and had no tasks to include [WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/manage_interfaces/tasks/loopback_interfaces.yml is empty and had no tasks to include [WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/manage_overlay/tasks/resync_fabric.yml is empty and had no tasks to include [WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/manage_overlay/tasks/add_vrf_lite_vrfs.yml is empty and had no tasks to include [WARNING]: file /home/cisco/Documents/ndfclab/ansible/roles/manage_overlay/tasks/add_policies.yml is empty and had no tasks to include PLAY [Build VXLAN EVPN Fabric on NDFC] ******************************************************************************************************************************************************************** TASK [add_inventory : ansible.builtin.debug] ************************************************************************************************************************************************************** ok: [10.15.0.98] => { "msg": [ "----------------------------------------------------------------", "+ Calling Role - [add_inventory] +", "----------------------------------------------------------------" ] } TASK [add_inventory : Query Until POAP Switch Becomes Available] ****************************************************************************************************************************************** ok: [10.15.0.98] TASK [add_inventory : ansible.builtin.debug] ************************************************************************************************************************************************************** ok: [10.15.0.98] => { "msg": "Serial Number - 9LYWYN8UWG7" } TASK [add_inventory : Set Switch Serial Number] *********************************************************************************************************************************************************** ok: [10.15.0.98] TASK [add_inventory : Add Switches to fabric-stage Using POAP] ******************************************************************************************************************************************** [WARNING]: Managing fabric switches can take a while. Please be patient... changed: [10.15.0.98] PLAY RECAP ************************************************************************************************************************************************************************************************ 10.15.0.98 : ok=5 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Take note of the serial number in the Ansible logs after running the last task. This serial number was stored using
the ansible ansible.builtin.set_fact
module and then passed in dynamically to the cisco.dcnm.dcnm_inventory
module to add the leaf3 device using POAP!
You might be tempted to move to the next section but it's important that you wait until the playbook adding the switch with POAP completes.
On the keyword press Ctrl + K + W
. This should close all open tabs to clear your workspace for the next section.
Once complete, move on to the next section to use your new border leaf that you just POAP'd into the fabric to extend the fabric to an external fabric using VRF-Lite.