Red Hat Certified Engineer RHCE · Free Practice Question Hard

Question 12

You need to configure firewall rules on managed nodes to ensure they persist after a reboot. How can you use Ansible's firewalld and template modules to deploy and enable customized firewall configurations that remain persistent across reboots?

  • A

    This ensures firewall rules persist after reboots.

  • 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.

The answer utilizes Ansible's firewalld and template modules to configure firewall rules that persist across reboots. First, the template module is used to deploy a customized firewall configuration file (custom_rules.xml) generated from a Jinja2 template. The file is placed in the appropriate directory (/etc/firewalld/services/). Then, the firewalld module is used to apply the custom rules and ensure they are permanent, meaning they will persist after a reboot. Lastly, the firewall is reloaded to apply the new rules and ensure they take effect.

Line-by-Line Explanation

  1. - hosts: all

    • This line defines that the tasks should run on all managed nodes specified in the inventory.

  2. tasks:

    • This section contains the tasks that will be executed on the managed nodes.

  3. - name: Deploy custom rules

    • This task name indicates that the task will deploy custom firewall rules to the managed nodes.

  4. ansible.builtin.template:

    • This uses the template module to manage files based on Jinja2 templates. The file is created dynamically with content from the specified template.

  5. src: templates/firewall.j2

    • The source file, firewall.j2, is a Jinja2 template stored in the templates directory. This file contains the firewall configuration template that will be processed and deployed.

  6. dest: /etc/firewalld/services/custom_rules.xml

    • This defines the destination path where the generated configuration file will be saved on the managed nodes. It will be placed in /etc/firewalld/services/ with the name custom_rules.xml.

  7. mode: '0644'

    • This specifies the file permissions for the custom_rules.xml file, giving read and write permissions to the owner, and read permissions to the group and others.

  8. - name: Apply rules

    • This task name indicates that it will apply the custom firewall rules after they are deployed.

  9. ansible.builtin.firewalld:

    • This uses the firewalld module to manage firewall rules.

  10. service: custom_rules

    • This specifies that the custom rules file (custom_rules.xml) should be applied by the firewalld service.

  11. permanent: yes

    • This ensures that the rules are permanent, meaning they will persist after a system reboot.

  12. state: enabled

    • This ensures that the firewall service is enabled and the rules are applied.

  13. - name: Reload firewalld

    • This task name indicates that the firewall service will be reloaded to apply the new rules.

  14. ansible.builtin.service:

    • This uses the service module to manage services on the managed nodes.

  15. name: firewalld

    • This specifies that the firewalld service should be reloaded.

  16. state: reloaded

    • This reloads the firewalld service to apply the new firewall rules.

This configuration ensures that the firewall rules are deployed, applied, and persist across reboots by utilizing Ansible's firewalld and template modules.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need