pod01

Learning Path - Inventory management with NetBox

Implementing a source of truth (SoT) with NetBox is crucial for effective network management and automation.

NetBox serves as a centralized repository that maintains accurate, up-to-date information about your network infrastructure, including IP addresses, devices, and connections.

This centralized approach ensures consistency across the network, reducing the risk of errors associated with manual data handling. By providing a single authoritative source, NetBox enables intent-based automation, allowing the network’s intended state to be defined and validated against its actual state.

This alignment facilitates quick identification and remediation of discrepancies, enhancing operational efficiency and network reliability.

Advantages of Using NetBox as a Source of Truth:

  • Enhanced Data Accuracy: Centralizing network information in NetBox ensures all teams access the same accurate data, minimizing inconsistencies.

  • Streamlined Automation: With a reliable SoT, automation tools can efficiently generate and deploy configurations, accelerating network changes and reducing manual effort.

  • Improved Troubleshooting: Access to a comprehensive and current network model aids in swiftly identifying and resolving issues, reducing downtime.

  • Operational Efficiency: Automated configuration management and zero-touch provisioning become achievable, expediting the deployment of new sites and services.

  • Proactive Drift Management: NetBox helps detect and resolve operational drift by comparing the intended and actual network states, ensuring alignment with organizational standards.

  • Seamless DevOps Integration: Docker containers are easily integrated into DevOps and CI/CD pipelines, streamlining the automation of the deployment process.

  • Support for Microservices Architecture: Docker is particularly well-suited for microservices architecture, as it allows each service to operate in its own container, thereby enhancing flexibility and system resilience.

Step 1: Validate the data

Log in to NetBox with your POD user and click under ‘Devices’. Search for your two devices and explore the options.

The following IP addresses for the Nexus device are created for you:

Device InterfaceIP VRFTenantRole
POD01-N9KV-01vlan100110.0.1.1/24Defaultpod01 
POD01-N9KV-01vlan100110.0.1.11/24Defaultpod01secondary
POD01-N9KV-01Ethernet1/1172.16.1.1/30Defaultpod01 
POD01-N9KV-01mgmt0198.18.1.12/24*managementpod01 

These are the IP addresses for the Catalyst device:

Device InterfaceIP VRFTenant
POD01-CAT8KV-01GigabitEthernet1198.18.1.12/24*managementpod01
POD01-CAT8KV-01GigabitEthernet2172.16.0.1/30Defaultpod01
POD01-CAT8KV-01GigabitEthernet310.0.0.1/24Defaultpod01

We already created all the devices’ interfaces and IP addresses for you in Netbox. Just explore the devices by browsing through the interface as shown in the screenshot below:

Step 2: Check templates and compliance

You might be wondering why we are creating all these interfaces and assigning IP addresses
 — it’s obviously a lot of work, and we can all agree on that.

However, since NetBox serves as our source of truth, we can now generate the full configuration automatically.

Now, you should understand why you created all the interfaces and assigned IP addresses and VLANs.

Check the preconfigured templates we created. Please do not make any changes here!

NetBox uses the Jinja template language to loop through interfaces with conditions.

A tutorial from NetBox is available here: https://netboxlabs.com/blog/how-to-generate-device-configurations-with-netbox/

Here is an example used for interface creation:

django
POD01
1{# Loop Through Interfaces and Configure #}
2{%- for interface in device.interfaces.all() %}
3
4interface {{ interface.name }}
5  {%- if interface.description %}
6  description {{ interface.description }}
7  {%- endif %}
8
9  {%- if interface.ip_addresses.all() %}
10      {%- if interface.vrf and interface.vrf.name != "Default" %}
11  vrf member {{ interface.vrf.name }}
12      {%- endif %}
13      {%- if not interface.name.startswith("vlan") and not interface.name.startswith("mgmt") %}
14  no switchport
15      {%- endif %}
16      {%- for ip in interface.ip_addresses.all() %}
17          {%- if loop.first %}
18  ip address {{ ip.address }}
19          {%- else %}
20  ip address {{ ip.address }} secondary
21          {%- endif %}
22      {%- endfor %}
23  no shutdown
24  {%- elif interface.mode == "access" and interface.untagged_vlan %}
25  switchport access vlan {{ interface.untagged_vlan.vid }}
26  {%- elif interface.mode == "tagged" %}
27  switchport mode trunk
28      {%- for vlan in interface.tagged_vlans.all() %}
29  switchport trunk allowed vlan add {{ vlan.vid }}
30      {%- endfor %}
31  {%- elif "tagged-all" in interface.mode %}
32  switchport mode trunk
33  switchport trunk allowed vlan all
34  {%- endif %}
35
36  {%- if interface.lag %}
37  channel-group {%- for char in interface.lag.name if char.isdigit() %}{{ char }}{% endfor %} mode on
38  {%- endif %}
39
40{%- endfor %}

You could also use the API to create all related items in Netbox but we wanted to make sure that you know how Netbox works and understand the context.

Congratulation🚀! You have implemented a source-of-truth!