Exercise 7: Event-Driven Ansible and NetBox in Action


Overview

Seeing EDA and NetBox Work Together

In this workshop, we’ll see Ansible Event-Driven Automation (EDA) and NetBox in action by making real-time changes to our network. First, we’ll modify an existing device’s configuration in NetBox, triggering Ansible to detect and apply updates automatically. Then, we’ll add a brand-new device, showcasing how Ansible reacts to new inventory entries by running predefined job templates.

This hands-on demonstration will highlight how Ansible EDA eliminates manual intervention, ensuring seamless, automated network management based on real-time changes in NetBox.

Now It’s Time to See Everything in Action!

Step 1: Switch to the NetBox web tab so we can apply changes there.

Step 2: Note that NetBox has been set up with one device called cat1 and all the dependencies that are required for devices to be created.

Step 3: In the next tasks, you will modify a running configuration as well as add a new device.

Lab Environment

The following services are available in your lab environment:

Service Purpose Access Port

AAP

Ansible Automation Platform Web UI

443

NetBox Web

NetBox Web Interface

8000

Terminal

DevTools Command Line

N/A

NetBox Term

NetBox Command Line

N/A

AAP Term

AAP Command Line

N/A

Lab Credentials

Ansible Automation Platform Credentials:

  • Username: admin

  • Password: ansible123!

NetBox Credentials:

  • Username: admin

  • Password: netbox


Task 1: Review NetBox Setup

Explore the Pre-configured Device

Step 1: Ensure you’re on the NetBox web tab.

Step 2: We have configured a Cisco Catalyst 8000v called cat1 with which we will be experimenting. You can check the device in the menu:Devices[Devices] menu of the sidebar.

NetBox Device cat1

Step 3: You will notice in the screenshot above that the cat1 device has a few other fields pre-loaded, like Site, Role, Manufacturer, and Type. These are part of the required fields.

Review Custom Fields

Step 4: Some other data points we had to pre-create were Custom Fields for the ansible_host and ansible_port variables. You can review these in the menu:Customization[Custom Fields] menu of the sidebar.

NetBox Custom Fields

Review Config Contexts

Step 5: Another setting we set in advance are the Config Contexts for the custom data we want to store for the NTP Servers and Login Banner. You can review these in the menu:Provisioning[Config Contexts] menu of the sidebar.

NetBox Config Contexts

Config Contexts in NetBox allow you to store device-specific configuration data that can be consumed by automation tools like Ansible.


Task 2: Configure NetBox Webhooks

Overview

To configure NetBox to send a notification to Ansible Automation Platform when an event happens, you need to set a few options. In this task, you will finish setting up the connection between NetBox and Event-Driven Ansible.

Create the Webhook

Step 1: In the NetBox tab, go to the left sidebar and navigate to menu:Operations[Webhooks].

We will create this first, as it is required for the Event Rules.

Step 2: Once in the Webhooks screen, click the green + Add button on the top right.

Step 3: Fill in the form with the following details:

Field Value

Name

EDA Webhook

URL

