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.
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.
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.
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.
|
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 |
|
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.
|
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 |
|
Object Types |
|
Event Types |
|
Action Type |
|
Webhook |
|
Step 3: Leave the other fields as they are.
Step 4: Click the Create button.
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 |
|
Object Types |
|
Event Types |
|
Action Type |
|
Webhook |
|
Step 10: Leave the other fields as they are.
Step 11: Click the Create button.
|
You’ve now created three event rules that will trigger automation:
|
Task 4: Update NTP Configuration
Check the Current Configuration
|
Before we actually apply changes:
|
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].
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.
Step 4: Click on the NTP updates Job Template to see more details about the job run, then click the Events tab.
Step 5: Now click on the ansible.eda.webhook event. You will see a pop-up with the payload that triggered the rule.
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 |
|
Device Role |
|
Device Type |
|
Site |
|
Status |
|
Platform |
|
Step 5: At the bottom in Custom Fields, fill in:
-
Host:
cisco2 -
Port:
22
Step 6: Click the Create button.
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.
Verify the New Device Configuration
Step 11: To verify, navigate to menu:Automation Execution[Infrastructure > Inventories] → NetBox Dynamic Inventory → Hosts 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.
|
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:
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 If the inventory doesn’t exist: Step 1: First, go to Exercise 2 and create the Step 2: Then, run the following command in the AAP terminal tab:
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:
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:
Step 3: Run the following command to restart NetBox services:
Step 4: Wait 2-3 minutes for the services to fully start, then try accessing NetBox again. |
End of Workshop - Thank You!













