2017-08-07 12:09:13 +02:00
|
|
|
---
|
2019-04-16 13:48:48 +02:00
|
|
|
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
|
|
|
|
#
|
2017-08-07 12:09:13 +02:00
|
|
|
# tasks file for nftables
|
|
|
|
|
2019-04-16 13:48:48 +02:00
|
|
|
- name: Load specific OS vars for nftables
|
2017-08-07 12:09:13 +02:00
|
|
|
include_vars: "{{ item }}"
|
|
|
|
with_first_found:
|
|
|
|
- "{{ ansible_distribution|lower }}-{{ ansible_distribution_version }}.yml"
|
|
|
|
- "{{ ansible_distribution|lower }}.yml"
|
|
|
|
- "{{ ansible_os_family|lower }}.yml"
|
|
|
|
|
2019-04-16 13:48:48 +02:00
|
|
|
# Manage packages [[[1
|
|
|
|
- name: Ensure Nftables packages are in there desired state
|
2017-08-07 12:09:13 +02:00
|
|
|
package:
|
|
|
|
name: '{{ item }}'
|
|
|
|
state: '{{ nft_pkg_state }}'
|
|
|
|
with_items:
|
2019-02-27 13:28:27 +01:00
|
|
|
- '{{ nft_pkg_list | to_nice_json }}'
|
2019-02-27 13:31:25 +01:00
|
|
|
register: pkg_install_result
|
|
|
|
until: pkg_install_result is success
|
2018-05-16 14:38:33 +02:00
|
|
|
when: nft_enabled|bool
|
2017-08-07 12:09:13 +02:00
|
|
|
|
2019-04-16 13:48:48 +02:00
|
|
|
- name: Ensure old Iptables packages are in there desired state
|
2017-08-18 09:25:28 +02:00
|
|
|
apt:
|
|
|
|
name: '{{ item }}'
|
|
|
|
state: '{{ nft_old_pkg_state }}'
|
|
|
|
with_items:
|
2019-02-27 13:28:27 +01:00
|
|
|
- '{{ nft_old_pkg_list | to_nice_json }}'
|
2019-02-27 13:31:25 +01:00
|
|
|
register: pkg_remove_result
|
|
|
|
until: pkg_remove_result is success
|
2018-05-16 14:38:33 +02:00
|
|
|
when: (nft_enabled|bool and
|
|
|
|
nft_old_pkg_manage|bool)
|
|
|
|
|
2019-04-16 13:48:48 +02:00
|
|
|
# Common configuration [[[1
|
|
|
|
- name: Ensure to create nftables.d directory
|
2017-08-18 09:18:43 +02:00
|
|
|
file:
|
|
|
|
path: "{{ nft_conf_dir_path }}"
|
|
|
|
state: directory
|
|
|
|
mode: 0755
|
2018-05-16 14:38:33 +02:00
|
|
|
when: nft_enabled|bool
|
2017-08-18 09:18:43 +02:00
|
|
|
|
|
|
|
- name: CONFIG generate main conf file
|
2017-08-07 13:48:54 +02:00
|
|
|
template:
|
|
|
|
src: "{{ nft_main_conf_content }}"
|
|
|
|
dest: "{{ nft_main_conf_path }}"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
|
|
|
backup: yes
|
2018-07-25 15:06:31 +02:00
|
|
|
notify: ['Restart nftables service']
|
2018-05-16 14:38:33 +02:00
|
|
|
when: nft_enabled|bool
|
2017-08-07 17:37:41 +02:00
|
|
|
|
2019-04-16 13:48:48 +02:00
|
|
|
- name: CONFIG generate vars definition file
|
2017-08-07 17:37:41 +02:00
|
|
|
template:
|
2019-04-16 13:48:48 +02:00
|
|
|
src: "{{ nft_define_conf_content }}"
|
|
|
|
dest: "{{ nft_define_conf_path }}"
|
2017-08-07 17:37:41 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
|
|
|
backup: yes
|
2018-07-25 15:06:31 +02:00
|
|
|
notify: ['Restart nftables service']
|
2018-05-16 14:38:33 +02:00
|
|
|
when: nft_enabled|bool
|
2017-08-08 12:11:58 +02:00
|
|
|
|
2019-04-16 13:48:48 +02:00
|
|
|
- name: CONFIG generate sets file
|
2017-08-08 15:35:05 +02:00
|
|
|
template:
|
2019-04-16 13:48:48 +02:00
|
|
|
src: "{{ nft_set_conf_content }}"
|
|
|
|
dest: "{{ nft_set_conf_path }}"
|
2017-08-08 15:35:05 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
|
|
|
backup: yes
|
2018-07-25 15:06:31 +02:00
|
|
|
notify: ['Restart nftables service']
|
2018-05-16 14:38:33 +02:00
|
|
|
when: nft_enabled|bool
|
2017-08-08 15:35:05 +02:00
|
|
|
|
2019-04-16 13:48:48 +02:00
|
|
|
# Filter table content [[[1
|
|
|
|
- name: Filter table - generate input rules file
|
2017-08-08 12:11:58 +02:00
|
|
|
template:
|
2019-04-16 13:48:48 +02:00
|
|
|
src: "{{ nft_input_conf_content }}"
|
|
|
|
dest: "{{ nft_input_conf_path }}"
|
2017-08-08 12:11:58 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
|
|
|
backup: yes
|
2018-07-25 15:06:31 +02:00
|
|
|
notify: ['Restart nftables service']
|
2018-05-16 14:38:33 +02:00
|
|
|
when: nft_enabled|bool
|
2017-08-08 14:32:59 +02:00
|
|
|
|
2019-04-16 13:48:48 +02:00
|
|
|
- name: Filter table - generate output rules file
|
2017-08-08 14:32:59 +02:00
|
|
|
template:
|
2019-04-16 13:48:48 +02:00
|
|
|
src: "{{ nft_output_conf_content }}"
|
|
|
|
dest: "{{ nft_output_conf_path }}"
|
2017-08-08 14:32:59 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0755
|
|
|
|
backup: yes
|
2018-07-25 15:06:31 +02:00
|
|
|
notify: ['Restart nftables service']
|
2018-05-16 14:38:33 +02:00
|
|
|
when: nft_enabled|bool
|
2017-08-09 14:27:07 +02:00
|
|
|
|
2019-04-16 13:48:48 +02:00
|
|
|
# Manage service [[[1
|
|
|
|
- name: Install Debian systemd service unit
|
2018-02-06 16:58:18 +01:00
|
|
|
template:
|
|
|
|
src: '{{ nft_service_unit_content }}'
|
|
|
|
dest: '{{ nft_service_unit_path }}'
|
|
|
|
owner: 'root'
|
|
|
|
group: 'root'
|
|
|
|
mode: '0644'
|
|
|
|
register: nftables__register_systemd_service
|
2018-05-16 14:38:33 +02:00
|
|
|
when: (nft_enabled|bool and
|
|
|
|
nft_service_manage|bool)
|
2018-07-25 15:06:31 +02:00
|
|
|
notify: ['Restart nftables service']
|