`http://control:5001/endpoint'

SSL

Disable the checkbox (unchecked)

Step 4: Leave the other fields as they are.

Step 5: Click the Create button.

Create EDA Webhook

This webhook will forward events from NetBox to your Event-Driven Ansible rulebook activation listening on port 5001.


Task 3: Create NetBox Event Rules

Overview

Now we can go to menu:Operations[Event Rules] to create the three events we want to forward.

Create NTP Servers Event Rule

Step 1: Once in the Event Rules screen, click the green + Add button on the top right.

Step 2: Fill in the form with the following details:

Field Value

Name

ntp_servers

Object Types

Extras > Config Context (TIP: type "context" to filter and auto-complete)

Event Types

Object updated

Action Type

Webhook (leave as is)

Webhook

EDA Webhook (select from the dropdown)

Step 3: Leave the other fields as they are.

Step 4: Click the Create button.

Create ntp_servers Event Rule

Create Login Banner Event Rule

Step 5: Repeat the above steps, but this time for the Name: login_banner event rule.

Step 6: Use the same configuration as the ntp_servers event rule:

  • Object Types: Extras > Config Context

  • Event Types: Object updated

  • Webhook: EDA Webhook

Step 7: Click the Create button.

Create New Device Event Rule

Now we need to create the new_device event rule. This one will be different - pay attention to the steps below:

Step 8: Once in the Event Rules screen, click the green + Add button on the top right.

Step 9: Fill in the form with the following details:

Field Value

Name

new_device

Object Types

DCIM > Device (TIP: type "device" to filter and auto-complete)

Event Types

Object created

Action Type

Webhook (leave as is)

Webhook

EDA Webhook (select from the dropdown)

Step 10: Leave the other fields as they are.

Step 11: Click the Create button.

Create new_device Event Rule

You’ve now created three event rules that will trigger automation:

  • ntp_servers - Triggers when NTP config is updated

  • login_banner - Triggers when login banner is updated

  • new_device - Triggers when a new device is added


Task 4: Update NTP Configuration

Check the Current Configuration

Before we actually apply changes:

  • Did you notice that cat1 had only 2 NTP servers configured and a default banner?

  • If you want to check, go to:

    • AAP tab → menu:Automation Execution[Infrastructure > Inventories] → NetBox Dynamic InventoryHostscat1

Current cat1 Configuration

Modify the NTP Configuration

Step 1: In the NetBox tab, go to the Provisioning menu on the left sidebar and click on Config Contexts.

Step 2: Click on the ntp_servers entry.

Step 3: Click on the orange EDIT button on the top right.

Step 4: Now we are going to modify the Data payload. Add "time-c-g.nist.gov" as shown below:

{
    "ntp_servers": [
        "time-a-g.nist.gov",
        "time-b-g.nist.gov",
        "time-c-g.nist.gov"
    ]
}

Pay attention to the commas! JSON syntax must be correct.

Step 5: Click the Save button.


Task 5: Verify Event-Driven Ansible in Action

Check the Rulebook Activation

Step 1: Switch to the AAP tab.

Step 2: A quick way to see if an event was triggered is to check the Fire count counter in the Rulebook Activations screen within menu:Automation Decisions[Rulebook Activations].

Rulebook Activation Fire Count

Review the Rule Audit

Step 3: For a more detailed output, navigate to menu:Automation Decisions[Rule Audit]. There you will see which Job Template was triggered.

Rule Audit Details

Step 4: Click on the NTP updates Job Template to see more details about the job run, then click the Events tab.

Job Template Events

Step 5: Now click on the ansible.eda.webhook event. You will see a pop-up with the payload that triggered the rule.

Webhook Payload

Check the Job Execution

Step 6: If you want to see the actual Job Template output, navigate to menu:Automation Execution[Jobs] and check the Job queue to see the details.

It might take a few seconds for the event to trigger. If it’s empty, wait a bit and refresh.


Task 6: Update Login Banner Configuration

Your Turn!

Step 1: Switch to the NetBox tab and try updating the login_banner by yourself.

If in doubt, follow the same steps as for the ntp_servers configuration in Task 4.

Step 2: After making changes, verify the automation triggered successfully in the AAP tab.


Task 7: Add a New Device in NetBox

Create the New Device in NetBox

Step 1: Ensure you’re in the NetBox tab.

Step 2: Navigate to menu:Devices[Devices] in the left sidebar.

Step 3: Click the green + Add button on the top right.

Step 4: Fill in the form with the following details:

Field Value

Name

cat2

Device Role

edge-router (from dropdown)

Device Type

cisco-c8000v (from dropdown)

Site

cisco-live-emea (from dropdown)

Status

Active (leave as-is)

Platform

cisco.ios.ios (from dropdown)

Step 5: At the bottom in Custom Fields, fill in:

  • Host: cisco2

  • Port: 22

Step 6: Click the Create button.

Create New Device cat2

Verify Automation in AAP

Step 7: Switch to the AAP tab.

Step 8: Check the Fire count in menu:Automation Decisions[Rulebook Activations].

Step 9: Check the output in menu:Automation Decisions[Rule Audit] and verify that New Device Added was executed successfully.

Step 10: Navigate to menu:Automation Execution[Jobs] and verify the Provision New Device Workflow job run was successful.

Provision New Device Workflow Success

Verify the New Device Configuration

Step 11: To verify, navigate to menu:Automation Execution[Infrastructure > Inventories] → NetBox Dynamic InventoryHosts to see both devices listed.

Step 12: Check the config for cat2 by clicking on it. You will see it has the three NTP servers we configured and your new login banner sourced from NetBox.

cat2 Configuration from NetBox

Congratulations! You’ve just witnessed Event-Driven Ansible automatically provisioning a new device with configurations pulled from NetBox - no manual intervention required!


Summary

In this exercise, you’ve accomplished:

  • Reviewed the NetBox setup including devices, custom fields, and config contexts

  • Created webhooks to connect NetBox with Event-Driven Ansible

  • Configured event rules for NTP updates, login banner updates, and new device creation

  • Modified NTP server configuration and watched automation trigger automatically

  • Updated login banner configuration

  • Added a new device to NetBox and witnessed the complete automated provisioning workflow

You’ve now experienced the full power of Event-Driven Ansible integrated with NetBox as a Source of Truth!


Congratulations!

🎉 You have finished the Event-Driven Ansible and Network Sources of Truth workshop!

You’ve successfully demonstrated how to:

  • Configure NetBox as a Dynamic Inventory source

  • Create and activate Event-Driven Ansible rulebooks

  • Set up webhooks and event rules in NetBox

  • Automatically trigger automation based on network changes

  • Provision new devices with zero manual intervention

This is the future of network automation - event-driven, automated, and efficient!


Troubleshooting

NetBox Worker Issues

If AAP is not showing a Fire count in the Rulebook Activations or you don’t see the jobs in Rule Audit after a while, the NetBox worker might be misbehaving and AAP is not receiving the events.

To diagnose:

Step 1: Check the NetBox web tab. In the left sidebar at the bottom, click menu:Admin[Background Tasks].

Step 2: In the table, if you don’t see any "Workers" listed and running in that column, or the tasks are getting stuck in the "Queue" or "Scheduled" columns, you need to restart the NetBox worker.

To fix:

Step 3: Switch to the netbox term tab.

Step 4: Run the following commands:

docker compose --project-directory=/tmp/netbox-docker stop
docker compose --project-directory=/tmp/netbox-docker up -d netbox netbox-worker

Step 5: Wait 2-3 minutes for the services to fully restart.

Missing Job Templates

For the Job Templates to be pre-created in Exercise 5, the NetBox Dynamic Inventory must exist.

If the inventory doesn’t exist:

Step 1: First, go to Exercise 2 and create the NetBox Dynamic Inventory.

Step 2: Then, run the following command in the AAP terminal tab:

su - rhel -c 'cd /home/rhel; ansible-navigator run /home/rhel/5-eda-playbooks.yml --mode stdout --penv _SANDBOX_ID'

Step 3: Wait for the playbook to complete, then refresh the AAP web interface.

Missing NetBox Pre-loaded Content

For the Dynamic Inventory in Exercise 2 to work, we need some NetBox pre-loaded content.

If you can’t see devices in the NetBox tab:

Step 1: Run the following command:

su - rhel -c 'cd /home/rhel/netbox-setup; ansible-navigator run /home/rhel/netbox-setup/netbox-setup.yml --mode stdout --penv _SANDBOX_ID'

Step 2: Wait for the setup playbook to complete, then refresh the NetBox web interface.

NetBox Startup Issues

NetBox needs a couple of minutes to get started.

If you can’t see the NetBox login screen in the NetBox tab:

Step 1: Go to the netbox term tab.

Step 2: Run the following command to stop NetBox:

docker compose --project-directory=/tmp/netbox-docker stop

Step 3: Run the following command to restart NetBox services:

docker compose --project-directory=/tmp/netbox-docker up -d netbox netbox-worker

Step 4: Wait 2-3 minutes for the services to fully start, then try accessing NetBox again.


End of Workshop - Thank You!