-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirewall.yaml
54 lines (49 loc) · 1.4 KB
/
firewall.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
- name: Check if a dedicate DDoS solution is in place
changed_when: false
ansible.builtin.stat:
path: /root/ipv4-rules.sh
register: _test_at_ddos_solution
- name: Firewall
when: not _test_at_ddos_solution.stat.exists
block:
- name: Install or update firewall software
ansible.builtin.apt:
name:
- iptables-persistent
- name: Create firewall script
ansible.builtin.template:
src: "firewall-ip{{ item }}.sh.j2"
dest: "/root/firewall-ip{{ item }}.sh"
mode: "0700"
with_items:
- "v4"
- "v6"
register: _fw_scripts
- name: Save iptables state
community.general.iptables_state:
ip_version: "ip{{ item }}"
state: saved
path: "/etc/iptables/rules.{{ item }}"
with_items:
- "v4"
- "v6"
register: _fw_old
- name: Reset firewall
when: _fw_scripts.changed or _fw_old.changed
block:
- name: Start firewall
changed_when: true
ansible.builtin.command:
cmd: "/root/firewall-ip{{ item }}.sh start"
with_items:
- "v4"
- "v6"
- name: Save iptables state of setup
community.general.iptables_state:
ip_version: "ip{{ item }}"
state: saved
path: "/etc/iptables/rules.{{ item }}"
with_items:
- "v4"
- "v6"