RHCE 9.0 Practice Exam: Installing Software Packages Using Ansible

Expertise in Cloud, Networking & DevOps
Photo by Dmitriy / Unsplash

πŸ“Œ Introduction

In this RHCE 9.0 Ansible exam practice guide, we will install and manage software packages across multiple managed nodes. We will use Ansible’s yum module to install individual packages, package groups, and update all packages.

This guide includes:

  • How to install specific software packages using Ansible
  • How to install package groups using Ansible
  • How to update all installed packages to the latest version
  • How to verify package installations and troubleshoot issues

πŸ’‘ What You Will Learn

βœ… How to use Ansible to install software packages across multiple nodes
βœ… How to install RPM package groups using Ansible
βœ… How to update all installed packages to their latest versions
βœ… How to verify package installations using rpm and yum commands


πŸ“œ 1. Task Requirements

πŸ“ 1.1. Problem Statement

  1. Create an Ansible playbook named /home/greg/ansible/packages.yml to perform the following tasks:
    • Install php and mariadb on all nodes in dev, test, and prod groups.
    • Install the RPM Development Tools package group on all nodes in dev group.
    • Upgrade all installed packages to the latest version on dev group nodes.
  2. Verify that all packages have been installed and updated correctly.

πŸ“œ 2. Preparing the Environment

πŸ“ 2.1. Verify the YUM Module in Ansible

$ ansible-doc -l | grep yum

πŸ“Œ Expected Output:

yum                         Manage packages with the `yum` package manager
yum_repository              Add or remove YUM repositories

βœ… Confirms that the required yum module is available for package management.


πŸ“œ 3. Writing the Ansible Playbook

πŸ“ 3.1. Create the Playbook File

$ vim /home/greg/ansible/packages.yml

πŸ“„ Playbook Breakdown (Step-by-Step)

---
- name: Install PHP and MariaDB
  hosts: dev,test,prod
  become: yes
  tasks:
    - name: Install PHP and MariaDB
      ansible.builtin.yum:
        name:
          - php
          - mariadb
        state: present

- name: Install RPM Development Tools and Upgrade Packages on Dev Nodes
  hosts: dev
  become: yes
  tasks:
    - name: Install RPM Development Tools Group
      ansible.builtin.yum:
        name: "@RPM Development Tools"
        state: present

    - name: Upgrade all installed packages
      ansible.builtin.yum:
        name: '*'
        state: latest

πŸ“Œ Explanation:

  • become: yes β†’ Ensures root privileges for package installation.
  • First Playbook Block (dev, test, prod):
    • Installs php and mariadb on all nodes in dev, test, and prod.
  • Second Playbook Block (dev only):
    • Installs the RPM Development Tools package group.
    • Upgrades all installed packages to the latest version.

πŸ“œ 4. Running the Playbook

$ ansible-navigator run /home/greg/ansible/packages.yml -m stdout

πŸ“Œ Expected Output

PLAY [Install PHP and MariaDB] **************************************************

TASK [Install PHP and MariaDB] *************************************************
changed: [node1]
changed: [node2]
changed: [node3]
changed: [node4]

PLAY [Install RPM Development Tools and Upgrade Packages on Dev Nodes] *********

TASK [Install RPM Development Tools Group] **************************************
changed: [node1]

TASK [Upgrade all installed packages] *******************************************
changed: [node1]

PLAY RECAP **********************************************************************
node1  : ok=3 changed=3 unreachable=0 failed=0
node2  : ok=1 changed=1 unreachable=0 failed=0
node3  : ok=1 changed=1 unreachable=0 failed=0
node4  : ok=1 changed=1 unreachable=0 failed=0

βœ… Confirms that packages were successfully installed and upgraded across nodes.


πŸ“œ 5. Verifying Software Installation

πŸ“ 5.1. Verify Installed Packages

$ ansible dev,test,prod -a 'rpm -q php mariadb'

πŸ“Œ Expected Output:

node1 | CHANGED | rc=0 >>
php-7.4.19-1.el9.x86_64
mariadb-10.5.13-1.el9.x86_64

node2 | CHANGED | rc=0 >>
php-7.4.19-1.el9.x86_64
mariadb-10.5.13-1.el9.x86_64

βœ… Confirms that php and mariadb are installed on all relevant nodes.


πŸ“ 5.2. Verify Installed Package Groups

$ ansible dev -a 'yum grouplist'

πŸ“Œ Expected Output:

Installed Groups:
 RPM Development Tools

βœ… Confirms that RPM Development Tools is installed on dev group nodes.


πŸ“ 5.3. Verify That All Packages Are Upgraded

$ ansible dev -a 'yum update'

πŸ“Œ Expected Output:

...
Nothing to do.

βœ… Confirms that all packages are already up-to-date.


πŸ“œ 6. Common Issues & Troubleshooting

πŸ”΄ Issue 1: No package php available

βœ… Solution:

  • Ensure that the EX294_BASE and EX294_STREAM repositories are enabled.

Verify that the repositories are correctly configured:

$ ansible all -a 'yum repoinfo'

πŸ”΄ Issue 2: Error: Group RPM Development Tools does not exist

βœ… Solution:

  • If missing, enable the required repository.

Verify available package groups using:

$ ansible dev -a 'yum group list'

πŸ”΄ Issue 3: Packages Not Upgrading

βœ… Solution:

If necessary, force package upgrades:

$ ansible dev -m shell -a 'yum -y upgrade'

Check for held packages:

$ ansible dev -a 'yum check-update'

πŸ“œ 7. Summary

  • Created an Ansible playbook (packages.yml) to install and upgrade software packages.
  • Installed php and mariadb on dev, test, and prod nodes.
  • Installed RPM Development Tools on dev nodes.
  • Upgraded all installed packages on dev nodes.
  • Verified package installations using rpm -q and yum grouplist.
  • Troubleshot common package installation and upgrade issues.

πŸš€ Congratulations! You have successfully managed software packages using Ansible for RHCE 9.0! πŸš€
πŸ“’ If you found this guide helpful, share it with your RHCE 9.0 study group! πŸ“’

πŸ”₯ Good luck on your RHCE 9.0 exam! πŸ”₯

Read more