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:

  1. Event Source — Detects changes (e.g., NetBox updates)

  2. Rulebook — Defines conditions and actions

  3. Job Template — Specifies the automation workflow

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

VS Code

Visual Studio Code Editor

80

Terminal

DevTools Command Line

N/A

AAP Terminal

AAP Command Line

N/A

Lab Credentials

Ansible Automation Platform Credentials:

  • Username: admin

  • Password: ansible123!

NetBox Credentials:

  • Username: admin

  • Password: netbox


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.

Job Templates Overview

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:

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 Exercise 5