Files
Kamino/roles/ufw/tasks/rules.yml
T
Defame1297 a9a973a523
Build / build (pull_request) Successful in 38s
Lint / lint (pull_request) Successful in 4m29s
Molecule / molecule (pull_request) Canceled after 1m14s
fix(ufw, fail2ban): keep the check-mode guard out of vars and test service_rules
vars/ holds constants only, so ufw's __ufw_can_configure is now a
set_fact after the install probe; the guards default it to true when the
install tasks were skipped by tags.

service_rules already skips its reconcile when `ufw status` fails under
check mode; the ufw check-absent scenario now calls it so CI holds that.
The fail2ban service jail task's tags sit with the task again, above the
comment of the configuration test.

Refs #478

Assisted-by: Claude Code
2026-11-29 17:10:25 +00:00

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 | default(true)