add iptables role and define firewall rules for mirror group
This commit is contained in:
parent
713d2d1c89
commit
bfa5e5807c
7 changed files with 105 additions and 0 deletions
6
roles/iptables/defaults/main.yml
Normal file
6
roles/iptables/defaults/main.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
|
||||
firewall_in:
|
||||
- {proto: tcp, port: 22}
|
||||
|
||||
firewall_raw: []
|
11
roles/iptables/handlers/main.yml
Normal file
11
roles/iptables/handlers/main.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
|
||||
- name: reload iptables
|
||||
service:
|
||||
name: iptables
|
||||
state: reloaded
|
||||
|
||||
- name: reload ip6tables
|
||||
service:
|
||||
name: ip6tables
|
||||
state: reloaded
|
35
roles/iptables/tasks/main.yml
Normal file
35
roles/iptables/tasks/main.yml
Normal file
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
|
||||
- name: remove firewalld
|
||||
package:
|
||||
name: firewalld
|
||||
state: removed
|
||||
|
||||
- name: install iptables packages
|
||||
package:
|
||||
name: "{{ item }}"
|
||||
state: installed
|
||||
with_items:
|
||||
- iptables
|
||||
- iptables-services
|
||||
|
||||
- name: create iptables config from template
|
||||
template:
|
||||
src: "{{ item }}.j2"
|
||||
dest: "/etc/sysconfig/{{ item }}"
|
||||
mode: 0600
|
||||
owner: root
|
||||
group: root
|
||||
notify: "reload {{ item }}"
|
||||
with_items:
|
||||
- iptables
|
||||
- ip6tables
|
||||
|
||||
- name: enable iptables service
|
||||
service:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
enabled: true
|
||||
with_items:
|
||||
- iptables
|
||||
- ip6tables
|
22
roles/iptables/templates/ip6tables.j2
Normal file
22
roles/iptables/templates/ip6tables.j2
Normal file
|
@ -0,0 +1,22 @@
|
|||
*filter
|
||||
:INPUT ACCEPT [0:0]
|
||||
:FORWARD DROP [0:0]
|
||||
:OUTPUT ACCEPT [0:0]
|
||||
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||
-A INPUT -p ipv6-icmp -j ACCEPT
|
||||
-A INPUT -i lo -j ACCEPT
|
||||
{% for rule in firewall_raw %}
|
||||
{{ rule }}
|
||||
{% endfor %}
|
||||
{% for rule in firewall_in %}
|
||||
{% if rule.from is defined %}
|
||||
{% for from in rule.from | ipv6 %}
|
||||
-A INPUT -m state --state NEW -m {{ rule.proto }} -p {{ rule.proto }} -s {{ from }} --dport {{ rule.port }} -j ACCEPT
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
-A INPUT -m state --state NEW -m {{ rule.proto }} -p {{ rule.proto }} --dport {{ rule.port }} -j ACCEPT
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
-A INPUT -j REJECT --reject-with icmp6-adm-prohibited
|
||||
-A FORWARD -j REJECT --reject-with icmp6-adm-prohibited
|
||||
COMMIT
|
22
roles/iptables/templates/iptables.j2
Normal file
22
roles/iptables/templates/iptables.j2
Normal file
|
@ -0,0 +1,22 @@
|
|||
*filter
|
||||
:INPUT ACCEPT [0:0]
|
||||
:FORWARD DROP [0:0]
|
||||
:OUTPUT ACCEPT [0:0]
|
||||
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||
-A INPUT -p icmp -j ACCEPT
|
||||
-A INPUT -i lo -j ACCEPT
|
||||
{% for rule in firewall_raw %}
|
||||
{{ rule }}
|
||||
{% endfor %}
|
||||
{% for rule in firewall_in %}
|
||||
{% if rule.from is defined %}
|
||||
{% for from in rule.from | ipv4 %}
|
||||
-A INPUT -m state --state NEW -m {{ rule.proto }} -p {{ rule.proto }} -s {{ from }} --dport {{ rule.port }} -j ACCEPT
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
-A INPUT -m state --state NEW -m {{ rule.proto }} -p {{ rule.proto }} --dport {{ rule.port }} -j ACCEPT
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
-A INPUT -j REJECT --reject-with icmp-host-prohibited
|
||||
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
|
||||
COMMIT
|
Loading…
Add table
Add a link
Reference in a new issue