Integrate Event-Driven Ansible controller with automation controller, import a project containing an Ansible Rulebook, activate a rulebook, and test it by sending some events.
Outcomes
Create a user token in the automation controller web UI.
Create a controller token, a project, and a ruleset activation in the Event-Driven Ansible controller web UI.
Inspect rule audits in the Event-Driven Ansible controller web UI.
As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.
[student@workstation ~]$ lab start controller-configure
Instructions
Create a user token in the automation controller web UI at https://controller.lab.example.com.
An application that uses this token can launch job templates and workflow job templates.
Navigate to https://controller.lab.example.com and log in as admin using redhat as the password.
Click in the upper right and then click .
Click the tab and then click . Create the user token with the following settings and then click .
| Field | Value |
|---|---|
Event-Driven Ansible controller
| |
Write
|
The field is not required. If you leave the field blank, then the user token becomes a personal access token.
Click the icon to copy the displayed token and then close the window.
Create a controller token in the Event-Driven Ansible controller web UI at https://eda-controller.lab.example.com.
This controller token enables rules to launch automation controller jobs by using the run_job_template and run_workflow_template actions.
In a new browser tab, navigate to https://eda-controller.lab.example.com and log in as admin using redhat as the password.
Click in the upper right and then click .
Click the tab and then click . Create the controller token with the following settings and then click .
| Field | Value |
|---|---|
controller.lab.example.com
| |
Token for admin user
| |
| (paste the previously copied token) |
Create a new project.
The project points to an existing Git repository that already contains Ansible Rulebooks in the top-level /rulebooks directory.
If necessary, click the main menu icon at the upper left of the page to display the main menu.
Navigate to and then click . Create the project with the following settings and then click .
| Field | Value |
|---|---|
Baseline
| |
Git
| |
https://git.lab.example.com/student/baseline
| |
Verify SSL
(selected)
|
Because this is a public Git repository in the classroom environment, the project does not require a credential.
After you click , Event-Driven Ansible controller immediately attempts to synchronize the project. Wait until the field displays the status.
Create a rulebook activation that uses an Ansible Rulebook in the Baseline project.
Event-Driven Ansible controller automatically runs any enabled rulebook activation.
If necessary, click the main menu icon at the upper left of the page to display the main menu.
Navigate to and then click . Create the rulebook activation with the following settings and then click .
| Field | Value |
|---|---|
Conform to baseline
| |
Baseline
| |
alertmanager.yml
| |
Automation Hub Default Decision Environment
| |
Always
| |
Enabled
(selected)
|
After you click , Event-Driven Ansible controller immediately attempts to run the rulebook activation. Wait until the field transitions from the to status.
(Optional) Examine components of the exercise configuration. Although this step is not required, you might complete this step to see how the different exercise components work with each other.
From a terminal window, change to the /home/student/git-repos directory and then clone the git@git.lab.example.com:student/baseline Git repository.
After cloning the repository, change to the baseline directory.
[student@workstation ~]$cd ~/git-repos[student@workstation git-repos]$git clone \git@git.lab.example.com:student/baselineCloning into 'baseline'... ...output omitted... [student@workstation git-repos]$cd baseline[student@workstation baseline]$
The student user uses the ~/.ssh/gitlab_rsa SSH key to connect to the Git repository.
Run the tree command to display the contents of the repository.
[student@workstation baseline]$ tree
.
├── playbooks
│ └── alertmanager-baseline-config.yml
└── rulebooks
└── alertmanager.yml
2 directories, 2 filesDisplay the contents of the alertmanager.yml rulebook.
This file is the rulebook used by the Conform to baseline rulebook activation.
---
- name: Capture alertmanager alerts
hosts: localhost
sources:
- ansible.eda.alertmanager:
host: 0.0.0.0
port: 5050
data_alerts_path: alerts
data_host_path: labels.instance
data_path_separator: .
skip_original_data: true
rules:
- name: SELinux was disabled
condition: event.alert.labels.alertname == "selinux disabled" and event.alert.status == "firing"
action:
run_job_template:
name: Apply baseline
organization: Default
job_args:
limit: "{{ event.meta.hosts }}"
...output omitted...The event source plug-in listens for events sent to port | |
This rule applies the | |
By passing the |
Display the contents of the alertmanager-baseline-config.yml playbook.
Although this playbook only contains one task, you might add tasks that apply a baseline configuration to your servers.
---
- name: Baseline config for all servers
hosts: all
tasks:
- name: Enable SELinux
ansible.posix.selinux:
policy: targeted
state: enforcing
become: trueIn a new browser tab, navigate to http://servera.lab.example.com:9090/alerts to display the Prometheus web UI.
A firing alert sends a notification to the Alertmanager pod running on the servera machine.
The alert is currently green, which means that the alert is not in a pending or a firing state.
![]() |
Return to the /home/student directory.
[student@workstation baseline]$ cd
[student@workstation ~]$Generate a problem that Event-Driven Ansible responds to, and then verify that the action resolves the problem.
Connect to servera as the student user.
[student@workstation ~]$ ssh servera
...output omitted...
[student@servera ~]$Use the sestatus command to display the current and persistent SELinux modes.
Both modes indicate that SELinux is running in enforcing mode.
[student@servera ~]$sestatusSELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode:enforcingMode from config file:enforcing...output omitted...
Use the setenforce command to change the current SELinux mode to permissive mode.
This change should ultimately trigger an alert.
[student@servera ~]$sudo setenforce 0[sudo] password for student:student
Use the sestatus command to display the current and persistent SELinux modes.
The setenforce command updated the current mode, but the command did not update the persistent mode.
[student@servera ~]$sestatusSELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode:permissiveMode from config file:enforcing...output omitted...
Return to the browser tab that contains the Event-Driven Ansible web UI. If necessary, click the main menu icon at the upper left of the page to display the main menu.
Navigate to . It might take a few minutes, but you should eventually see two entries in the rule audit list. The first entry () appears when Event-Driven Ansible controller identifies a problem. The second entry () appears when Event-Driven Ansible controller recognizes that the problem has been resolved.
You can proceed with the exercise after you see the entry.
![]() |
Click the entry and then click the tab. You can see that the action displays the status.
![]() |
(Optional) Right-click the link and select .
This link opens the automation controller web UI and displays details about the successful job.
If necessary, log in as admin using redhat as the password.
You might examine the job information displayed on the and tabs.
Use the sestatus command to verify that the current SELinux mode has been restored to use enforcing mode.
[student@servera ~]$sestatusSELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode:enforcingMode from config file: enforcing ...output omitted...
Log out of the servera machine.
[student@servera ~]$ logout
Connection to servera closed.
[student@workstation ~]$