Automate the configuration of automation controller settings using the ansible.controller Ansible content collection and a job template triggered by a webhook.
Outcomes
Configure an existing job template to use a GitLab webhook.
Browse the automation controller API to identify variable names for settings.
Push changes to a Git repository and verify that automation controller launches the job template that applies changes.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that automation controller is installed and configured with any necessary resources created in previous exercises. It also initializes the remote https://git.lab.example.com/git/code_review.git Git repository, which you need for this exercise.
[student@workstation ~]$ lab start code-review
Procedure 8.4. Instructions
The lab start code-review command configured a job template named Apply Controller Settings, which modifies some automation controller settings.
Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password. Verify that the job template exists and configure it to use a GitLab webhook.
Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password.
Navigate to → and verify that is in the list of job templates.
Click the icon for the job template.
Select the checkbox.
In the list, choose , and then click .
Pay attention to the Webhook URL and Webhook Key values generated with this configuration because you use them in the next step.
The values in the and fields on your automation controller differ from the ones shown here. Ensure you use the ones provided by your automation controller.
The https://git.lab.example.com/git/code_review.git Git repository contains the Controller Settings GitLab project that includes a playbook to modify settings for your automation controller. You can log in to the GitLab server as student using Student@123 as the password.
Configure the Controller Settings GitLab project to use the webhook URL and webhook key defined for the Apply Controller Settings job template. The GitLab project should trigger the webhook on push events, and you need to disable SSL verification for it.
In a separate browser window or tab, navigate to https://git.lab.example.com and log in as student using Student@123 as the password.
Click the project, and then navigate to → .
In the field, enter the Webhook URL value generated by automation controller for its Apply Controller Settings job template.
In the field, enter the Webhook Key value generated by automation controller for its Apply Controller Settings job template.
The values in the and fields on your GitLab server must match the values provided by your automation controller, not those shown in the example.
Ensure that you select .
Clear and click when done.
Because the servers in your lab environment are configured with TLS/SSL certificates that are not signed by a certificate authority trusted by the server, SSL verification fails.
If you do not clear the checkbox, it results in the following error message when you try to use the webhook:
Hook execution failed: SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate)
In production, configure the certificates and servers so that SSL verification can be enabled.
Scroll to the bottom of the page. Your webhook is displayed in the Project Hooks list.
(Optional) In the list for the project hook, select to test the webhook configuration. When done, the following message is displayed at the top of the page:
Hook executed successfully: HTTP 202
At https://controller.lab.example.com/api/v2/settings/all/, browse the API settings for your automation controller and identify the name of the variable used to set the maximum number of forks per job. By default, automation controller sets the value of that variable to 200.
Navigate to https://controller.lab.example.com/api/v2/settings/all/. If you have been logged out due to inactivity, log in again as the admin user with redhat as the password.
Scroll down until you find the variable used to set the maximum number of forks per job.
The variable used to set the maximum number of forks per job is MAX_FORKS. Use this variable in the following step.
Change the setting on your automation controller for the maximum number of forks per job to a value of 50. Test the webhook by making that change in your Git repository.
As the student user on the workstation machine, open a terminal window and clone the Git repository located at https://git.lab.example.com/git/code_review.git to the /home/student/git-repos directory. Modify the ~/git-repos/code_review/vars/settings.yml variable file to set the maximum number of forks per job to 50. Save, commit, and push your changes to the remote repository. Use Set maximum forks as your commit message.
From a terminal, create the /home/student/git-repos directory if it does not already exist, and then change into it.
[student@workstation ~]$mkdir -p ~/git-repos/[student@workstation ~]$cd ~/git-repos/
Clone the https://git.lab.example.com/git/code_review.git repository and then change into it:
[student@workstation git-repos]$git clone \>https://git.lab.example.com/git/code_review.gitCloning into 'code_review'... ...output omitted... [student@workstation git-repos]$cd code_review
In the ~/git-repos/code_review/vars/settings.yml variable file, update the controller_settings variable to add a new key-value pair using the previously identified variable name and the new value.
When you have edited it, the ~/git-repos/code_review/vars/settings.yml variable file should contain the following content for the controller_settings variable:
---
controller_settings:
- key: ANSIBLE_FACT_CACHE_TIMEOUT
value: 86400
- key: SESSION_COOKIE_AGE
value: 3600
- key: SESSIONS_PER_USER
value: 2
- key: MAX_FORKS
value: 50Save, commit, and push your changes to the remote repository. Use Set maximum forks for your commit message.
[student@workstation code_review]$git add vars/settings.yml[student@workstation code_review]$git commit -m "Set maximum forks"...output omitted... [student@workstation code_review]$git push...output omitted...
Confirm that the webhook launched the Apply Controller Settings job template when you pushed your changes to the Git repository. From the automation controller web UI, verify that the job was successful and the maximum number of forks per job is now 50.
In the browser window for automation controller, navigate to → .
Click the job. The output shows the change in the configuration for the MAX_FORKS variable.
If you did the optional step 2.8, you get slightly different playbook output than is shown in the following example. This is because the push from the test already changed some variables configured in the settings.yml file.
Navigate to in automation controller.
Under the box select .
In the tab confirm that the value for the maximum number of forks per job is 50.