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)
[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.
-
URL: https://server.{subdomain_base}/-/user_settings/ssh_keys
-
Username:
root
-
Password:
redhat..123
Click on add new key and paste the public key into the "Key" box. Give it a title and click "Add key".
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/
[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
[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.
Now click on Create Inventory:
Name: localhost
Organization: Default
Let’s add a host to the inventory. Now click on Hosts
Click on Create hosts:
Name: localhost
Click on create host:
Now with the host created:
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
Confirming that you created the ec2-user user:
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
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
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
Now in Automation Decisions(EDA) we will create the credential:
Let’s create the credential. Select Automation Decisions > Infrastructure > Credentials > Create credential:
Let’s now add the credential information:
Name: gitlab
Organization: Default
Credential type: Source Control
Username: root
Password: redhat..123
Let’s create the project in EDA:
Click Create Project:
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
The project does not sync. Find the error and resolve. |
Click on Create Credential:
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:
Create credential registry Red Hat.
Click in Create Credential in Automation Decisions:
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
Now, edit Decision Environments:
Click in tree dots.
In credential add redhat
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
Click on Create rulebook activation
Now in Running:
Let’s click on the rulebook: rh1-aap-extra-vars-eda
Let’s go to History:
Click on the rulebook that is in Running:
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: |
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
Guided solution
-
Disable host in inventory:
Go back to the inventory and disable the host:
-
Remove
remote_user: root
the playbookhello-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.
-
In job_template rh1-aap-extra-vars-eda, enable Prompt on launch in Extra variables.
-
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.