Red Hat Certified Engineer RHCE · Free Practice Question Hard
Question 15
You are required to configure a system-wide firewall rule that blocks incoming traffic on all ports except SSH and HTTPS. How would you use the firewalld module in Ansible to configure this firewall rule and ensure it is enforced on all nodes?
-
A
Blocking Incoming Traffic Except SSH and HTTPS Using
firewalld
To block all traffic except SSH and HTTPS:- - hosts: all
- tasks:
- - name: Allow SSH and HTTPS traffic
- ansible.builtin.firewalld:
- service: "{{ item }}"
- state: enabled
- permanent: yes
- loop:
- - ssh
- - https
- - name: Set default zone to drop all other traffic
- ansible.builtin.firewalld:
- default_zone: drop
- state: enabled
This ensures only SSH and HTTPS traffic is allowed.
-
B
This is a performance based question and not multiple choice. Therefore the answer is in #1. If you require additional explanation, please ask your question in the Q&A section.
Reveal correct answer
Correct answer: A
A.
This playbook configures the firewall on all managed nodes using the firewalld module to ensure that only SSH and HTTPS traffic is allowed while all other incoming traffic is blocked. It achieves this by first allowing the SSH and HTTPS services, then setting a default firewall zone to drop all other traffic. The firewall rules are enforced permanently to ensure they persist even after a reboot.
Line-by-Line Explanation
- hosts: allThis line specifies that the tasks will be executed on all hosts defined in the Ansible inventory.
tasks:This marks the start of the tasks section where specific actions will be performed on the hosts.
- name: Allow SSH and HTTPS trafficThis task description indicates that SSH and HTTPS traffic will be allowed on the hosts.
ansible.builtin.firewalld:This is the
firewalldmodule from Ansible that is used to configure the firewall on the managed nodes.
service: "{{ item }}"This tells Ansible to iterate through the services specified in the
loop(SSH and HTTPS) and apply the firewall rule to allow them.
state: enabledThis ensures that the service (SSH or HTTPS) is enabled in the firewall, allowing the traffic through.
permanent: yesThis ensures the rule is permanent and will persist even after a system reboot.
loop:This indicates that the task will be repeated for each item in the following list (SSH and HTTPS).
- sshThis specifies that the SSH service will be allowed by the firewall.
- httpsThis specifies that the HTTPS service will be allowed by the firewall.
- name: Set default zone to drop all other trafficThis task sets a default firewall rule to block all other incoming traffic except the specified services.
ansible.builtin.firewalld:Again, the
firewalldmodule is used to configure the firewall.
default_zone: dropThis defines the default zone as "drop," which means that any incoming traffic not explicitly allowed will be dropped.
state: enabledThis ensures that the default rule (to drop other traffic) is enabled in the firewall.
This Ansible playbook configures a firewall on all managed nodes to allow only SSH and HTTPS traffic, blocking all other incoming traffic. The rules are applied permanently to ensure they remain effective even after a reboot. The playbook achieves this by using Ansible's firewalld module to manage firewall services and set a default zone to drop traffic.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
