diff --git a/tasks/fail2ban.yml b/tasks/fail2ban.yml index 1b7a7f8..b0e06ef 100644 --- a/tasks/fail2ban.yml +++ b/tasks/fail2ban.yml @@ -12,7 +12,7 @@ state: present when: ansible_os_family == 'Debian' -- name: Copy fail2ban custom configuration file into place. +- name: Copy jail custom configuration file into place. template: src: "{{ security_fail2ban_custom_configuration_template }}" dest: /etc/fail2ban/jail.local @@ -22,6 +22,19 @@ notify: - reload fail2ban +- name: Copy fail2ban custom configuration file into place. + template: + src: fail2ban.local.j2 + dest: /etc/fail2ban/fail2ban.local + owner: root + group: root + mode: 0644 + when: + - ansible_os_family == 'Debian' + - ansible_distribution_major_version | int >= 12 + notify: + - reload fail2ban + - name: Ensure fail2ban is running and enabled on boot. service: name: fail2ban diff --git a/templates/fail2ban.local.j2 b/templates/fail2ban.local.j2 new file mode 100644 index 0000000..59bc278 --- /dev/null +++ b/templates/fail2ban.local.j2 @@ -0,0 +1,2 @@ +[Definition] +logtarget = SYSTEMD-JOURNAL diff --git a/templates/jail.local.j2 b/templates/jail.local.j2 index de9b947..2670d99 100644 --- a/templates/jail.local.j2 +++ b/templates/jail.local.j2 @@ -2,3 +2,6 @@ enabled = true port = {{ security_ssh_port }} filter = sshd +{% if ansible_os_family == 'Debian' and ansible_distribution_major_version | int >= 12 %} +backend = systemd +{% endif %}