Files
Kamino/roles/fail2ban/tasks/validate.yml
T
DragonishandClaude Sonnet 5.5 57b15df1ac
Build / build (pull_request) Successful in 11s
Lint / lint (pull_request) Successful in 26s
Molecule / molecule (pull_request) Successful in 52s
feat(fail2ban): add fail2ban_ignoreip to exempt trusted addresses
Write fail2ban_ignoreip as ignoreip in the [DEFAULT] section of jail.local, so
it applies to every jail, the service jails in jail.d included. The default is
Fail2Ban's own (127.0.0.1/8 and ::1). Entries are validated (no whitespace,
\Z-anchored) because they are joined into one line.

The first run after upgrading adds the [DEFAULT] section and restarts Fail2Ban
once.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q72rsMCgwaR1sbYZangwbp
2026-11-15 11:55:17 +00:00

23 lines
1002 B
YAML

---
- name: Validate Fail2Ban jails
ansible.builtin.assert:
that:
- item.name is defined
- item.enabled is defined
- item.filter is defined
- item.logpath is defined or item.journalmatch is defined or item.backend | default('') == 'systemd'
- item.maxretry is defined
- item.bantime is defined
- item.findtime is defined
fail_msg: "Invalid Fail2Ban jail: {{ item }}"
loop: "{{ fail2ban_jails }}"
# Entries are joined with spaces into one ignoreip line, so an entry holding whitespace would silently become two. The
# pattern ends in \Z, not $: Python's $ also matches before a trailing newline. The type of the list is argument_specs' job.
- name: Validate the Fail2Ban ignoreip entries
ansible.builtin.assert:
that:
- fail2ban_ignoreip | select('match', '^\S+\Z') | list | length == fail2ban_ignoreip | length
fail_msg: "fail2ban_ignoreip entries must be non-empty and hold no whitespace: {{ fail2ban_ignoreip }}"
quiet: true