Auto Provision Devices with NetBox and Cisco PnP: A Guide
Authors
Michael Schwartzkopff
Be the first to hear news and subscribe here.
Key links
Share
Most administrators still integrate new network devices into the network with the help of the famous blue cable, i.e. console access.
But for lazy administrators all manufacturers offer so-called Zero Touch Provision (ZTP) options, utilizing TFTP servers or the TR069 protocol. Cisco came up with the more modern solution called Cisco Plug-and-Play (Cisco PnP) protocol. With the help of NetBox as source of truth, a DHCP server and a small python application you can set up an environment to auto-provision your Cisco devices.
The setup also is the basis for a setup to manage your network completely based on the NetBox configuration.
Cisco PnP
Cisco describes the modern PnP protocol as an alternative to the old-fashioned to the ZTP process utilizing a TFTP server. The complete setup is implemented i.e. in a Cisco DNA server.
Basically a new device discovers a central provision server by DHCP or DNS or other methods. In our setup I will use the ISC Kea DHCP server to provide the information where to find the provisioning server.
Then the new device connects the server with a HELLO request to check if the server is available. If the server answers with a 200 OK the device accepts the server and periodically requests a WORK-REQUEST from the server. The server answers by sending a new configuration or an update to the operation system.
Using this setup of the central PnP server and the periodic WORK-REQUESTS from the devices, we can set up a complete centralized system to manage all the devices in the network. A central NetBox instance as a Source-of-Truth that provides the configuration of the devices via config_templates is the central component of the setup.
In this article I want to describe the complete setup of such a system of a DHCP server, NetBox and a python flask application as PnP server to achieve the task of a zero touch provisioning of the devices and subsequent centralized management via NetBox.
The DHCP Server
If a new Cisco device is booted without any configuration it requests an IP address via the DHCP protocol. The DHCP server can be utilized to pass additional information to the new device. Especially in option 43 the server can provide information about the PnP server.
I described the setup for a ISC Kea DHCP server in another article already.
If the DHCP client sends the text cisconpnp in the request, the DHCP server adds the information about the PnP server protocol and IP address to the answer.
The PnP Server
In the next step we will set up a PnP server that delivers the configuration to the new device. We use a simple flask application. This setup is based on the work of dmfigol on github.
Please note that I am not a programmer and there are a lot of improvements to the application. As soon as I find time I will upload it to github and take care of the merge requests.
Application Setup
I will describe the flask application in detail on the following sections, so anyone can send improvements. First we have to set up the program:
Next we connect to the NetBox to manage our devices:
The first request of the new device is a HELLO that must be answered with a 200 OK.
All follow up requests of the devices will be POST to the WORK-REQUEST route. Here our work starts.
The idea is to check NetBox, if the device exists and what is the status of the device. Devices are identified by their serial number. If the device does not yet exist, i.e. it is a completely new device, the app will add the new device to NetBox and set its status to provision. Since the device tells the app in the request about its serial number and its device type, it is easy to add it to NetBox. In the simple app I use a fixed device name staging to add the device. More sophisticated setups are welcome.
Now the administrator can configure the new device in NetBox, i.e. setting up the correct device name, the management IP address and VLAN and finally assigning a config template to the device. In the last step the administrator sets the status to staged. Only with this status the app will proceed.
Of course the app also has to take care of the answer of the device. After the device finishes the WORK-REQUEST it sends a WORK-RESPONSE as an answer to the PnP server. The server just acknowledges the reply:
Working Example
The config template in NetBox can be written in Jinja. The following template is inspired by the demonstration of the template capabilities.
If you start your DHCP server and the flask application with
root@host# flask --app main run --host 192.0.2.16 --port 80
and boot your new device you can watch the PnP process the the logs of the device, if you connect to device with the blue cable:
After this process, the device has the correct config and is ready to work.
Please do not hesitate to contact me if you have further questions: Michael Schwartzkopff, ms@sys4.de.