RHCE 9.0 Practice Exam: Installing and Configuring Ansible

Expertise in Cloud, Networking & DevOps
Photo by Markus Spiske / Unsplash

πŸ“Œ Introduction

In this RHCE 9.0 Ansible exam practice guide, we will install and configure Ansible on a control node, ensuring that it is correctly set up to manage remote nodes using an inventory file.

This guide includes:

  • How to install Ansible and required dependencies
  • How to create a static inventory file for managing remote hosts
  • How to configure ansible.cfg to define paths and settings
  • How to verify Ansible installation and test connectivity with managed nodes

πŸ’‘ What You Will Learn

βœ… How to install ansible-core and ansible-navigator
βœ… How to create a static inventory file to manage nodes
βœ… How to configure ansible.cfg for roles and collections
βœ… How to verify the installation and check node connectivity


πŸ“œ 1. Task Requirements

πŸ“ 1.1. Problem Statement

  1. Install Ansible on the control node (control).
  2. Set up an inventory file (inventory) in /home/greg/ansible/ with the following host group structure:
    • node1 belongs to the dev host group.
    • node2 belongs to the test host group.
    • node3 and node4 belong to the prod host group.
    • node5 belongs to the balancers host group.
    • The prod group is a child of the webservers group.
  3. Configure the Ansible settings in /home/greg/ansible/ansible.cfg:
    • Set the inventory file to /home/greg/ansible/inventory.
    • Define the roles path as /home/greg/ansible/roles.
    • Define a custom collections path /home/greg/ansible/mycollection.
    • Disable SSH host key checking.
    • Set the default remote user to greg.
    • Enable privilege escalation (become=True).
  4. Verify Ansible installation and ensure all managed nodes can be reached via ping.

πŸ“œ 2. Installing Ansible

πŸ“ 2.1. Connect to the Control Node

$ ssh greg@control

πŸ“Œ Explanation:

  • Logs into the control node (control) where Ansible will be installed.

πŸ“ 2.2. Install Ansible and Required Packages

$ sudo yum -y install ansible-core ansible-navigator

πŸ“Œ Explanation:

  • ansible-core β†’ Provides the core Ansible engine.
  • ansible-navigator β†’ Provides a text-based user interface for running playbooks and managing collections.

πŸ“œ 3. Setting Up Ansible Configuration

πŸ“ 3.1. Create Required Directories

$ mkdir -p /home/greg/ansible/roles
$ mkdir -p /home/greg/ansible/mycollection

πŸ“Œ Explanation:

  • Creates the roles directory for storing Ansible roles.
  • Creates the collections directory for custom Ansible collections.

πŸ“ 3.2. Generate a Default Ansible Configuration

$ ansible-config init --disabled > /home/greg/ansible/ansible.cfg

πŸ“Œ Explanation:

  • Generates a default Ansible configuration file (ansible.cfg) with all settings disabled for customization.

πŸ“ 3.3. Modify the ansible.cfg File

$ vim /home/greg/ansible/ansible.cfg

πŸ“Œ Add the Following Content:

[defaults]
inventory = /home/greg/ansible/inventory
remote_user = greg
host_key_checking = False
roles_path = /home/greg/ansible/roles:/usr/share/ansible/roles
collections_path = /home/greg/ansible/mycollection:.ansible/collections:/usr/share/ansible/collections

[privilege_escalation]
become=True

πŸ“Œ Explanation:

  • inventory = /home/greg/ansible/inventory β†’ Sets the default inventory file.
  • remote_user = greg β†’ Defines greg as the default SSH user.
  • host_key_checking = False β†’ Disables SSH host key checking (prevents prompts).
  • roles_path β†’ Sets role storage paths.
  • collections_path β†’ Defines custom collection storage paths.
  • [privilege_escalation] become=True β†’ Enables privilege escalation (sudo access).

πŸ“œ 4. Creating the Static Inventory File

πŸ“ 4.1. Create and Edit the Inventory File

$ vim /home/greg/ansible/inventory

πŸ“Œ Add the Following Content:

[dev]
node1

[test]
node2

[prod]
node3
node4

[balancers]
node5

[webservers:children]
prod

πŸ“Œ Explanation:

  • Groups nodes into dev, test, prod, and balancers.
  • Defines prod as a child group of webservers.

πŸ“œ 5. Verifying Ansible Installation

πŸ“ 5.1. Check Ansible Version

$ ansible --version

πŸ“Œ Expected Output:

ansible [core 2.14.0]
  config file = /home/greg/ansible/ansible.cfg
  python version = 3.9.10

βœ… Ensures that Ansible is installed and configured correctly.


πŸ“ 5.2. Verify Inventory File

$ ansible-inventory --graph

πŸ“Œ Expected Output:

@all:
  |--@balancers:
  |  |--node5
  |--@dev:
  |  |--node1
  |--@prod:
  |  |--node3
  |  |--node4
  |--@test:
  |  |--node2
  |--@webservers:
  |  |--node3
  |  |--node4

βœ… Ensures that the inventory file is correctly structured.


πŸ“ 5.3. Test Connectivity to Managed Nodes

$ ansible all -m ping

πŸ“Œ Expected Output:

node1 | SUCCESS => {
    "ping": "pong"
}
node2 | SUCCESS => {
    "ping": "pong"
}
node3 | SUCCESS => {
    "ping": "pong"
}
node4 | SUCCESS => {
    "ping": "pong"
}
node5 | SUCCESS => {
    "ping": "pong"
}

βœ… Confirms that all nodes are reachable and correctly configured.


πŸ“œ 6. Configuring Podman & Collection Verification

πŸ“ 6.1. Authenticate with the Podman Registry

$ podman login utility.lab.example.com -u admin -p redhat

πŸ“Œ Ensures Podman is correctly set up for running Ansible automation inside containers.


πŸ“ 6.2. Verify Available Ansible Images

$ ansible-navigator images

πŸ“Œ Expected Output:
Displays the available container images for Ansible execution environments.


πŸ“ 6.3. Verify Installed Collections

$ ansible-navigator collections

πŸ“Œ Expected Output:
Lists all installed Ansible collections, confirming that the environment is ready for automation.


πŸ“œ 7. Summary

  • Installed Ansible and required dependencies on the control node.
  • Created an inventory file to manage multiple nodes.
  • Configured ansible.cfg for inventory, roles, and collections.
  • Verified Ansible installation and node connectivity.
  • Tested Podman authentication and execution environments.

πŸš€ Congratulations! You have successfully installed and configured 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