---

- name: packages
  apt:
    force_apt_get: true
    name: "{{ f2b_packages }}"
    state: latest

- name: directories
  loop:
    - /etc/fail2ban/filter.d
    - /etc/fail2ban/jail.d
    - /etc/fail2ban/action.d
  file:
    path: "{{ item }}"
    state: directory

- name: jail defaults
  notify: restart fail2ban
  template:
    src: jail.local.j2
    dest: /etc/fail2ban/jail.local

- name: filter
  notify: restart fail2ban
  copy:
    dest: /etc/fail2ban/filter.d/{{ f2b_filter.name }}.local
    content: "{{ f2b_filter.content }}"

- name: jail
  notify: restart fail2ban
  copy:
    dest: /etc/fail2ban/jail.d/{{ f2b_jail.name }}.local
    content: "{{ f2b_jail.content }}"

- name: service
  systemd:
    name: fail2ban
    enabled: true
    state: started

...
