Copied from the environment repository's roles/fail2ban and scrubbed for the Collection: galaxy namespace mortis, the molecule scenario calls the role by its FQCN (and takes its paths from the workflow, like docker's), README examples use mortis.kamino.fail2ban, repository-local issue references are dropped. mock_roles in .ansible-lint lists the new FQCN. Not verified locally: the molecule scenario (runs on the kamino-molecule runner in CI) and ansible-test sanity. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
58 lines
2.0 KiB
YAML
58 lines
2.0 KiB
YAML
---
|
|
- 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 <HOST>.*$"
|
|
|
|
- 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 <HOST>.*$"
|
|
|
|
# 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
|