In this blog post I will demonstrate a simple NetBox integration that enables Ansible to automate devices managed by a Cisco Catalyst Center Controller. The solution covered here could easily be adapted to work with other controller based networks, such as Meraki and ACI.
Use Case
- Multiple Cisco Catalyst Center controllers managing devices in different regions
- You need to run automation tools targeting devices regardless of which CCC controller they are managed by.
Subscribe to our newsletter for more tutorials like these!
NetBox, Cisco Catalyst Center and Ansible Integration Overview
The four main elements of the integration are as follows:
1 – NetBox Custom Fields
The NetBox data model is extended by adding two Custom Fields to the devices
model. Custom Field 1 is called cisco_catalyst_center
, and is a Selection
type field that maps to the hostname of the Cisco Catalyst Center controller:
The Custom Field makes use of a Choice Set
called Cisco Catalyst Center Hosts
which is a drop-down menu of available Cisco Catalyst Center hosts:
Custom Field 2 is called ccc_device_id
, and is a Text
type field that maps to the device UUID in the Cisco Catalyst Center controller:
2 – Devices Created in NetBox
Devices managed by the Cisco Catalyst Center are manually added to NetBox and the device data includes the custom field values for cisco_catalyst_center
and ccc_device_id
:
3 – NetBox Dynamic Inventory for Ansible
The NetBox Inventory Plugin for Ansible is used to dynamically generate the inventory from NetBox to be used in the Ansible playbook:
# ansible.cfg
[defaults]
inventory = ./netbox_inv.yml
# netbox_inv.yml
plugin: netbox.netbox.nb_inventory
validate_certs: False
group_by:
- device_roles
- sites
4 – Ansible Playbooks
The Ansible playbooks target hosts based on the device_roles
as defined in NetBox and pulled from the dynamic inventory. They contain a set_facts
task to map the values of the ccc_device_id
and cisco_catalyst_center
custom fields to the devices, so they can be used in later tasks per inventory device:
---
- name: Get Device Details From Cisco Catalyst Center
hosts: device_roles_distribution, device_roles_access
tasks:
- name: Set Custom Fields as Facts for Cisco Catalyst Center host and Device UUID
set_fact:
cisco_catalyst_center: "{{ hostvars[inventory_hostname].custom_fields['cisco_catalyst_center'] }}"
ccc_device_id: "{{ hostvars[inventory_hostname].custom_fields['ccc_device_id'] }}"
- name: Get Device Details
uri:
url: "https://{{ cisco_catalyst_center }}/dna/intent/api/v1/network-device/{{ ccc_device_id }}"
method: GET
return_content: yes
validate_certs: no
headers:
Content-Type: "application/json"
x-auth-token: "{{ login_response.json['Token'] }}"
register: device_details
delegate_to: localhost
Wrap Up
So, I hope that this has been a useful overview of how to build a simple NetBox integration that enables Ansible to automate devices managed by a Cisco Catalyst Center Controller. If you’d like try this yourself then you can find full instructions and all the code in the accompanying Git Repository.
Cisco Live EMEA Amsterdam February 5-9 2024
See me present this solution live in person at Cisco Live EMEA, where I’ll also discuss how this simple solution maps to a broader reference architecture for modern network automation that incorporates Source of Truth, Observability, and Automation components, spanning open source and commercial tools from Cisco and others, and how we at NetBox Labs are seeing networking teams starting and progressing in their automation journeys.
Session Type: Cisco U.
Session ID: CISCOU-1014
Session Title: Integrating Cisco Catalyst Center with NetBox and Ansible as part of a modern Network Automation Architecture
Location: Cisco U. Theatre in the Learning and Certification area in The HUB
Date: 06/02/2024
Start Time: 11:30:00 – 12:00:00
Interested in chatting at Cisco Live EMEA? Email info@netboxlabs.com to set up a chat.