In the process of writing playbooks to configure firewalld
(on RHEL) with Ansible, we've encountered some issues with juggling the running config and the configuration written to /etc/firewalld/firewalld.conf
, which is usually modified via firewall-cmd
. We want the systems whose firewalls we're managing with Ansible to converge to the state we specify after every run of Ansible (i.e., after having the firewalld
playbook(s) run against a host, both the running and written configs are in the desired state).
Ansible provides the firewalld
module, which can manage many settings. Unfortunately, it can’t do everything that firewall-cmd
can do, such as set things like DefaultZone
(which is one of the options we want to be managing). While we initially though the solution to the shortcomings of the firewalld
module would be to run firewall-cmd
using the Ansible command module, we quickly realized that if you set the value of DefaultZone
using the Ansible command plugin to run firewall-cmd
and then someone else uses a text editor to modify the value of DefaultZone
in firewalld.conf
, Ansible will fail when trying to reset DefaultZone
back to its original value, since firewall-cmd
thinks the configuration option already has the desired value.
Does anyone know of a way to ensure that both the running and written configuration for firewalld
are in the desired state after each run of Ansible? We’re more concerned about unloaded configuration changes surprising us than we are about someone making an ephemeral change to the running ruleset that will be replaced the next time firewalld
rulesets are loaded from disk, but it would be ideal if we could manage everything with Ansible.