Skip to content

Commit

Permalink
Add posibility to assign more than one interface to zones
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-z1 committed Jun 3, 2020
1 parent cd52402 commit fa4ae80
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ The following variable is used to define the default zone of firewalld:

---

The following variables are used to define the interface of a zone (multiple interfaces per zone possible, one interface per line):

```
firewalld_zone_interface:
public: (required, e.g. eth0)
```

---

The following variables are used to define the source of a zone:

```
Expand Down Expand Up @@ -89,6 +80,21 @@ The following variables are used to define a port rule:

---

The following variables are used to define which interfaces assigned to zones:

```
firewalld_zone_interfaces:
- name: trusted
interfaces:
- eth1
- eth2
- name: public
interfaces:
- eth0
```

---

The following variables are used to define a rich rule:

```
Expand Down
10 changes: 6 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
changed_when: result.stdout == "success"
tags: firewalld

- name: set firewalld zone interface
- name: set firewalld zone interfaces
shell: |
if [[ "$(/bin/firewall-cmd --get-zone-of-interface={{ item.value }})" != "{{ item.key }}" ]]
if [[ "$(/bin/firewall-cmd --get-zone-of-interface={{ item.1 }})" != "{{ item.0.name }}" ]]
then
/bin/firewall-cmd --zone={{ item.key }} --add-interface={{ item.value }} --permanent && echo "changed"
/bin/firewall-cmd --zone={{ item.0.name }} --add-interface={{ item.1 }} --permanent && echo "changed"
fi
with_dict: "{{ firewalld_zone_interface|default({}) }}"
with_subelements:
- "{{ firewalld_zone_interfaces|default([]) }}"
- interfaces
register: shell_result
changed_when: shell_result.stdout | join('') is search('changed')
notify: restart firewalld
Expand Down

0 comments on commit fa4ae80

Please sign in to comment.