RHCE Labs

Hands-on labs aligned with the Red Hat Certified Engineer (EX294) exam. Ansible inventory management, playbook development, and role-based automation.

These Labs Cover All Major Linux Certifications

LPI Linux Essentials CompTIA Linux+ (XK0-006) LPIC-1 (101 & 102) LPIC-2 (201 & 202) LPIC-3 (300 / 303 / 305 / 306)
RHCSA (EX200) RHCE (EX294) RHCA LFCS LFCE LFCA CKA CKAD CKS

RHCE Labs - Module 7

Ansible inventory management, playbook development, and role-based automation — core RHCE (EX294) skills.

Lab 19: Ansible Inventory & Ad-Hoc Commands
Advanced / Terminal + GUI
Scenario: Configure Inventory and Run Ad-Hoc Tasks
You are setting up Ansible for a small fleet of servers. You must verify Ansible is installed, inspect the inventory, test connectivity with the ping module, gather facts, install a package remotely, and copy a configuration file to managed hosts. Ad-hoc commands are tested on the RHCE exam alongside playbooks.

Learning Objectives:

RHCE EX294 — Ansible
  • Setup: Verify Ansible installation and configuration
  • Inventory: View and understand static inventory files
  • Connectivity: Test reachability with the ping module
  • Ad-Hoc: Execute remote tasks without playbooks

📋 Step-by-Step Instructions

  1. Step 1: Verify Ansible Installation
    🎯 Goal: Confirm Ansible is installed and check version

    💻 Check version:
    ansible --version

    💻 Show config file location:
    ansible --version | grep "config file"
    💡 Tip: RHCE uses Ansible 2.9+ (ansible-core on RHEL 9). The config file is usually /etc/ansible/ansible.cfg or a project-local file.
  2. Step 2: View the Inventory File
    🎯 Goal: Inspect the static inventory with host groups

    💻 Show inventory:
    cat /home/ansible/inventory

    💻 List hosts from inventory:
    ansible all -i /home/ansible/inventory --list-hosts
    💡 Tip: Inventories define groups like [webservers] and [dbservers]. Use -i to specify the inventory file.
  3. Step 3: Test Connectivity with Ping
    🎯 Goal: Verify Ansible can reach all managed hosts

    💻 Ping all hosts:
    ansible all -i /home/ansible/inventory -m ping
    💡 Tip: The ping module tests SSH connectivity and Python availability, not ICMP ping.
  4. Step 4: Gather Facts from Hosts
    🎯 Goal: Use the setup module to gather system facts

    💻 Gather facts:
    ansible all -i /home/ansible/inventory -m setup -a "filter=ansible_os_family"
    💡 Tip: Facts are auto-gathered in playbooks. Use filter= to retrieve specific facts only.
  5. Step 5: Install a Package via Ad-Hoc Command
    🎯 Goal: Use the yum module to install httpd on webservers

    💻 Install package:
    ansible webservers -i /home/ansible/inventory -m yum -a "name=httpd state=present" -b
    ⚠️ Exam Note: The -b flag enables privilege escalation (become). Without it, package installs fail.
  6. Step 6: Copy a File to Remote Hosts
    🎯 Goal: Use the copy module to distribute a config file

    💻 Copy file:
    ansible webservers -i /home/ansible/inventory -m copy -a "src=/home/ansible/index.html dest=/var/www/html/index.html" -b
    🎓 Checkpoint: You used Ansible ad-hoc commands with ping, setup, yum, and copy modules — essential RHCE skills.

Ansible Control Node

Terminal
Inventory Dashboard
Host Status
Activity Log
ansible@control:~$
Inventory Overview
Inventory FileNot viewed
Total HostsUnknown
GroupsUnknown
ConnectivityNot tested
Inventory Contents
View inventory to populate this panel.
Managed Hosts
HostGroupPingStatus
Recent Activity
[--:--:--]Lab session started. Ready for commands.
Progress: 0/6 tasks completed
Score: 0/100
🎉 After Completing All Steps:

1. Click "Validate Configuration" to check completed vs pending tasks.
2. Use Inventory Dashboard and Host Status to verify visually.
Tip: Ad-hoc commands are quick one-liners; playbooks are for repeatable automation.
Lab 20: Ansible Playbook Development
Advanced / Terminal + GUI
Scenario: Write and Execute an Ansible Playbook
You need to automate web server deployment. Create a playbook that installs httpd, starts the service, deploys content, and opens the firewall. You will check syntax, run the playbook, and verify the results. Playbook writing is the primary RHCE (EX294) skill.

Learning Objectives:

RHCE EX294 — Playbooks
  • Playbooks: View and understand YAML playbook structure
  • Syntax: Validate playbook syntax before execution
  • Execution: Run playbooks and interpret output
  • Verification: Check mode (dry run) and verbose output

