Run a playbook in automation controller that retrieves an Ansible Content Collection by using a requirements file and that uses content in a custom Ansible Content Collection.
Outcomes
Run a playbook on automation controller that uses a customized collection stored on a private automation hub.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command creates the /home/student/builder-use directory and configures automation controller with the following resources:
The Exercise Credential machine credential.
The Git Project Credential source control credential.
The Exercise Inventory resource.
The command also requests a new API token for the private automation hub admin user and updates the relevant automation controller credentials with the new token.
[student@workstation ~]$ lab start builder-use
Procedure 9.4. Instructions
Publish the provided Ansible Content Collection on private automation hub.
Navigate to https://hub.lab.example.com and log in as the student user with redhat123 as the password.
From the private automation hub web UI, navigate to → and then click .
On the page, complete the details as follows and click to create the namespace.
| Field | Value |
|---|---|
exercise
| |
Content Developers
|
The Content Developers group must be a namespace owner for group members, such as the student user, to upload to the namespace.
Click and then .
In the UI, browse to the /home/student/builder-use directory, select the exercise-motd-1.0.0.tar.gz file, and click .
The upload produces the following messages:
Importing with galaxy-importer 0.4.4 Getting doc strings via ansible-doc Finding content inside collection Loading role banner Linting role banner via ansible-lint... CHANGELOG.rst file not found at top level of collection. Collection loading complete Done
A collection can include an optional CHANGELOG.rst file.
It is safe to ignore the message about not being able to find the CHANGELOG.rst file.
After the upload completes, navigate to → and then click .
Create a project from the automation controller web UI.
Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password.
Navigate to → and then click .
Add a new project that installs the exercise.motd collection using a requirements file located in the project.
Use the following information for the project and then click .
| Field | Value |
|---|---|
Install Collection
| |
Default
| |
Git
| |
git@git.lab.example.com:student/use-collection.git
| |
Git Project Credential
|
Wait for the synchronization to complete.
If the synchronization fails, then ensure that you entered the correct source control URL and that the uploaded motd collection has been approved from the private automation hub web UI.
Attempt the project synchronization again.
From the page, click to display details about the project synchronization.
Notice that the job installed collections found in the collections/requirements.yml file.
...output omitted...
TASK [fetch galaxy collections from collections/requirements.(yml/yaml)] *******
changed: [localhost] => (item=/var/lib/awx/projects/_8__install_collection/collections/requirements.yml)
PLAY RECAP *********************************************************************
localhost : ok=4 changed=2 ... failed=0 skipped=2 ...
(Optional) Locate the installed exercise.motd collection on the automation controller server.
Open a terminal and use the ssh command to connect to the controller machine as the awx user.
Display the contents of the /var/lib/awx/projects/.__awx_cache directory.
[student@workstation ~]$ssh awx@controller \>'tree /var/lib/awx/projects/.__awx_cache'/var/lib/awx/projects/.__awx_cache └── _8__install_collection└── 3
├── requirements_collections │ └── ansible_collections
│ ├── exercise
│ │ └── motd
│ │ ├── FILES.json │ │ ├── MANIFEST.json ...output omitted...
Each automation controller project has a unique identification number associated with it.
In this example, the | |
This numbered directory represents the job ID of the automation controller job that performed the project synchronization. Your job ID might be different. | |
The | |
The | |
The |
This step is for information purposes only.
Most developers do not have access to view the /var/lib/awx/projects/.__awx_cache directory on the automation controller server.
Display the existing messages of the day for the servera and serverb machines.
The machines do not display custom messages of the day.
Use the ssh command to connect to the servera machine as the student user.
[student@workstation ~]$ ssh student@servera
Activate the web console with: systemctl enable --now cockpit.socket
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --registerUse the logout command to return to the workstation machine.
[student@servera ~]$ logout
Connection to servera closed.
[student@workstation ~]$Use the ssh command to connect to the serverb machine as the student user.
[student@workstation ~]$ ssh student@serverb
Activate the web console with: systemctl enable --now cockpit.socket
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --registerUse the logout command to return to the workstation machine.
[student@serverb ~]$ logout
Connection to serverb closed.
[student@workstation ~]$Create a job template to run the motd-test.yml playbook from the Install Collection project.
From the automation controller web UI, navigate to → .
On the page, click → . Create a job template using the following information and then click .
| Field | Value |
|---|---|
MOTD Test 1
| |
Test using installed collection
| |
Exercise Inventory
| |
Install Collection
| |
Automation Hub Minimal execution environment
| |
motd-test.yml
| |
Exercise Credential
| |
servera.lab.example.com
|
Click to launch the MOTD Test 1 job template.
The job succeeds and the output indicates that servera.lab.example.com was changed.
...output omitted...
TASK [exercise.motd.banner : Create custom motd banner] ************************
changed: [servera.lab.example.com]
...output omitted...Verify that the servera machine contains an additional message of the day.
Use the ssh command to connect to the servera machine as the student user.
The system displays a message indicating that it is managed by Ansible.
[student@workstation ~]$ ssh student@servera
...output omitted...
================================================================================
================================================================================
== ==
== This system is managed by Ansible. ==
== ==
================================================================================
================================================================================
...output omitted...Use the logout command to return to the workstation machine.
[student@servera ~]$ logout
Connection to servera closed.
[student@workstation ~]$Add a new execution environment resource using the automation controller web UI.
Navigate to → and then click .
Create an execution environment resource using the following information, and then click :
| Field | Value |
|---|---|
MOTD execution environment
| |
hub.lab.example.com/ee-motd-minimal
| |
Only pull the image if not present before running.
| |
Default
| |
Automation Hub Container Registry
|
Add a new automation controller project that uses the exercise.motd collection installed within a custom automation execution environment.
Navigate to → and then click . Create a project resource using the following information, and then click :
| Field | Value |
|---|---|
Use Custom EE
| |
Default
| |
Git
| |
git@git.lab.example.com:student/use-ee.git
| |
Git Project Credential
|
Wait for the synchronization to complete.
If the synchronization fails, then ensure that you entered the correct source control URL and attempt the project synchronization again.
Create a job template to run the motd-test.yml playbook from the Use Custom EE project.
Navigate to → and then click → . Create the job template using the following information:
| Field | Value |
|---|---|
MOTD Test 2
| |
Test using custom EE
| |
Exercise Inventory
| |
Use Custom EE
| |
MOTD execution environment
| |
motd-test.yml
| |
Exercise Credential
| |
message: "My test message"
| |
serverb.lab.example.com
|
The job template selects a specific automation execution environment and only uses one host from the Exercise Inventory resource.
The job template overrides the value of the message variable set in the exercise.motd.banner role.
Click .
Click to launch the MOTD Test 2 job template.
The job succeeds and the output indicates that serverb.lab.example.com was changed.
...output omitted...
TASK [exercise.motd.banner : Create custom motd banner] ************************
changed: [serverb.lab.example.com]
...output omitted...Verify that the serverb machine contains an additional message of the day.
Use the ssh command to connect to the serverb machine as the student user.
The system displays a message using the value of the message variable configured in the MOTD Test 2 job template.
[student@workstation ~]$ ssh student@serverb
...output omitted...
================================================================================
================================================================================
== ==
== My test message ==
== ==
================================================================================
================================================================================
...output omitted...Use the logout command to return to the workstation machine.
[student@serverb ~]$ logout
Connection to serverb closed.
[student@workstation ~]$