--- - name: Converge the base role (jail.local, sshd jail on the systemd backend) hosts: all roles: - role: mortis.kamino.fail2ban # The entry point service roles use. Two services must not overwrite each other: # each gets its own jail.d file. - name: Converge two service jails through the entry point hosts: all tasks: - name: Service jail with a logpath ansible.builtin.include_role: name: mortis.kamino.fail2ban tasks_from: service_jail vars: fail2ban_service_name: svc-a fail2ban_service_jail: port: "8080" logpath: /var/log/svc-a.log maxretry: 4 fail2ban_service_filter: failregex: "^.*auth failure from .*$" - name: Service jail with a journalmatch ansible.builtin.include_role: name: mortis.kamino.fail2ban tasks_from: service_jail vars: fail2ban_service_name: svc-b fail2ban_service_jail: port: "9090" journalmatch: "_SYSTEMD_UNIT=ssh.service" fail2ban_service_filter: failregex: "^.*denied for .*$" # An input the entry point must reject. The block proves it is refused (the # verify step proves no file was left behind); the play still passes, so the # idempotence run stays clean. - name: Missing failregex is rejected block: - name: Service jail without a failregex ansible.builtin.include_role: name: mortis.kamino.fail2ban tasks_from: service_jail vars: fail2ban_service_name: svc-bad fail2ban_service_jail: logpath: /var/log/svc-a.log fail2ban_service_filter: {} - name: Fail when the invalid input was accepted ansible.builtin.fail: msg: service_jail accepted a filter without a failregex rescue: - name: The entry point refused the input ansible.builtin.debug: msg: Rejected as expected