Configure Event Drive to send Extra Variables to AAP.

What’s in this break-fix?

In this section, you will configure Ansible Automation Platform to receive events from Event-Driven Ansible(Automation Decisions). To be successful in this lab. After sending the curl with the host parameters. You need to run the Jobs Template: rh1-aap-extra-vars-eda

Let’s copy the files:

On node1 let’s list the files in the .ssh/ folder and view your public key.

ssh node1
ls -lha .ssh/
cat .ssh/n66g5key.pub (Change to your ssh pub key)
Output
[lab-user@bastion ~]$ ssh node1
[ec2-user@node1 ~]$ ls -lha .ssh/
total 36K
drwx------.  2 ec2-user ec2-user  157 Nov 26 14:23 .
drwx------. 10 ec2-user ec2-user 4.0K Nov 26 14:05 ..
-rw-------.  1 ec2-user ec2-user 3.1K Nov 26 13:21 authorized_keys
-r--------.  1 ec2-user ec2-user  216 Nov 26 14:02 config
-rw-------.  1 ec2-user ec2-user 2.6K Nov 26 13:47 id_rsa
-rw-------.  1 ec2-user ec2-user  582 Nov 26 13:47 id_rsa.pub
-rw-------.  1 ec2-user ec2-user 1.7K Nov 26 14:23 known_hosts
-rw-------.  1 ec2-user ec2-user  913 Nov 26 14:21 known_hosts.old
-r--------.  1 ec2-user ec2-user 2.6K Nov 26 14:22 n66g5key.pem
-r--------.  1 ec2-user ec2-user  552 Nov 26 14:22 n66g5key.pub
[ec2-user@node1 ~]$ cat .ssh/n66g5key.pub (Change to your ssh pub key)

Copy the contents of the public key and add it to this link. To do this you will need to hold the shift key, and then highlight the key and right click to copy.

You will need to open and log into the GitLab server if you have not done so already.

lab003-add002

Click on add new key and paste the public key into the "Key" box. Give it a title and click "Add key".

lab003-add004
lab003-add005

On node1, pull the rh1-aap-extra-vars-eda repository and copy both folders into rh1-aap-extra-vars-eda:

