--- # Runs after the idempotence check and before verify. Record the daemon's PID, ban an address, change a jail setting so jail.local # is rewritten and the handler fires, and let verify prove the daemon was reloaded, not restarted. The PID is the discriminator: # a restart starts a new process, a reload does not. The ban alone would not tell them apart, because Fail2Ban restores unexpired # bans from its database when a jail starts. The PID goes to a file because verify is a separate play. - name: Change a jail setting while an address is banned hosts: all gather_facts: false tasks: - name: Read the unit state of the Fail2Ban daemon ansible.builtin.systemd: name: fail2ban register: fail2ban_side_effect_unit - name: Keep the main PID for the verify step ansible.builtin.copy: content: "{{ fail2ban_side_effect_unit.status.MainPID }}\n" dest: /run/fail2ban-molecule-mainpid mode: "0644" # 198.51.100.0/24 is TEST-NET-2 (RFC 5737), outside the 192.0.2.0/24 the converge step ignores. - name: Ban a documentation address on the sshd jail ansible.builtin.command: fail2ban-client set sshd banip 198.51.100.77 changed_when: true - name: Rewrite jail.local with a different maxretry ansible.builtin.include_role: name: mortis.kamino.fail2ban vars: fail2ban_ignoreip: - 127.0.0.1/8 - "::1" - 192.0.2.0/24 fail2ban_jails: - name: sshd enabled: true port: ssh filter: sshd backend: systemd maxretry: 4 bantime: "1h" findtime: "10m"