Setup firewalld

This commit is contained in:
Jake Howard 2020-07-03 21:53:31 +01:00
parent fba284f9a9
commit 82bffc3538
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 49 additions and 0 deletions

View file

@ -0,0 +1,4 @@
requested_firewall_ports:
- 80/tcp
- 443/tcp
- 1080/tcp

View file

@ -38,3 +38,4 @@
- statping - statping
- socks-proxy - socks-proxy
- upload - upload
- firewall

View file

@ -0,0 +1,44 @@
- name: Install firewalld
package:
name: firewalld
become: true
- name: Enable firewalld
systemd:
name: firewalld
enabled: true
state: started
become: true
- name: Mark wireguard as internal traffic
firewalld:
source: "{{ wireguard.cidr }}"
zone: trusted
state: enabled
permanent: true
immediate: true
become: true
- name: Get firewall ports
shell: firewall-cmd --list-ports --zone public
become: true
register: firewall_ports
- name: Open firewall ports
firewalld:
port: "{{ item }}"
permanent: true
immediate: true
state: enabled
loop: "{{ requested_firewall_ports }}"
become: true
- name: Close firewall ports
firewalld:
port: "{{ item }}"
permanent: true
immediate: true
state: disabled
when: item and item not in requested_firewall_ports
loop: "{{ firewall_ports.stdout.split(' ') }}"
become: true