2017-01-06 15:50:48 +01:00
|
|
|
---
|
|
|
|
|
2017-01-09 16:38:21 +01:00
|
|
|
- name: Check if minifirewall is running
|
2017-01-31 17:41:33 +01:00
|
|
|
shell: /sbin/iptables -L -n | grep -E "^(DROP\s+udp|ACCEPT\s+icmp)\s+--\s+0\.0\.0\.0\/0\s+0\.0\.0\.0\/0\s*$"
|
2017-01-09 16:38:21 +01:00
|
|
|
changed_when: False
|
|
|
|
failed_when: False
|
2017-03-24 14:15:09 +01:00
|
|
|
check_mode: no
|
2017-01-09 16:38:21 +01:00
|
|
|
register: minifirewall_is_running
|
2017-01-31 17:42:32 +01:00
|
|
|
|
|
|
|
- debug:
|
2017-04-11 16:13:10 +02:00
|
|
|
var: minifirewall_is_running
|
|
|
|
verbosity: 1
|
2017-01-09 16:38:21 +01:00
|
|
|
|
2017-01-06 15:50:48 +01:00
|
|
|
- name: Begin marker for IP addresses
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/default/minifirewall
|
|
|
|
create: no
|
|
|
|
line: "# BEGIN ANSIBLE MANAGED BLOCK FOR IPS"
|
|
|
|
insertbefore: '^# Main interface'
|
|
|
|
|
|
|
|
- name: End marker for IP addresses
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/default/minifirewall
|
|
|
|
create: no
|
|
|
|
line: "# END ANSIBLE MANAGED BLOCK FOR IPS"
|
|
|
|
insertafter: '^PRIVILEGIEDIPS='
|
|
|
|
|
2017-03-22 18:12:30 +01:00
|
|
|
- fail:
|
|
|
|
msg: You must provide at least 1 trusted IP
|
|
|
|
when: minifirewall_trusted_ips == []
|
2017-09-14 14:26:44 +02:00
|
|
|
- debug:
|
|
|
|
msg: "Warning: minifirewall_trusted_ips='0.0.0.0/0', the firewall is useless!"
|
|
|
|
when: minifirewall_trusted_ips == ["0.0.0.0/0"]
|
2017-03-22 18:12:30 +01:00
|
|
|
|
2017-01-06 15:50:48 +01:00
|
|
|
- name: Configure IP addresses
|
|
|
|
blockinfile:
|
|
|
|
dest: /etc/default/minifirewall
|
|
|
|
create: no
|
|
|
|
marker: "# {mark} ANSIBLE MANAGED BLOCK FOR IPS"
|
|
|
|
content: |
|
2017-01-31 17:44:31 +01:00
|
|
|
# Main interface
|
2017-01-06 15:50:48 +01:00
|
|
|
INT='{{ minifirewall_int }}'
|
2017-01-31 17:44:31 +01:00
|
|
|
|
|
|
|
# IPv6
|
2017-01-06 15:50:48 +01:00
|
|
|
IPV6='{{ minifirewall_ipv6 }}'
|
2017-01-31 17:44:31 +01:00
|
|
|
|
|
|
|
# Trusted IPv4 local network
|
|
|
|
# ...will be often IP/32 if you don't trust anything
|
2017-01-06 15:50:48 +01:00
|
|
|
INTLAN='{{ minifirewall_intlan }}'
|
2017-01-31 17:44:31 +01:00
|
|
|
|
|
|
|
# Trusted IPv4 addresses for private and semi-public services
|
2017-01-06 15:50:48 +01:00
|
|
|
TRUSTEDIPS='{{ minifirewall_trusted_ips | join(' ') }}'
|
2017-01-31 17:44:31 +01:00
|
|
|
|
|
|
|
# Privilegied IPv4 addresses for semi-public services
|
|
|
|
# (no need to add again TRUSTEDIPS)
|
2017-01-06 15:50:48 +01:00
|
|
|
PRIVILEGIEDIPS='{{ minifirewall_privilegied_ips | join(' ') }}'
|
2017-01-09 16:38:21 +01:00
|
|
|
register: minifirewall_config_ips
|
2017-01-06 15:50:48 +01:00
|
|
|
|
|
|
|
- name: Begin marker for ports
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/default/minifirewall
|
|
|
|
create: no
|
|
|
|
line: "# BEGIN ANSIBLE MANAGED BLOCK FOR PORTS"
|
|
|
|
insertbefore: '^# Protected services'
|
|
|
|
|
|
|
|
- name: End marker for ports
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/default/minifirewall
|
|
|
|
create: no
|
|
|
|
line: "# END ANSIBLE MANAGED BLOCK FOR PORTS"
|
|
|
|
insertafter: '^SERVICESUDP3='
|
|
|
|
|
|
|
|
- name: Configure ports
|
|
|
|
blockinfile:
|
|
|
|
dest: /etc/default/minifirewall
|
|
|
|
create: no
|
|
|
|
marker: "# {mark} ANSIBLE MANAGED BLOCK FOR PORTS"
|
|
|
|
content: |
|
2017-01-31 17:44:31 +01:00
|
|
|
# Protected services
|
|
|
|
# (add also in Public services if needed)
|
2017-01-06 15:50:48 +01:00
|
|
|
SERVICESTCP1p='{{ minifirewall_protected_ports_tcp | join(' ') }}'
|
|
|
|
SERVICESUDP1p='{{ minifirewall_protected_ports_udp | join(' ') }}'
|
2017-01-31 17:44:31 +01:00
|
|
|
|
|
|
|
# Public services (IPv4/IPv6)
|
2017-01-06 15:50:48 +01:00
|
|
|
SERVICESTCP1='{{ minifirewall_public_ports_tcp | join(' ') }}'
|
|
|
|
SERVICESUDP1='{{ minifirewall_public_ports_udp | join(' ') }}'
|
2017-01-31 17:44:31 +01:00
|
|
|
|
|
|
|
# Semi-public services (IPv4)
|
2017-01-06 15:50:48 +01:00
|
|
|
SERVICESTCP2='{{ minifirewall_semipublic_ports_tcp | join(' ') }}'
|
|
|
|
SERVICESUDP2='{{ minifirewall_semipublic_ports_udp | join(' ') }}'
|
2017-01-31 17:44:31 +01:00
|
|
|
|
|
|
|
# Private services (IPv4)
|
2017-01-06 15:50:48 +01:00
|
|
|
SERVICESTCP3='{{ minifirewall_private_ports_tcp | join(' ') }}'
|
|
|
|
SERVICESUDP3='{{ minifirewall_private_ports_udp | join(' ') }}'
|
2017-01-09 16:38:21 +01:00
|
|
|
register: minifirewall_config_ports
|
|
|
|
|
2017-10-07 23:39:50 +02:00
|
|
|
- name: evomaintenance
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/default/minifirewall
|
|
|
|
line: "/sbin/iptables -A INPUT -p tcp --sport 5432 --dport 1024:65535 -s {{ item }} -m state --state ESTABLISHED,RELATED -j ACCEPT"
|
|
|
|
insertafter: "^# EvoMaintenance"
|
|
|
|
with_items: "{{ evomaintenance_hosts }}"
|
|
|
|
|
|
|
|
- name: remove minifirewall example rule for the evomaintenance
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/default/minifirewall
|
|
|
|
regexp: '^#.*(--sport 5432).*(-s X\.X\.X\.X)'
|
|
|
|
state: absent
|
|
|
|
when: evomaintenance_hosts != []
|
|
|
|
|
2017-01-09 16:38:21 +01:00
|
|
|
- name: restart minifirewall
|
2017-01-31 17:43:10 +01:00
|
|
|
# service:
|
|
|
|
# name: minifirewall
|
|
|
|
# state: restarted
|
|
|
|
command: /etc/init.d/minifirewall restart
|
|
|
|
register: minifirewall_init_restart
|
|
|
|
failed_when: "'starting IPTables rules is now finish : OK' not in minifirewall_init_restart.stdout"
|
|
|
|
changed_when: "'starting IPTables rules is now finish : OK' in minifirewall_init_restart.stdout"
|
2017-01-09 16:38:21 +01:00
|
|
|
when: minifirewall_is_running.rc == 0 and (minifirewall_config_ips | changed or minifirewall_config_ports | changed)
|
2017-04-11 16:13:10 +02:00
|
|
|
|
|
|
|
- debug:
|
|
|
|
var: minifirewall_init_restart
|
|
|
|
verbosity: 2
|