Configure ansible-galaxy and use it to install Ansible Content Collections.
Outcomes
Configure various collection sources on a system to install collections.
Install collections with the ansible-galaxy collection command.
Install multiple collections using a requirements.yml file.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command creates an Ansible project in the /home/student/manage-finding/ directory on workstation.
[student@workstation ~]$ lab start manage-finding
Procedure 2.2. Instructions
Browse the Ansible Content Collections available from the classroom's private automation hub.
Access the details for one of the collections that Red Hat provides and supports, ansible.netcommon.
Use a browser to navigate to the private automation hub at https://hub.lab.example.com, and then log in as student using redhat123 as the password.
Navigate to → to browse the Ansible Content Collections.
Because the ansible.netcommon collection is a Red Hat Certified Ansible Content Collection, select from the menu.
Search for the collection by entering netcommon in the search field.
When the search completes, click the tile.
Notice that the UI displays an ansible-galaxy collection install ansible.netcommon command that you can use to install the collection.
Click the tab to access the list of modules and plug-ins available with this collection.
On the workstation machine, configure the Ansible project in the /home/student/manage-finding/ directory so that the ansible-galaxy command retrieves collections from the classroom's private automation hub.
Enable access to the rh-certified and community repositories.
Change to the /home/student/manage-finding/ directory.
[student@workstation ~]$ cd ~/manage-finding/You need to run the ansible-galaxy commands in this exercise from the /home/student/manage-finding/ directory, which contains the Ansible project.
This helps ensure that you use the correct configuration file and install Ansible Content Collections to the correct location.
From the private automation hub web UI, navigate to → .
This page has the parameters that you need for configuring the ansible.cfg file.
Click the icon in the column and the row.
Do not close your web browser window.
You might need to collapse the web UI navigation bar or zoom out in your web browser to see the icon for the column.
Modify the ansible.cfg file to append the lines that you copied to the clipboard in the preceding step.
The modified ansible.cfg file now contains the following content:
[defaults] inventory = ./inventory[galaxy]server_list = rh-certified_repo[galaxy_server.rh-certified_repo]url=https://hub.lab.example.com/api/galaxy/content/rh-certified/token=<put your token here>
Return to the page in the private automation hub web UI. Click the icon in the column and the row.
Do not close your web browser window.
Modify the ansible.cfg file to append the lines that you copied to the clipboard in the preceding step.
The modified ansible.cfg file now contains the following content:
[defaults] inventory = ./inventory [galaxy] server_list = rh-certified_repo [galaxy_server.rh-certified_repo] url=https://hub.lab.example.com/api/galaxy/content/rh-certified/ token=<put your token here>[galaxy]server_list = community_repo[galaxy_server.community_repo]url=https://hub.lab.example.com/api/galaxy/content/community/token=<put your token here>
You added a second [galaxy] section to the file, and there needs to be only one [galaxy] section.
You correct that problem in the next step.
Update the ansible.cfg file so that it only contains one [galaxy] section.
Update the first [galaxy] section so that it lists both repositories, rh-certified_repo and community_repo.
Remove the second [galaxy] section.
The modified ansible.cfg file now contains the following content.
[defaults]
inventory = ./inventory
[galaxy]
server_list = rh-certified_repo, community_repo
[galaxy_server.rh-certified_repo]
url=https://hub.lab.example.com/api/galaxy/content/rh-certified/
token=<put your token here>
[galaxy_server.community_repo]
url=https://hub.lab.example.com/api/galaxy/content/community/
token=<put your token here>Return to the private automation hub web UI. Navigate to → and then click . Copy the API token.
Using the copied token, update both token lines in the ansible.cfg file.
Your token is probably different from the one displayed in this example.
Save and close the file when done.
[defaults] inventory = ./inventory [galaxy] server_list = rh-certified_repo, community_repo [galaxy_server.rh-certified_repo] url=https://hub.lab.example.com/api/galaxy/content/rh-certified/token=c4f21af7090f0f9cb74d3c3f9e1748884ecdc180[galaxy_server.community_repo] url=https://hub.lab.example.com/api/galaxy/content/community/token=c4f21af7090f0f9cb74d3c3f9e1748884ecdc180
Create a collections directory within the project directory, and then install the ansible.netcommon collection into the new directory.
Create the collections directory.
[student@workstation manage-finding]$ mkdir collectionsUse the ansible-galaxy command to install the ansible.netcommon collection into the collections directory.
[student@workstation manage-finding]$ansible-galaxy collection install \>ansible.netcommon -p collections/Starting galaxy collection install process [WARNING]: The specified collections path '/home/student/manage-finding/collections' is not part of the configured Ansible collections paths '/home/student/.ansible/collections:/usr/share/ansible/collections'. The installed collection won't be picked up in an Ansible run. Process install dependency map Starting collection install process Downloading https://hub.lab.example.com/api/galaxy/v3/plugin/ansible/content/rh-certified/collections/artifacts/ansible-netcommon-4.1.0.tar.gz to /home/student/.ansible/tmp/ansible-local-29962sr162r7w/tmprxsyau18/ansible-netcommon-4.1.0-eduihb5k [WARNING]: The GnuPG keyring used for collection signature verification was not configured but signatures were provided by the Galaxy server to verify authenticity. Configure a keyring for ansible-galaxy to use or disable signature verification. Skipping signature verification. Installing 'ansible.netcommon:4.1.0' to '/home/student/manage-finding/collections/ansible_collections/ansible/netcommon' Downloading https://hub.lab.example.com/api/galaxy/v3/plugin/ansible/content/rh-certified/collections/artifacts/ansible-utils-2.8.0.tar.gz to /home/student/.ansible/tmp/ansible-local-29962sr162r7w/tmprxsyau18/ansible-utils-2.8.0-hn1_8a18 ansible.netcommon:4.1.0 was installed successfully Installing 'ansible.utils:2.8.0' to '/home/student/manage-finding/collections/ansible_collections/ansible/utils' ansible.utils:2.8.0 was installed successfully
You might see two WARNING messages in the output that you can safely ignore.
The first one is solved when you configure the collections_paths directive in the next step.
The second warning occurs because the Ansible Galaxy server is providing GnuPG digital signatures that can be used to verify the downloaded content, but your client is not configured to validate those signatures.
The preceding output indicates that the ansible-galaxy command downloaded the collection from https://hub.lab.example.com, the classroom private automation hub.
Notice that the ansible.utils collection is installed automatically as a dependency of the ansible.netcommon collection.
Modify the ansible.cfg file so that it explicitly looks for collections in the project collections directory.
The top of the modified file now contains the following content:
[defaults]
inventory = ./inventory
collections_paths = ./collections:/usr/share/ansible/collections
...output omitted...In the /home/student/manage-finding directory, use the ansible-galaxy command to list the collections installed on the control node that are specified by the current collections_paths directive.
[student@workstation manage-finding]$ ansible-galaxy collection list
# /home/student/manage-finding/collections/ansible_collections
Collection Version
----------------- -------
ansible.netcommon 4.1.0
ansible.utils 2.8.0
# /usr/share/ansible/collections/ansible_collections
Collection Version
------------------------ -------
redhat.rhel_system_roles 1.16.2Although other Ansible Content Collections might be installed on the system, the ansible-galaxy command only lists collections in the directories specified by the collections_paths directive.
The versions of the ansible.netcommon, ansible.utils, and redhat.rhel_system_roles collections installed on your system might be different than the versions displayed here.
Install version 2.1.0 of the redhat.rhv collection.
Make sure that you run ansible-galaxy from a prompt in the Ansible project's /home/student/manage-finding directory.
Because you updated the project's ansible.cfg file to look first for collections in the ./collections directory, you do not need to use the -p option.
[student@workstation manage-finding]$ansible-galaxy collection install \>redhat.rhv:2.1.0...output omitted... Installing 'redhat.rhv:2.1.0' to '/home/student/manage-finding/collections/ansible_collections/redhat/rhv' redhat.rhv:2.1.0 was installed successfully
Install collections specified in a requirements file.
Include the existing ansible.netcommon and redhat.rhv collections, and then add two additional collections, community.crypto and ansible.controller.
Create a file named requirements.yml in the collections directory, and add the following content:
---
collections:
- name: ansible.netcommon
- name: redhat.rhv
version: 2.1.0
- name: community.crypto
version: 2.7.0
- name: ansible.controller
version: 4.2.1Save and close the file when done.
In the /home/student/manage-finding directory, install the collections by using the ansible-galaxy command.
Add the -r option to specify the location of the requirements file.
When you run the command, it skips installing the ansible.netcommon, redhat.rhv, and ansible.utils collections because they are already installed.
[student@workstation manage-finding]$ansible-galaxy collection install \>-r collections/requirements.ymlStarting galaxy collection install process Process install dependency map Starting collection install process Downloading https://hub.lab.example.com/api/galaxy/v3/plugin/ansible/content/community/collections/artifacts/community-crypto-2.7.0.tar.gz to /home/student/.ansible/tmp/ansible-local-32771_upchxep/tmp36d_hwh7/community-crypto-2.7.0-fx5pgw7w 'ansible.netcommon:4.1.0' is already installed, skipping. 'redhat.rhv:2.1.0' is already installed, skipping. 'ansible.utils:2.8.0' is already installed, skipping. Installing 'community.crypto:2.7.0' to '/home/student/manage-finding/collections/ansible_collections/community/crypto' Downloading https://hub.lab.example.com/api/galaxy/v3/plugin/ansible/content/rh-certified/collections/artifacts/ansible-controller-4.2.1.tar.gz to /home/student/.ansible/tmp/ansible-local-32771_upchxep/tmp36d_hwh7/ansible-controller-4.2.1-89anvds8 community.crypto:2.7.0 was installed successfully [WARNING]: The GnuPG keyring used for collection signature verification was not configured but signatures were provided by the Galaxy server to verify authenticity. Configure a keyring for ansible-galaxy to use or disable signature verification. Skipping signature verification. Installing 'ansible.controller:4.2.1' to '/home/student/manage-finding/collections/ansible_collections/ansible/controller' ansible.controller:4.2.1 was installed successfully
In the Ansible project's /home/student/manage-finding directory, list the collections installed on the control node.
[student@workstation manage-finding]$ ansible-galaxy collection list
# /home/student/manage-finding/collections/ansible_collections
Collection Version
------------------ -------
ansible.controller 4.2.1
ansible.netcommon 4.1.0
ansible.utils 2.8.0
community.crypto 2.7.0
redhat.rhv 2.1.0
# /usr/share/ansible/collections/ansible_collections
Collection Version
------------------------ -------
redhat.rhel_system_roles 1.16.2