RHCE 9.0 Practice Exam: Installing Ansible Roles Using Ansible Galaxy

RHCE 9.0 Practice Exam: Installing Ansible Roles Using Ansible Galaxy
Photo by Lukas / Unsplash

πŸ“Œ 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

  1. Use Ansible Galaxy to install two roles from external URLs:
    • 🟒 http://classroom/materials/haproxy.tar, named balancer
    • 🟒 http://classroom/materials/phpinfo.tar, named phpinfo
  2. Install these roles into the directory:
    πŸ“‚ /home/greg/ansible/roles
  3. 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! πŸ”₯

Read more