RHCE 9.0 Practice Exam: Installing and Configuring Ansible
π 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
- Install Ansible on the control node (
control
). - 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
andnode4
belong to the prod host group.node5
belongs to the balancers host group.- The
prod
group is a child of thewebservers
group.
- 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
).
- Set the inventory file to
- 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
β Definesgreg
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
, andbalancers
. - Defines
prod
as a child group ofwebservers
.
π 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! π₯