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
27 lines
1.3 KiB
YAML
27 lines
1.3 KiB
YAML
---
|
|
# Rules marked delete: true are applied after every other rule, whatever their place in
|
|
# the list, so a replacement rule exists before the rule it replaces is removed. A delete
|
|
# is sent without its comment: ufw matches a delete that has no comment against the rule
|
|
# whatever its comment, but one with a different comment matches nothing and does nothing.
|
|
- name: Apply UFW rules
|
|
become: true
|
|
community.general.ufw:
|
|
rule: "{{ ufw_rule.rule }}"
|
|
port: "{{ ufw_rule.port | default(omit) }}"
|
|
proto: "{{ ufw_rule.proto | default(omit) }}"
|
|
from: "{{ ufw_rule.from | default(omit) }}"
|
|
to: "{{ ufw_rule.to | default(omit) }}"
|
|
interface: "{{ ufw_rule.interface | default(omit) }}"
|
|
direction: "{{ ufw_rule.direction | default(omit) }}"
|
|
comment: "{{ omit if ufw_rule.delete | default(false) else ufw_rule.comment | default(omit) }}"
|
|
delete: "{{ ufw_rule.delete | default(omit) }}"
|
|
loop: "{{ (ufw_aggregated_rules | default([]) | reject('in', ufw_rules_deleted) | list) + ufw_rules_deleted }}"
|
|
loop_control:
|
|
loop_var: ufw_rule
|
|
vars:
|
|
ufw_rules_deleted: "{{ ufw_aggregated_rules | default([]) | selectattr('delete', 'defined') | selectattr('delete') | list }}"
|
|
when:
|
|
- ufw_enabled
|
|
- ufw_manage_rules
|
|
- __ufw_can_configure
|