RHCE 9.0 Practice Exam: Creating a Web Content Directory Using Ansible
π Article Overview
This tutorial is designed for RHCE 9.0 certification candidates and explains how to use Ansible to create a web content directory with the correct permissions, symbolic links, and access configurations.
π‘ What You Will Learn:
β
How to create a web content directory using Ansible
β
How to set permissions, group ownership, and special permissions (SGID)
β
How to create symbolic links in Apacheβs web root directory
β
How to verify web content accessibility via HTTP
π 1. Task Requirements
π 1.1. Problem Statement
- Create an Ansible Playbook named
/home/greg/ansible/webcontent.yml
. - Run the playbook on all hosts in the
dev
group. - Ensure the following directory structure and configuration:
- Create
/webdev
directory with:- Owner:
webdev
- Permissions:
2775
(SGID set, owner & group can read/write/execute, others can read/execute)
- Owner:
- Create a symbolic link:
/var/www/html/webdev
β/webdev
- Create an
index.html
file inside/webdev
:
- Create
Verify that accessing http://172.25.250.9/webdev/
(or equivalent) displays:
Development
Content:
Development
π 2. Gathering Information
Before writing the playbook, verify web root permissions and SELinux contexts.
π 2.1. Check Apache Web Root Directory
$ ansible dev -a 'ls -ldZ /var/www/html'
π Expected Output
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html
β
The directory should have the correct SELinux context (httpd_sys_content_t
).
π 3. Writing the Ansible Playbook
π 3.1. Create the Playbook File
$ vim /home/greg/ansible/webcontent.yml
π Add the Following Content
---
- name: Create Web Directory and Configure Web Content
hosts: dev
become: yes
tasks:
- name: Create /webdev directory
ansible.builtin.file:
path: /webdev
state: directory
owner: webdev
group: webdev
mode: '2775'
- name: Create a symbolic link from /var/www/html/webdev to /webdev
ansible.builtin.file:
src: /webdev
dest: /var/www/html/webdev
state: link
- name: Create index.html with Development content
ansible.builtin.copy:
content: 'Development\n'
dest: /webdev/index.html
mode: '0644'
setype: httpd_sys_content_t
π Explanation:
- Creates
/webdev
with the correct owner, group, and SGID permission (2775
). - Creates a symbolic link (
/var/www/html/webdev β /webdev
). - Creates an
index.html
file inside/webdev
with proper SELinux context (httpd_sys_content_t
).
πΎ Save and exit: (ESC
β :wq
)
π 4. Running the Playbook
π 4.1. Execute the Playbook
$ ansible-navigator run /home/greg/ansible/webcontent.yml -m stdout
π Expected Output
PLAY [Create Web Directory and Configure Web Content] *************************
TASK [Create /webdev directory] ***********************************************
changed: [node1]
changed: [node2]
changed: [node3]
TASK [Create a symbolic link from /var/www/html/webdev to /webdev] ************
changed: [node1]
changed: [node2]
changed: [node3]
TASK [Create index.html with Development content] *****************************
changed: [node1]
changed: [node2]
changed: [node3]
PLAY RECAP ********************************************************************
node1 : ok=3 changed=3 unreachable=0 failed=0
node2 : ok=3 changed=3 unreachable=0 failed=0
node3 : ok=3 changed=3 unreachable=0 failed=0
β The directory structure, symbolic link, and index file were successfully created.
π 5. Verifying Web Content
π 5.1. Check Directory and File Permissions
$ ansible dev -m shell -a 'ls -ld /webdev'
π Expected Output
drwxrwsr-x. webdev webdev 2775 /webdev
$ ansible dev -m shell -a 'ls -ld /var/www/html/webdev'
π Expected Output
lrwxrwxrwx. root root /var/www/html/webdev -> /webdev
π 5.2. Verify Web Page Content
$ curl http://node1/webdev/
π Expected Output
Development
β If the output matches, the web directory setup is correct.
π 6. Common Issues & Troubleshooting
π΄ Issue 1: Web Directory /webdev
Not Created
β Solution:
If missing, manually create:
$ ansible dev -m shell -a 'mkdir -p /webdev && chown webdev:webdev /webdev'
Ensure Ansible has the necessary permissions:
$ ansible dev -m shell -a 'ls -ld /webdev'
π΄ Issue 2: Symbolic Link /var/www/html/webdev
Not Created
β Solution:
If missing, re-run:
$ ansible dev -m shell -a 'ln -s /webdev /var/www/html/webdev'
Verify if the symbolic link exists:
$ ansible dev -m shell -a 'ls -ld /var/www/html/webdev'
π΄ Issue 3: Web Page Not Loading
β Solution:
Check SELinux Context:
$ ls -ldZ /webdev/index.html
If incorrect, fix it:
$ restorecon -Rv /webdev/index.html
Check Firewall Rules:
$ firewall-cmd --list-services
If http
is missing, add it:
$ firewall-cmd --add-service=http --permanent
$ firewall-cmd --reload
Check Apache Configuration:
$ systemctl status httpd
If not running, restart it:
$ systemctl restart httpd
π Congratulations! You have successfully used Ansible to configure a web content directory 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! π₯