📋 Step-by-Step Instructions

  1. Step 1: View the Playbook
    🎯 Goal: Inspect a pre-written playbook for web server deployment

    💻 View playbook:
    cat /home/ansible/webserver.yml
    💡 Tip: Playbooks use YAML syntax. Indentation matters — use spaces, never tabs.
  2. Step 2: Check Playbook Syntax
    🎯 Goal: Validate YAML and Ansible syntax before running

    💻 Syntax check:
    ansible-playbook /home/ansible/webserver.yml -i /home/ansible/inventory --syntax-check
    ⚠️ Exam Note: Always syntax-check before running. A YAML indent error can waste precious exam time.
  3. Step 3: Run the Playbook
    🎯 Goal: Execute the playbook against the webservers group

    💻 Run playbook:
    ansible-playbook /home/ansible/webserver.yml -i /home/ansible/inventory
    💡 Tip: Green = ok (no change), Yellow = changed, Red = failed. A good run shows changed and ok.
  4. Step 4: Verify the Deployment
    🎯 Goal: Confirm httpd is running on managed hosts

    💻 Check service:
    ansible webservers -i /home/ansible/inventory -m command -a "systemctl is-active httpd"
    💡 Tip: Use ad-hoc commands to verify playbook results. Expect "active" from all webservers.
  5. Step 5: Run Playbook in Check Mode (Dry Run)
    🎯 Goal: Preview changes without applying them

    💻 Dry run:
    ansible-playbook /home/ansible/webserver.yml -i /home/ansible/inventory --check
    💡 Tip: --check simulates execution. Not all modules support check mode perfectly.
  6. Step 6: Run Playbook with Verbose Output
    🎯 Goal: Debug and inspect detailed execution output

    💻 Verbose run:
    ansible-playbook /home/ansible/webserver.yml -i /home/ansible/inventory -v
    🎓 Checkpoint: You wrote, validated, ran, verified, and debugged an Ansible playbook — the core RHCE workflow.

Ansible Control Node

Terminal
Playbook Viewer
Run History
Activity Log
ansible@control:~$
webserver.yml
View playbook to populate this panel.
Playbook Run Summary
Syntax ValidNot checked
Last RunNever
Run ResultN/A
Check ModeNot run
Verbose RunNot run
Recent Activity
[--:--:--]Lab session started. Ready for commands.
Progress: 0/6 tasks completed
Score: 0/100
🎉 After Completing All Steps:

1. Validate configuration to review playbook execution status.
2. Use Playbook Viewer and Run History for visual inspection.
Tip: The RHCE exam is entirely Ansible-based — practice writing playbooks from scratch.
Lab 21: Ansible Roles & Variables
Advanced / Terminal + GUI
Scenario: Build and Use Ansible Roles
Your team wants reusable automation. You must initialize a role directory structure, inspect it, create a playbook that uses the role with variables, run it, then use ansible-galaxy to install a community role. Roles and variables are heavily tested on the RHCE exam.

Learning Objectives:

RHCE EX294 — Roles
  • Roles: Initialize and understand role directory structure
  • Variables: Use role defaults and playbook variables
  • Galaxy: Install roles from Ansible Galaxy
  • Execution: Run role-based playbooks

📋 Step-by-Step Instructions

  1. Step 1: Initialize a Role
    🎯 Goal: Create a new role directory structure

    💻 Create role:
    ansible-galaxy role init /home/ansible/roles/webconfig
    💡 Tip: ansible-galaxy role init creates the standard directory structure: tasks, handlers, defaults, vars, files, templates, meta.
  2. Step 2: View Role Directory Structure
    🎯 Goal: Understand the role layout

    💻 Show tree:
    find /home/ansible/roles/webconfig -type f | head -20
    💡 Tip: Key directories: tasks/main.yml for logic, defaults/main.yml for default variables, handlers/main.yml for handlers.
  3. Step 3: View the Role-Based Playbook
    🎯 Goal: Inspect a playbook that references the webconfig role with variables

    💻 View playbook:
    cat /home/ansible/site.yml
    💡 Tip: Roles are referenced in the roles: section. Variables can override role defaults.
  4. Step 4: Run the Role-Based Playbook
    🎯 Goal: Execute the site playbook that uses the webconfig role

    💻 Run playbook:
    ansible-playbook /home/ansible/site.yml -i /home/ansible/inventory
    💡 Tip: Role tasks execute in order from tasks/main.yml. Handlers trigger at the end of the play.
  5. Step 5: Install a Galaxy Role
    🎯 Goal: Install a community role from Ansible Galaxy

    💻 Install role:
    ansible-galaxy role install geerlingguy.firewall -p /home/ansible/roles
    ⚠️ Exam Note: On the RHCE exam, you may need to install roles from a provided requirements.yml file.
  6. Step 6: List Installed Roles
    🎯 Goal: Verify all roles are available

    💻 List roles:
    ansible-galaxy role list -p /home/ansible/roles
    🎓 Checkpoint: You created a role, ran a role-based playbook, and managed Galaxy roles — essential RHCE skills.

Ansible Control Node

Terminal
Roles Dashboard
Site Playbook
Activity Log
ansible@control:~$
Role Management
webconfig roleNot created
geerlingguy.firewallNot installed
Site playbook runNot run
Roles listedNo
Role Structure
Initialize a role to see its structure.
site.yml
View site.yml to populate this panel.
Recent Activity
[--:--:--]Lab session started. Ready for commands.
Progress: 0/6 tasks completed
Score: 0/100
🎉 After Completing All Steps:

1. Validate to check role creation, playbook execution, and Galaxy installs.
2. Use Roles Dashboard and Site Playbook viewer for visual inspection.
Tip: Roles are the most common way to organize Ansible code in production.