Under --check the package task only reports a change, so on a fresh host the tasks after it ran against a missing binary, /etc directory or unit and failed. They now skip when the install would change in check mode. fail2ban registers __fail2ban_install and guards its template, service, config test, jail tasks and handler with the standard `not ansible_check_mode or ... is not changed` guard. ufw registers __ufw_install plus a command probe (ansible_check_mode is not set for a play-level check_mode inside include_role), combined once in vars/main.yml as __ufw_can_configure. flush_handlers is left unguarded: the handler it runs is guarded itself. A check-absent scenario per role purges the package, refreshes the APT cache and runs only `check`, so each fix is tested; one scenario covering both would make the ufw role a user of fail2ban and select the ufw and traefik scenarios on every fail2ban change. Fixes #478 Assisted-by: Claude Code
22 lines
689 B
YAML
22 lines
689 B
YAML
---
|
|
# Run only under --check (the check step): fail2ban is not installed, so the tasks that need it skip.
|
|
- name: Converge the base role on a host without fail2ban
|
|
hosts: all
|
|
roles:
|
|
- role: mortis.kamino.fail2ban
|
|
|
|
- name: Converge a service jail on a host without fail2ban
|
|
hosts: all
|
|
tasks:
|
|
- name: Service jail with a journalmatch
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.fail2ban
|
|
tasks_from: service_jail
|
|
vars:
|
|
fail2ban_service_name: svc-a
|
|
fail2ban_service_jail:
|
|
port: "8080"
|
|
journalmatch: "_SYSTEMD_UNIT=ssh.service"
|
|
fail2ban_service_filter:
|
|
failregex: "^.*denied for <HOST>.*$"
|