Develop an Event Driven Ansible Controller Rulebook with Webhook
This topic explains how a rulebook gets triggered in the Event Driven Ansible Controller (EDA) when it receives a Webhook request.
It also describes how to activate a rulebook in EDA and set up a Webhook in GitHub.
Enabling Webhook in GitHub
Before proceeding with the Webhook setup, ensure you have the appropriate (admin or owner) role
for the repository. Select the repository from which you want to receive the Webhook. This setup
uses a repository named ibm-eda-webhook:
-
Select the Settings.

-
Select Code and automation -> Hooks. Click Add webhook.

-
Now provide the Payload URL, for example,
https://eda.example.com:5001, to which you want to receive the payload. Select theapplication/jsonas content type and select the events to which you want to trigger the Webhook and clickAdd webhook.
eda.example.com is resolvable from GitHub. You might need to change
the DNS server setting in your network.
Simulating Webhook with curl
For quick testing you can also use the curl command to create a Webhook request
on EDA.
curl -H 'Content-Type: application/json' -d "{\"message\": \"This is an example message\"}" 127.0.0.1:5001/endpoint
Creating firewall rules in EDA
To allow the Webhook to reach the EDA machine, open port 5001. Run the following
command in EDA:
firewall-cmd --permanent --add-port 5001/tcp
firewall-cmd --reload
Creating the rulebook and connecting with EDA
-
The rulebook in the following sample launches the job template -> ansible KVM guest installation in AAC when it receives a Webhook request from the repository
ibm-eda-webhook.Sample rulebook:- name: Webhook Events hosts: localhost sources: - ansible.eda.webhook: host: 0.0.0.0 port: 5001 rules: - name: Trigger Example Playbook on demand condition: all: - event.payload.repository.name == "ibm-eda-webhook" action: run_job_template: name: ansible kvm guest installation organization: Default
-
Create a new repository called
eda-rulebooksand place the rulebook from step 1 in this repository in the folderrulebooks.
Note: All the rulebooks created should be placed in a directory called rulebooks in their repository for the EDA to detect. -
Go to
EDAto add your GitHub personal access token under Resources -> Credentials for the EDA to access your rulebook git repository, by selectingCreate Credential.-
Provide your
UsernameandToken. -
select
GitHub personal access tokenfromCredential typeand then clickCreate credential.
-
-
Add your rulebook git repository under Resources -> Projects, by selecting
Create Project.-
Provide the
NameandSCM URL. -
Select your git personal access token from the previous step under
Credential, then clickCreate project.
-
-
For the Event Driven Ansible Controller (EDA) to launch a job template in the Ansible Automation Controller (AAC), you need to connect the AAC with the EDA from the controller token generated from AAC.
-
Log in to
AAC, select the Access -> Users. From the Users list select theadmin.
-
Select Tokens -> Add.

-
Provide the Description and select the Scope has Write. Click Save.

-
Copy the Token, it is used in the next step.

-
Log in to EDA, select User Access -> Users. From the Users list, select admin.

-
Select the Controller tokens. Now provide the Name and paste the copied token in Token.
-
Click Create controller token.

-
-
Activate the "eda-rulebook.yml" rulebook by selecting
Create rulebook activationunder Views -> Rulebook Activations.-
Provide the
Name. -
Select your
Projectfrom the previous step from the drop-down. -
Select the
RulebookandDecision Environment. -
Activate your rulebook by clicking
Create rulebook activation
-
Make sure the rulebook is in a
Runningstate after it is created.
-
The Webhook in action
-
Assume that the Webhook gets triggered from the
ibm-eda-webhookrepository. -
GitHub sends the payload to
https://eda.example.com:5001. -
After the payload reaches
https://eda.example.com:5001, it triggers the rulebook in the EDA and theFire countchanges from 0 to 1.
-
Fire countwith a value of 1 triggers thejob template->ansible KVM guest installationin theAACas described in the rulebook underaction.
-
Go to AAC Views -> Jobs. The Ansible KVM guest installation is
successful.