CertGrid CertGrid
Hands-on Lab·Ansible

Ansible Firewall Rules and Safe Ordering

Configuring a firewall remotely has one hazard that nothing else in this path shares: get the order wrong and you disconnect yourself from the machine you are configuring, mid-play, with no way back in. The rules go in first and the default policy goes in last. This does it in that order and proves the connection survived.

Automating Administration Guide 33 of 45 Intermediate

Written against the versions above. This lab is Ubuntu 26.04 and EX294 is a RHEL exam. Ubuntu uses **ufw** and EX294 expects **firewalld**. The concepts map directly: `community.general.ufw` here is `ansible.posix.firewalld` there; ufw's `rule: allow` is firewalld's `service:`/`port:` with `state: enabled`; ufw applies immediately where firewalld distinguishes runtime from permanent with `immediate: true`. The ordering hazard is identical on both.

The `db` host. Its firewall is enabled and then reset, over the same SSH connection Ansible is using.
Server NameIP AddressOSRolesCPURAMHDD
ANS-CTL01192.168.0.36Ubuntu 26.04 LTSAnsible Control Node2 Core3 GB50 GB
ANS-B01192.168.0.38Ubuntu 26.04 LTSManaged Node (group: db)2 Core3 GB50 GB

Before you start

  1. The configuration this guide assumes

  2. The tool this distribution uses

  3. Allow SSH first

  4. What the rules look like

  5. The connection still works

Official sources