Skip to content
This repository was archived by the owner on Oct 27, 2025. It is now read-only.

Commit 04fa5f4

Browse files
committed
Support assignment of interfaces to firewalld zones
1 parent 8fd80d5 commit 04fa5f4

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,30 @@ and routed updated.
235235
roles:
236236
- role: network
237237

238+
9) This role can also optionally add network interfaces to firewalld zones. The
239+
core firewalld module (http://docs.ansible.com/ansible/latest/firewalld_module.html)
240+
can perform the same function, so if you make use of both modules then your
241+
playbooks may not be idempotent. Consider this case, where only the firewalld
242+
module is used:
243+
244+
* network_interface role runs; with no firewalld_zone host var set then any
245+
ZONE line will be removed from ifcfg-*
246+
* firewalld module runs; adds a ZONE line to ifcfg-*
247+
* On the next playbook run, the network_interface role runs and removes the
248+
ZONE line again, and so the cycle repeats.
249+
250+
In order for this role to manage firewalld zones, the system must be running a
251+
RHEL based distribution, and using NetworkManager to manage the network
252+
interfaces. If those criteria are met, the following example shows how to add
253+
the eth0 interface to the public firewalld zone:
254+
255+
- device: eth0
256+
bootproto: static
257+
address: 192.168.10.18
258+
netmask: 255.255.255.0
259+
gateway: 192.168.10.1
260+
firewalld_zone: public
261+
238262
Note: Ansible needs network connectivity throughout the playbook process, you
239263
may need to have a control interface that you do *not* modify using this
240264
method while changeing IP Addresses so that Ansible has a stable connection

templates/bond_RedHat.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ BONDING_MASTER={{ item.bonding_master }}
5454
{% if item.bridge is defined %}
5555
BRIDGE={{ item.bridge }}
5656
{% endif %}
57+
58+
{% if item.firewalld_zone is defined %}
59+
ZONE={{ item.firewalld_zone }}
60+
{% endif %}

templates/bridge_RedHat.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ DEFROUTE={{ item.defroute | bool | ternary("yes", "no") }}
6767
{% if item.mtu is defined %}
6868
MTU={{ item.mtu }}
6969
{% endif %}
70+
71+
{% if item.firewalld_zone is defined %}
72+
ZONE={{ item.firewalld_zone }}
73+
{% endif %}

templates/ethernet_RedHat.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ DEFROUTE={{ item.defroute | bool | ternary("yes", "no") }}
6262
{% if item.mtu is defined %}
6363
MTU={{ item.mtu }}
6464
{% endif %}
65+
66+
{% if item.firewalld_zone is defined %}
67+
ZONE={{ item.firewalld_zone }}
68+
{% endif %}

0 commit comments

Comments
 (0)