RHCE 9.0 Practice Exam: Using Ansible Galaxy Roles for Load Balancing and PHP Configuration
π 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
- Use the
balancer
role to configure a load balancer:- Runs on all nodes in the
balancers
group. - Balances HTTP requests across all
webservers
.
- Runs on all nodes in the
- Use the
phpinfo
role to configure PHP:- Runs on all nodes in the
webservers
group. - Also displays detailed PHP configuration.
- Runs on all nodes in the
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 towebservers
. - Second applies the
balancer
role tobalancers
.
- First applies the
πΎ 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! π₯