RHCE 9.0 Practice Exam: Installing Ansible Roles Using Ansible Galaxy
π Article Overview
This tutorial is designed for RHCE 9.0 certification candidates and explains how to install Ansible roles using ansible-galaxy
and a requirements file.
π‘ What You Will Learn:
β
How to create and configure requirements.yml
for role installation
β
How to install Ansible roles from a custom URL
β
How to verify installed roles using ansible-galaxy list
β
Troubleshooting common issues
β
Step-by-step guide with realistic command-line output formatting
π 1. Task Requirements
π 1.1. Problem Statement
- Use
Ansible Galaxy
to install two roles from external URLs:- π’
http://classroom/materials/haproxy.tar
, namedbalancer
- π’
http://classroom/materials/phpinfo.tar
, namedphpinfo
- π’
- Install these roles into the directory:
π/home/greg/ansible/roles
- Verify that the roles have been installed correctly
π 2. Preparing the Environment
π 2.1. Verify Ansible Installation
Ensure Ansible is installed on the control node (control
):
$ ansible --version
π Expected Output
ansible [core 2.14.2]
config file = /etc/ansible/ansible.cfg
python version = 3.9.10
If Ansible is missing, install it:
$ sudo yum install -y ansible
π 3. Creating requirements.yml
π 3.1. Open the File in Vim
$ vim /home/greg/ansible/roles/requirements.yml
π Editing requirements.yml
(with Vim Syntax Highlighting)
---
- src: http://classroom/materials/haproxy.tar
name: balancer
- src: http://classroom/materials/phpinfo.tar
name: phpinfo
π Key Points:
src:
β Defines the source URL for each role.name:
β Sets the local role name after installation.
πΎ Save and exit: (ESC
β :wq
)
π 4. Installing Ansible Roles
Run the following command to install the roles into /home/greg/ansible/roles
:
$ ansible-galaxy install -r /home/greg/ansible/roles/requirements.yml
π Expected Terminal Output:
Starting role installation process
=========================================================
Processing requirements from /home/greg/ansible/roles/requirements.yml
---------------------------------------------------------
Downloading http://classroom/materials/haproxy.tar...
β Successfully downloaded to /tmp/haproxy.tar
+ Installing role balancer...
- Extracting package...
- Verifying integrity...
- Deploying role...
- Installed in /home/greg/ansible/roles/balancer
β Installation of balancer completed.
Downloading http://classroom/materials/phpinfo.tar...
β Successfully downloaded to /tmp/phpinfo.tar
+ Installing role phpinfo...
- Extracting package...
- Verifying integrity...
- Deploying role...
- Installed in /home/greg/ansible/roles/phpinfo
β Installation of phpinfo completed.
=========================================================
β
All roles have been installed successfully.
π Key Highlights in the Output:
- Each role is downloaded from the specified URL.
- Installation steps include extraction, verification, and deployment into the target directory.
- Final confirmation message:
"β All roles have been installed successfully."
π 5. Verifying Installed Roles
To confirm the roles are installed, run:
$ ansible-galaxy list
π Expected Terminal Output
# /home/greg/ansible/roles
=========================================================
- balancer, (unknown version)
- phpinfo, (unknown version)
=========================================================
β If the roles appear in the list, the installation was successful!
π 6. Confirming Role Directory Structure
To manually verify the installation, use the tree
command:
$ tree /home/greg/ansible/roles/
π Expected Directory Structure Output
/home/greg/ansible/roles/
βββ balancer
β βββ defaults
β βββ handlers
β βββ tasks
β βββ templates
β βββ vars
β βββ README.md
β βββ meta
β βββ files
β βββ tests
β βββ galaxy.yml
βββ phpinfo
β βββ defaults
β βββ handlers
β βββ tasks
β βββ templates
β βββ vars
β βββ README.md
β βββ meta
β βββ files
β βββ tests
β βββ galaxy.yml
β If the directory structure appears correctly, it confirms successful installation.
π 7. Scoring Criteria
Step | Description | Score |
---|---|---|
1. Create requirements.yml |
Defines roles with correct URLs and names | 5 points |
2. Install roles using ansible-galaxy |
Ensures correct directory installation | 10 points |
3. Verify roles with ansible-galaxy list |
Confirms successful installation | 10 points |
4. Check role directory structure | Ensures roles are correctly placed | 10 points |
β Total Score: 35 points
π 8. Common Issues & Troubleshooting
π΄ Issue 1: Role installation fails
Possible Error:
ERROR! Failed to download role
β Solution: Ensure the URL is accessible:
$ curl -I http://classroom/materials/haproxy.tar
If the file is missing, re-upload it.
π΄ Issue 2: Installed roles do not appear in ansible-galaxy list
β Solution: Check the installation path:
$ ls /home/greg/ansible/roles/
If the directory is missing, reinstall roles:
$ ansible-galaxy install -r /home/greg/ansible/roles/requirements.yml
π΄ Issue 3: How to remove a role?
Run:
$ ansible-galaxy remove <role_name>
For example:
$ ansible-galaxy remove balancer
π Congratulations! You have successfully installed and verified Ansible roles using ansible-galaxy
for RHCE 9.0 certification! π
π’ If you found this guide helpful, share it with your RHCE 9.0 study group! π’
π‘ Final Thoughts
By following this guide, you now have:
- β
A solid understanding of Ansible role management using
ansible-galaxy
. - β
Experience in configuring
requirements.yml
for role installation. - β Knowledge of verifying and troubleshooting installed roles.
Now, you are fully prepared for RHCE 9.0's Ansible role installation task! π―
π₯ Good luck on your RHCE 9.0 exam! π₯