Skip to content

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

  1. Data Source: NetBox holds the desired configuration for switch interfaces.

  2. Key Operation: Ensure switch interfaces match configurations from NetBox, focusing on attributes like adminStatus, description, and vlanId.

Step 2: Set Up Ansible Environment

  1. Ansible Inventory : Utilize the inventory setup from previous missions, ensuring it includes all relevant devices .

  2. 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

  1. Retrieve Interface Data from NetBox: Use netbox.netbox.nb_lookup to gather current interface details, focusing on adminStatus, description, and vlanId.

  2. Retrieve Current Interface Data from Switches: Use cisco.dnac.network_device_info and cisco.dnac.device_interface_info to get current configurations from the switches.

  3. Compare and Update Interfaces:

    • Match interfaces from NetBox with those on switches using port names.
    • Compare each interface's adminStatus, description, and vlanId:
    • 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.
  4. 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.