2015-08-23 11:06:25 +02:00
|
|
|
---
|
|
|
|
|
2018-04-26 15:58:35 +02:00
|
|
|
- block:
|
2019-10-26 16:36:07 +02:00
|
|
|
- name: Set Ubuntu firewall packages
|
|
|
|
set_fact:
|
|
|
|
ubuntu_firewall_packages:
|
|
|
|
- firewalld
|
|
|
|
- tidy
|
|
|
|
- fail2ban
|
|
|
|
- python3-systemd # for fail2ban systemd backend
|
|
|
|
|
2018-04-26 15:58:35 +02:00
|
|
|
- name: Install firewalld and deps
|
2020-03-09 14:20:51 +01:00
|
|
|
when: ansible_distribution_version is version('16.04', '>=')
|
2019-10-26 16:36:07 +02:00
|
|
|
apt: pkg={{ ubuntu_firewall_packages }} state=present
|
2018-04-26 15:58:35 +02:00
|
|
|
|
2020-04-25 12:54:50 +02:00
|
|
|
- name: Remove ufw
|
|
|
|
when: ansible_distribution_version is version('16.04', '>=')
|
|
|
|
apt: pkg=ufw state=absent
|
|
|
|
|
2020-04-25 13:21:17 +02:00
|
|
|
# I'm not sure why, but you can use firewalld with the nftables backend even
|
|
|
|
# if nftables itself is not installed. In that case the only way to see the
|
|
|
|
# currently active rules is with firewall-cmd. I prefer installing nftables
|
|
|
|
# so that we can have somewhat of a parallel with iptables:
|
|
|
|
#
|
|
|
|
# nft list ruleset
|
|
|
|
#
|
|
|
|
# See: https://firewalld.org/2018/07/nftables-backend
|
|
|
|
- name: Install nftables
|
|
|
|
when: ansible_distribution_version is version('20.04', '==')
|
|
|
|
apt: pkg=nftables state=present
|
|
|
|
|
|
|
|
- name: Use nftables backend in firewalld
|
|
|
|
when: ansible_distribution_version is version('20.04', '==')
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/firewalld/firewalld.conf
|
|
|
|
regexp: '^FirewallBackend=iptables$'
|
|
|
|
line: 'FirewallBackend=nftables'
|
|
|
|
notify:
|
|
|
|
- restart firewalld
|
|
|
|
|
2018-04-26 15:58:35 +02:00
|
|
|
- name: Copy firewalld public zone file
|
2020-03-09 14:20:51 +01:00
|
|
|
when: ansible_distribution_version is version('16.04', '>=')
|
2018-04-26 15:58:35 +02:00
|
|
|
template: src=public.xml.j2 dest=/etc/firewalld/zones/public.xml owner=root mode=0600
|
2015-08-23 11:06:25 +02:00
|
|
|
|
2018-04-26 15:58:35 +02:00
|
|
|
- name: Format public.xml firewalld zone file
|
2020-03-09 14:20:51 +01:00
|
|
|
when: ansible_distribution_version is version('16.04', '>=')
|
2018-04-26 15:58:35 +02:00
|
|
|
command: tidy -xml -iq -m -w 0 /etc/firewalld/zones/public.xml
|
|
|
|
notify:
|
2019-10-05 11:29:30 +02:00
|
|
|
- restart firewalld
|
2019-10-05 11:28:30 +02:00
|
|
|
|
|
|
|
- name: Copy ipsets of abusive IPs
|
2020-03-09 14:20:51 +01:00
|
|
|
when: ansible_distribution_major_version is version('16.04', '>=')
|
2019-10-05 11:28:30 +02:00
|
|
|
copy: src={{ item }} dest=/etc/firewalld/ipsets/{{ item }} owner=root group=root mode=0600
|
|
|
|
loop:
|
|
|
|
- abusers-ipv4.xml
|
|
|
|
- abusers-ipv6.xml
|
|
|
|
notify:
|
2019-10-05 11:29:30 +02:00
|
|
|
- restart firewalld
|
2019-10-26 16:36:07 +02:00
|
|
|
|
|
|
|
- include_tasks: fail2ban.yml
|
2020-03-09 14:20:51 +01:00
|
|
|
when: ansible_distribution_version is version('16.04', '>=')
|
2018-04-25 17:58:31 +02:00
|
|
|
tags: firewall
|
2018-04-25 17:55:22 +02:00
|
|
|
|
|
|
|
# vim: set sw=2 ts=2:
|