Additional Mission 7: Write an Ansible Playbook to Update Switch Interfaces Based on NetBox Data
In this mission, create an Ansible playbook to update Cisco switch interfaces according to the configuration specified in NetBox. This playbook will ensure that attributes such as adminStatus
, description
, and vlanId
align with the source of truth defined in NetBox.
Step 1: Understand the Requirements
-
Data Source: NetBox holds the desired configuration for switch interfaces.
-
Key Operation: Ensure switch interfaces match configurations from NetBox, focusing on attributes like
adminStatus
,description
, andvlanId
.
Step 2: Set Up Ansible Environment
-
Ansible Inventory : Utilize the inventory setup from previous missions, ensuring it includes all relevant devices .
-
Required Ansible Modules:
netbox.netbox.nb_lookup
: To query NetBox for interface data.cisco.dnac.network_device_info
: To retrieve device information using the Management IP.cisco.dnac.device_interface_info
: To fetch all device interfaces.cisco.dnac.interface_update
: To apply configuration updates to interfaces.
Step 3: Write the Ansible Playbook
-
Retrieve Interface Data from NetBox: Use
netbox.netbox.nb_lookup
to gather current interface details, focusing onadminStatus
,description
, andvlanId
. -
Retrieve Current Interface Data from Switches: Use
cisco.dnac.network_device_info
andcisco.dnac.device_interface_info
to get current configurations from the switches. -
Compare and Update Interfaces:
- Match interfaces from NetBox with those on switches using port names.
- Compare each interface's
adminStatus
,description
, andvlanId
: adminStatus
: Ensure the switch interface is enabled/disabled as per NetBox.description
: Update the interface description to match NetBox.vlanId
: Adjust VLAN settings to reflect NetBox specifications.
-
Apply Updates with Ansible: Use
cisco.dnac.interface_update
to update any interfaces where discrepancies are identified.
Considerations
- Run with Check Mode: Execute the playbook in check mode to simulate the changes and verify its behavior before applying any updates.
- Validation: After running the playbook, verify that both NetBox and switch configurations match.
By completing this mission, you will ensure that your switch interfaces are consistently configured according to the authoritative data in NetBox, maintaining network reliability and accuracy.