RHCE 9.0 Practice Exam: Creating a Web Content Directory Using Ansible

Expertise in Cloud, Networking & DevOps
Photo by Florian Krumm / Unsplash

πŸ“Œ 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

  1. Create an Ansible Playbook named /home/greg/ansible/webcontent.yml.
  2. Run the playbook on all hosts in the dev group.
  3. 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)
    • Create a symbolic link:
      • /var/www/html/webdev β†’ /webdev
    • Create an index.html file inside /webdev:

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'

βœ… 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! πŸ”₯

Read more