Exploring the Red Hat Ansible Certified Collection for NetBox – Part One

Earlier this year we announced NetBox Labs collaboration with Red Hat to support and certify the hugely popular NetBox Ansible Collection on RedHat Ansible Automation Platform. This blog post is the first in a four-part series that will take a deep dive into the collection and show how to get the most out of this Network Automation power-pairing.

In this first blog post we will introduce the collection and show how to get started with it. Then in parts two, three and four, we will investigate the three main use cases of the collection, namely:

  • NetBox as a dynamic inventory source for Ansible
  • Using Ansible to define intended network state in NetBox
  • Using Ansible to Query and return data from NetBox

What is the Ansible Certified Collection for NetBox?

The Red Hat Ansible Certified Collection for NetBox is a great proofpoint of the power of the NetBox community we know and love. The collection was first created by Mikhail Yohman in 2019, and more recently has been maintained by Martin Rødvand. The collection has seen contributions from nearly 100 NetBox community members, while becoming a core component for thousands of networking teams that combine NetBox with Ansible to accelerate their network operations. In fact, the NetBox Ansible Content Collection is among the top 5 percent of all Ansible collections by adoption and usage!

The collection consists of Modules to define the intended network state in NetBox, and Plugins to drive automation of the network using data from NetBox. There is now official support from NetBox Labs and Red Hat for customers. The certified and supported collection is available for customers from Red Hat Ansible Automation Hub, with the un-supported version available from Ansible Galaxy.

What is Ansible?

Ansible is an IT framework to configure systems, deploy software, and orchestrate simple to more advanced IT tasks such as continuous deployments. It has an Open Source ecosystem, mostly written in Python and requires Python to run. Ansible is Agentless and supports SSH/NETCONF/API/winrm access to devices. It is simple, using a Human readable declarative language (YAML), plus it’s extensible with Collections, Roles, Modules and Plugins.

You can run Ansible locally on your laptop or on another host server, but the real power comes with the RedHat Ansible Automation Platform. This unified platform breaks down IT silo’s and provides consistent automation and governance for Devs/DevOps, IP Ops, SecOps and Network Ops teams across multiple lines of business, empowering automation across Edge, Cloud and Datacenter networks.

Ansible is also extremely popular as a network automation tool due to its low barrier to entry.

Network Automation Requires a Source of Truth

Network Source of Truth (NSoT) is a representation of the intended configuration and state of the devices, connections, and services of the network. It captures the intended state, which is different than the operational state. It uses a structured, cohesive, comprehensive data model for network intent, that forces completeness and correctness in design, planning, configuration management and operations.

NetBox is the World’s Most Popular Network Source of Truth

NetBox has a comprehensive network data model supporting object types from ASNs through to VPNs, and everything in between. NetBox has a robust API and and is built with an integration first approach – with REST and graphQL interfaces to interact with the database, plus features like Event Streams and Webhooks that allow other systems to act based on events in NetBox. There is massive extensibility with Plugins, Device Types, Custom Scripts, Custom Fields and more, plus there is an enormous ecosystem of tools around NetBox – everything works with it!

A Modern Network Automation Architecture

The Ansible Certified Collection for NetBox allows NetBox and Ansible to integrate seamlessly as part of a modern network automation solution. As you can see from the architecture diagram below, NetBox sits at the heart of the solution as the Network Source of Truth (NSoT), and Ansible lives in the Automation tooling space (bottom-right) and extracts the the intended network state and inventory data from NetBox.

Ansible then automates the deployment of the intended state out to the target network devices as defined in the inventory.

Getting Started with the Red Hat Ansible Certified Collection for NetBox

This guide is based on the Ansible Galaxy installation and shows how to use the collection from the command line, rather than from within Ansible Automation Hub. There is a Git Repository that accompanies this series, which contains all the example code used, so you can easily follow along with the examples. The requirements are as follows:

  • You must be running one of the two most recent releases of NetBox
  • A NetBox write-enabled API token when using modules or a read-only token for the nb_lookup  and nb_inventory plugins.
  • Python 3.10+
  • Python modules:
    • pytz
    • pynetbox
  • Ansible 2.15+

NOTE: This guide assumes you have a working NetBox installation, populated with some device data of your own. The easiest way to do this is to set up a NetBox Cloud Free Plan instance, and you can be up and running in seconds. The NetBox instance used in this example has 2 sites with some devices already added:

Installation and Set Up

1. Clone the Git repo and change into the netbox-ansible-collection-quick-start directory: 

git clone https://github.com/netboxlabs/netbox-learning.git
cd netbox-learning/netbox-ansible-collection-quick-start

2. Create and activate a Python 3 virtual environment:

python3 -m venv ./venv
source venv/bin/activate

3. Install Python Modules and Ansible

pip install pytz
pip install pynetbox
pip install ansible

3. Install the NetBox Ansible Collection. Before using this collection, you need to install it with the Ansible Galaxy command-line tool:

ansible-galaxy collection install netbox.netbox

4. Set environment variables for your NetBox API token and URL of your NetBox instance:

export NETBOX_API=<YOUR_NETBOX_URL> (note - must include http:// or https://)
export NETBOX_TOKEN=<YOUR_NETBOX_API_TOKEN>

Learn More By Attending Our Webinar

That’s it for the set up and for this first blog post in the series. In part two we will explore the first use case – NetBox as a Dynamic Inventory Source for Ansible.

If you want to learn more and see all three use cases in action then register for the upcoming Webinar: Exploring the Red Hat Ansible Certified Collection for NetBox on August 13, 2024 11:00 ET | 15:00 UTC | 17:00 CET.

Share the Post:

Related Posts