RHCE 9.0 Practice Exam: Using Ansible Galaxy Roles for Load Balancing and PHP Configuration

RHCE 9.0 Practice Exam: Using Ansible Galaxy Roles for Load Balancing and PHP Configuration
Photo by Thomas Jensen / Unsplash

πŸ“Œ Article Overview

This tutorial is designed for RHCE 9.0 certification candidates and explains how to use pre-installed Ansible roles (balancer and phpinfo) to configure load balancing and deploy PHP web applications.

πŸ’‘ What You Will Learn:

βœ… How to create an Ansible Playbook to use Galaxy roles
βœ… How to configure a Load Balancer using the balancer role
βœ… How to deploy a PHP web application using the phpinfo role
βœ… How to verify load balancing across multiple web servers
βœ… How to check PHP configuration via a browser


πŸ“œ 1. Task Requirements

πŸ“ 1.1. Problem Statement

  1. Use the balancer role to configure a load balancer:
    • Runs on all nodes in the balancers group.
    • Balances HTTP requests across all webservers.
  2. Use the phpinfo role to configure PHP:
    • Runs on all nodes in the webservers group.
    • Also displays detailed PHP configuration.

Visiting /hello.php should display:

Hello PHP World from node3.lab.example.com

or

Hello PHP World from node4.lab.example.com

Visiting http://172.25.250.13 should alternately show:

Welcome to node3.lab.example.com on 172.25.250.11
Welcome to node4.lab.example.com on 172.25.250.12

πŸ“œ 2. Creating the Ansible Playbook

πŸ“ 2.1. Open the Playbook File

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

πŸ“„ Add the Following Content:

---
- name: Configure PHP on Web Servers
  hosts: webservers
  roles:
    - phpinfo

- name: Configure Load Balancer
  hosts: balancers
  roles:
    - balancer

πŸ“Œ Key Points:

  • Defines two plays:
    • First applies the phpinfo role to webservers.
    • Second applies the balancer role to balancers.

πŸ’Ύ Save and exit: (ESC β†’ :wq)


πŸ“œ 3. Running the Playbook

πŸ“ 3.1. Execute the Playbook

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

πŸ“Œ Expected Output

PLAY [Configure PHP on Web Servers] *******************************************

TASK [phpinfo : Install required PHP packages] ********************************
changed: [node3]
changed: [node4]

TASK [phpinfo : Deploy hello.php file] ***************************************
changed: [node3]
changed: [node4]

PLAY [Configure Load Balancer] ***********************************************

TASK [balancer : Install HAProxy or equivalent] *******************************
changed: [node1]

TASK [balancer : Configure Load Balancer] ************************************
changed: [node1]

TASK [balancer : Restart Load Balancer Service] ******************************
ok: [node1]

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

βœ… The playbook successfully configures PHP and load balancing.


πŸ“œ 4. Verifying Load Balancing

πŸ“ 4.1. Check Hosts in the balancers Group

$ ansible balancers --list-hosts

πŸ“Œ Expected Output

hosts (1):
  node1

βœ… The load balancer runs on node1 (172.25.250.13).

πŸ“ 4.2. Test Load Balancer

Run the following curl command multiple times:

$ curl http://172.25.250.13

πŸ“Œ Expected Alternating Outputs

Welcome to node3.lab.example.com on 172.25.250.11
Welcome to node4.lab.example.com on 172.25.250.12

βœ… The load balancer is correctly distributing requests!


πŸ“œ 5. Verifying PHP Configuration

πŸ“ 5.1. Check Hosts in the webservers Group

$ ansible webservers --list-hosts

πŸ“Œ Expected Output

hosts (2):
  node3
  node4

βœ… PHP is deployed on node3 and node4.

πŸ“ 5.2. Test PHP Application

Visit the following URLs in a web browser:

  • http://172.25.250.11/hello.php
  • http://172.25.250.12/hello.php

Alternatively, use curl:

$ curl http://172.25.250.11/hello.php

πŸ“Œ Expected Output

Hello PHP World from node3.lab.example.com
$ curl http://172.25.250.12/hello.php

πŸ“Œ Expected Output

Hello PHP World from node4.lab.example.com

βœ… Both PHP servers return the correct hostname!


πŸ“œ 6. Final Browser Verification

πŸ”Ή Open a web browser and navigate to:

  • http://172.25.250.11/hello.php
  • http://172.25.250.12/hello.php

πŸ“Œ Expected Web Page Appearance

  • Main Title: "Hello PHP World from nodeX.lab.example.com"
  • Background: Purple
  • PHP Configuration: Displayed below the text

βœ… The PHP page is accessible, and PHP configuration details are displayed!


πŸ“œ 7. Scoring Criteria

Step Description Score
1. Create roles.yml Playbook Defines correct roles & hosts 5 points
2. Run Playbook with ansible-navigator Successfully deploys configurations 10 points
3. Verify Load Balancer (curl 172.25.250.13) Alternates between node3 & node4 10 points
4. Verify PHP App (/hello.php) Displays hostname & PHP details 10 points
5. Check Browser Rendering PHP page has a purple background & correct info 10 points

βœ… Total Score: 45 points


πŸ“œ 8. Common Issues & Troubleshooting

πŸ”΄ Issue 1: Load balancer is not alternating requests

βœ… Solution:

$ systemctl restart haproxy
$ systemctl restart httpd

πŸ”΄ Issue 2: PHP page is not displaying

βœ… Solution: Ensure phpinfo is correctly installed:

$ yum list installed | grep php

If missing, reinstall PHP:

$ yum install -y php php-cli php-common php-fpm
$ systemctl restart httpd

πŸš€ Congratulations! You have successfully deployed an Ansible Playbook that configures a Load Balancer and a PHP Web Server 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