cd 03-lab/
git clone git@server.example.com:root/rh1-aap-extra-vars-eda.git
cp -rf rh1-eda-example/*  rh1-aap-extra-vars-eda/
Output
[ec2-user@node1 ~]$ cd 03-lab/
[ec2-user@node1 03-lab]$ git clone git@server.example.com:root/rh1-aap-extra-vars-eda.git
[ec2-user@node1 03-lab]$ cp -rf rh1-eda-example/*  rh1-aap-extra-vars-eda/

Change directory to rh1-aap-extra-vars-eda and commit to git:

cd rh1-aap-extra-vars-eda/
git add .
git commit -m "RH1"
git push
Output
[ec2-user@node1 03-lab]$ cd rh1-aap-extra-vars-eda/
[ec2-user@node1 rh1-aap-extra-vars-eda]$ git add .
[ec2-user@node1 rh1-aap-extra-vars-eda]$ git commit -m "RH1"
[ec2-user@node1 rh1-aap-extra-vars-eda]$ git push

Now in Automation Execution(Controller):

If you have not already opened the AAP site, please do so now, the URL is: https://controller.{subdomain_base}/ Let’s log in:

User: admin
Pass: R3dh4t1!

Let’s create the inventory. Select Automation Execution > Infrastructure > Inventories.

To create the inventory we will click on "Create Inventory" in blue.

create-inventory-001

Now click on Create Inventory:

Name: localhost
Organization: Default
lab003-002

Let’s add a host to the inventory. Now click on Hosts

lab003-003

Click on Create hosts:

lab003-004

Name: localhost

Click on create host:

lab003-005

Now with the host created:

lab003-006

Let’s create the hosts ec2-user user credential in AAP:

To create the machine credential in AAP, we need to get the private key from the bastion host.

In the test environment I’m using now it’s: .ssh/vkhtjkey.pem

To validate your private key:
[lab-user@bastion ~]$ ls -lha .ssh/
total 24K
drwx------. 2 lab-user lab-user  102 Nov 19 02:24 .
drwxr-xr-x. 8 lab-user lab-user 4.0K Nov 19 12:41 ..
-rw-------. 1 lab-user lab-user 2.4K Nov 19 13:10 authorized_keys
-r--------. 1 lab-user root      216 Nov 19 01:40 config
-rw-r--r--. 1 lab-user lab-user  374 Nov 19 12:41 known_hosts
-r--------. 1 lab-user root     2.6K Nov 19 01:40 wlffskey.pem
-r--------. 1 lab-user root      552 Nov 19 01:40 wlffskey.pub
[lab-user@bastion ~]$
[lab-user@bastion ~]$ cat .ssh/vkhtjkey.pem

Let’s copy the contents of the private key and create the credential machine:

Name: ec2-user
Organization: Default
credential type: Machine
Username: ec2-user
SSH Private Key: Copy your bastion private key: cat .ssh/vkhtjkey.pem
lab003-009

Confirming that you created the ec2-user user:

lab003-010

Let’s create the gitlab credential:

Name: gitlab
Organization: Default
credential type: Source Control
Username: root
SCM Private Key: Copy your bastion private key: cat .ssh/vkhtjkey.pem
lab003-011

Let’s create the project in AAP to sync the rh1-aap-extra-vars-eda project:

Name: rh1-aap-extra-vars-eda
Organization: Default
credential control type: git
Source control URL: git@server.example.com:root/rh1-aap-extra-vars-eda.git
Source control credential: gitlab
check box:
  Clean
  Delete
  Update revision on launch
lab003-015

Once the project finishes sync’ing, let’s create the job_template in AAP with the project name rh1-aap-extra-vars-eda:

Name: rh1-aap-extra-vars-eda
Inventory: localhost
Project: rh1-aap-extra-vars-eda
Playbook: playbook/hello-rh1.yml
Credentials: ec2-user
lab003-add006

Now in Automation Decisions(EDA) we will create the credential:

Let’s create the credential. Select Automation Decisions > Infrastructure > Credentials > Create credential:

lab003-017

Let’s now add the credential information:

lab003-018
Name: gitlab
Organization: Default
Credential type: Source Control
Username: root
Password: redhat..123

Let’s create the project in EDA:

Click Create Project:

lab003-021

Create the project:

Name: rh1-aap-extra-vars-eda
Organization: Default
Source control type: git
Source control URL: https://server.example.com/root/rh1-aap-extra-vars-eda.git
Source control credential: gitlab
Disable verify SSL: Uncheck
lab003-020
lab003-024
The project does not sync. Find the error and resolve.

Click on Create Credential:

lab003-017
lab003-018

Let’s add:

Name: AAP
Organization: Default
Credential type: Red Hat Ansible Automation Platform
Red Hat Ansible Automation Platform: https://controller.example.com/api/controller/
Username: admin
Password: R3dh4t1!

Click on Create Credential:

lab003-027

Create credential registry Red Hat.

Click in Create Credential in Automation Decisions:

lab003-add007
Name: redhat
Organization: Default
Credential type: Container Registry
authentication URL: registry.redhat.io
username: 1979710|rh1lab20
Password or Token: (The token is located in /home/ec2-user/03-lab/registry-credentials.txt one node1)

Click in Create Credential

lab003-add008

Now, edit Decision Environments:

Click in tree dots.

lab003-add009
lab003-add010

In credential add redhat

lab003-add011

Click on Save Decision Environment

Now let’s create the RuleBook:

Click on Create Rulebook activation:

Name: rh1-aap-extra-vars-eda
Organization: Default
Project: rh1-aap-extra-vars-eda
Rulebook: webhook-example.yml
Credential: AAP
Decision environment: Default Decision Environment
lab003-025
lab003-028

Click on Create rulebook activation

Now in Running:

lab003-032

Let’s click on the rulebook: rh1-aap-extra-vars-eda

lab003-033

Let’s go to History:

lab003-034

Click on the rulebook that is in Running:

lab003-035

Now let’s send the curl to this rulebook:

ssh node1
curl -H 'Content-Type: application/json' -d '{"event_name": "Hello", "host_host": "node1.example.com" }' controller:6000/endpoint

After sending the curl. The Job Template rh1-aap-extra-vars-eda will execute.

You need to resolve this error:
Output
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host localhost port 22: Connection refused", "unreachable": true}

PAUSE


Before moving ahead

Please take a moment to solve the challenge on your own.

The real value of this activity lies in your effort to troubleshoot independently.

Once you have tried, continue to the next section for guided steps to verify your approach or learn an alternate solution.


CONTINUE


Guided solution

  1. Disable host in inventory:

    Go back to the inventory and disable the host:
lab003-006
  1. Remove remote_user: root the playbook hello-rh1.yml.

[ec2-user@node1 ~]$ cd 03-lab/
[ec2-user@node1 03-lab]$ ls
rh1-aap-extra-vars-eda  rh1-eda-example
[ec2-user@node1 03-lab]$ cd rh1-aap-extra-vars-eda/
[ec2-user@node1 rh1-aap-extra-vars-eda]$ ls
playbook  README.md  rulebooks
[ec2-user@node1 rh1-aap-extra-vars-eda]$ vim playbook/hello-rh1.yml

Save the file.

  1. In job_template rh1-aap-extra-vars-eda, enable Prompt on launch in Extra variables.

lab003-add013
  1. Now, send curl command:

    [source,bash]
    ----
    ssh node1
    curl -H 'Content-Type: application/json' -d '{"event_name": "Hello", "host_host": "node1.example.com" }' controller:6000/endpoint
    ----

After sending the curl. The Job Template rh1-aap-extra-vars-eda will execute.