nerdexam
Red_Hat

EX294 · Question #7

07. Creating and Using Roles Create a role named apache in /home/greg/ansible/roles according to the following requirements: - The httpd package is installed, set to start on system boot, and…

This task focuses on creating an Apache web server role that handles package installation, service management, firewall configuration, and template-based file creation.

Submitted by andres_qro· Apr 18, 2026Work with Roles

Question

  1. Creating and Using Roles Create a role named apache in /home/greg/ansible/roles according to the following requirements: - The httpd package is installed, set to start on system boot, and running. - Firewall is enabled and running, with rules allowing access to the web server. - A template file named index.html.j2 exists, used to create a file with the following output: /var/www/html/index.html: Welcome to HOSTNAME on IPADDRESS This playbook runs on hosts in the webservers host group and uses the apache role. Correct Answer: See the below explanation Explanation Explanation/Reference: Solution: [Virtual Machine: 172.25.250.254|control] [greg@control ansible]$ ansible-galaxy role init --init-path /home/greg/ansible/roles apache [greg@control ansible]$ ansible-galaxy list [greg@control ansible]$ vim roles/apache/tasks/main.yml --- - name: Install Apache ansible.builtin.yum: name: httpd state: latest - name: Start httpd ansible.builtin.systemd: name: httpd state: started enabled: yes - name: Start firewalld ansible.builtin.systemd: name: firewalld state: started enabled: yes - name: Start apache ansible.posix.firewalld: # Note that the service name for Apache in the firewall is not httpd. service: http permanent: yes state: enabled immediate: yes - template: # path = roles/apache/templates/ src: index.html.j2 dest: /var/www/html/index.html [greg@control ansible]$ vim roles/apache/templates/index.html.j2 Welcome to {{ ansible_nodename }} on {{ ansible_default_ipv4.address }} [greg@control ansible]$ vim /home/greg/ansible/apache.yml --- - name: webservers role hosts: webservers roles: - apache [greg@control ansible]$ ansible-navigator run apache.yml -m stdout [greg@control ansible]$ ansible webservers --list-hosts hosts (2): node3 node4 [Virtual Machine: foundation] # Verification (mandatory operation) # Verification: Access node3 and node4 to return webpage results (using command line or browser) to determine if the role is executed correctly. Welcome to node3.lab.example.com on 172.25.250.11 Welcome to node4.lab.example.com on 172.25.250.12

Explanation

This task focuses on creating an Apache web server role that handles package installation, service management, firewall configuration, and template-based file creation.

Concept tested. Ansible role creation and configuration

Reference. https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_reuse_roles.html

Topics

#Ansible Roles#Service Management#Firewall Configuration#Jinja2 Templating

Community Discussion

No community discussion yet for this question.

Full EX294 Practice