2.0 KiB
EX294 9.3: Firewall rules
Open services and ports on the managed nodes with
ansible.posix.firewalld, see the difference between permanent and
immediate, and do the same with the firewall system role.
Before you start
This VM is the control node. The lab creates the user greg (password
Lab-Pass-1) with an SSH key, and installs ansible-core. Work as greg,
in /home/greg/ansible: its ansible.cfg reads the inventory inventory,
logs in as devops and becomes root. node1 is in the group webservers
and node2 in dbservers. The ansible.posix collection and the system
roles aren't installed yet.
The managed nodes node1 (10.99.1.11) and node2 (10.99.1.12) are
AlmaLinux 10 containers, prepared as in chapter 3.1: devops takes greg's
key and may use sudo without a password. Both run firewalld, and node1
runs a web server that the firewall blocks for now. For a root shell on a
node, sudo podman exec -it node1 bash.
Tasks
- Open HTTP and port 8080/tcp permanently and immediately on the web
servers.
curl http://node1/works from this VM, andfirewall-cmd --permanent --list-allon node1 lists both. - Add port 9090/tcp on the web servers with
permanent: trueonly, and find it:--list-portsdoesn't show it,--permanent --list-portsdoes. Then reload firewalld there, after which both do. - Use the firewall system role to allow
mysqlon the database servers.firewall-cmd --list-serviceson node2 includesmysql.
Hints
ansible-galaxy collection install ansible.posixforansible.posix.firewalld:serviceorport,permanent,immediate,state: enabled.ansible webservers -a 'firewall-cmd --reload', or asystemd_servicetask withstate: reloaded.- The system roles come from the
rhel-system-rolespackage on the control node; the role isredhat.rhel_system_roles.firewall, with the rules in the variablefirewall. Its README is in/usr/share/doc/rhel-system-roles/firewall/.