Exercise 5: Event-Driven Ansible Playbooks
Overview
Event-Driven Ansible and Playbooks
In this exercise, we will check two pre-created Job Templates that we will use as part of our Event-Driven Ansible actions. The Job Templates are the usual ones found in Automation Controller, but we are going to use them later in our Ansible Rulebook as the action condition.
Note how the name of each of them matches the one specified in run_job_template in our netbox-webhooks.yml Rulebook.
|
The Job Templates to run in a Rulebook action are defined by their name. Make sure they are unique and always match! |
Key EDA Components
Understanding how the components work together:
-
Event Source — Detects changes (e.g., NetBox updates)
-
Rulebook — Defines conditions and actions
-
Job Template — Specifies the automation workflow
Task 1: Verify "Configure NTP Servers" Job Template
Overview
This Job Template will run when EDA "listens" to an update of the NTP servers configuration from NetBox.
Verify the Job Template
Step 1: In the left sidebar, click on the Automation Execution section to expand it.
Step 2: Navigate to menu:Automation Execution[Templates].
Step 3: Locate and verify that the Job Template called Configure NTP Servers exists in the list.
Step 4: Click on the Configure NTP Servers Job Template to review its configuration.
|
This Job Template is linked to the rulebook action for NTP server updates. When NetBox detects a change to the NTP configuration context, this template will be automatically executed. |
Task 2: Verify "Configure Login Banner" Job Template
Overview
This Job Template will run when EDA "listens" to an update of the Login Banner from NetBox.
Verify the Job Template
Step 1: In the Templates section, locate and verify that the Job Template called Configure Login Banner exists in the list.
Step 2: Click on the Configure Login Banner Job Template to review its configuration.
|
This Job Template is linked to the rulebook action for login banner updates. When NetBox detects a change to the login banner configuration, this template will be automatically executed. |
Understanding the Connection
How Job Templates Connect to Rulebooks
The Job Templates you just verified are directly referenced in your Event-Driven Ansible rulebook. When the rulebook detects an event that matches a condition, it triggers the corresponding Job Template by name.
Example from the Rulebook:
- name: NTP updates
condition: event.payload.event == "updated" and event.payload.model == "configcontext" and event.payload.data.name == "ntp_servers"
action:
run_job_template:
organization: "Default"
name: "Configure NTP Servers"
|
Best Practice: Always ensure that the Job Template names in your rulebook exactly match the names of the Job Templates in Automation Controller. Even minor differences (like extra spaces or capitalization) will prevent the automation from working correctly. |
Summary
In this exercise, you’ve verified that the required Job Templates are in place:
-
Configure NTP Servers - Automatically updates NTP configuration on network devices
-
Configure Login Banner - Automatically updates login banners on network devices
These Job Templates are now ready to be triggered automatically by your Event-Driven Ansible rulebook whenever NetBox detects the corresponding configuration changes.
Next Steps
Congratulations! You’ve verified that the Job Templates needed for Event-Driven Ansible automation are properly configured.
Step 1: Press the Next button below to go to the next challenge.
Troubleshooting
|
NetBox Startup Issues NetBox needs a couple of minutes to get started. If you can’t see the NetBox login screen: 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 Exercise 5
