Files
Kamino/roles/ufw/tasks/main.yml
T
Defame1297 c617bee02a
Build / build (pull_request) Successful in 33s
Molecule / select (pull_request) Successful in 2s
Lint / lint (pull_request) Successful in 4m5s
Molecule / scenarios (pull_request) Successful in 12m51s
Molecule / Result (pull_request) Successful in 0s
fix(ufw): mask nftables.service so an upgrade cannot flush the rules
When nftables.service is enabled, the nftables package's postinst
restarts it on upgrade. The stock /etc/nftables.conf begins with
`flush ruleset` and the unit's ExecStop flushes too, so every rule ufw
and Docker loaded was deleted until they reloaded.

The role now masks the unit without stopping it, gated on ufw_enabled
and the new opt-out input ufw_mask_nftables. systemd refuses every job
but a stop on a masked unit, so the postinst's try-restart fails
before anything runs (the postinst ignores the failure) and the unit
does not start at boot. Masking works when the unit is absent too.

Assisted-by: Claude Code:claude-opus-5-5
2026-12-05 22:33:26 +00:00

57 lines
2.1 KiB
YAML

---
# Stray variable guard: the role does not discover rules by variable name, so a variable
# named like <role>_ufw_rules / <role>_ufw_before_rules would be silently ignored. Fail instead,
# naming it. The base lists ufw_rules and ufw_before_rules have no prefix before "_ufw_" and do not
# match; the producers' <role>_ufw_service_rules do not either. varnames covers every variable
# visible to the host (inventory, play, role and extra vars), unlike the deprecated vars dictionary.
- name: Refuse stray *_ufw_rules and *_ufw_before_rules variables
ansible.builtin.assert:
that: ufw_stray_rule_variables | length == 0
fail_msg: >-
ufw does not read variables named like *_ufw_rules or *_ufw_before_rules, so they would
be ignored: {{ ufw_stray_rule_variables | join(', ') }}. Pass the rules of a service through
the ufw role's tasks_from: service_rules entry point (ufw_service_name and ufw_service_rules),
or move base rules into ufw_rules. Delete or rename the leftover definition in group_vars,
host_vars or the play.
quiet: true
vars:
ufw_stray_rule_variables: >-
{{ lookup('ansible.builtin.varnames', '^.+_ufw_(before_)?rules$', wantlist=True) | sort }}
tags: [ufw, always]
- name: Import UFW install task
ansible.builtin.import_tasks: install.yml
tags: [ufw, ufw_install]
- name: Import UFW sysctl task
ansible.builtin.import_tasks: sysctl.yml
tags: [ufw, ufw_sysctl]
- name: Import UFW aggregate task
ansible.builtin.import_tasks: aggregate_rules.yml
tags: [ufw, ufw_aggregate]
- name: Import UFW validate task
ansible.builtin.import_tasks: validate.yml
tags: [ufw, ufw_validate]
- name: Import UFW nftables task
ansible.builtin.import_tasks: nftables.yml
tags: [ufw, ufw_nftables]
- name: Import UFW before rules task
ansible.builtin.import_tasks: before_rules.yml
tags: [ufw, ufw_before_rules]
- name: Import UFW defaults task
ansible.builtin.import_tasks: defaults.yml
tags: [ufw, ufw_defaults]
- name: Import UFW rules task
ansible.builtin.import_tasks: rules.yml
tags: [ufw, ufw_rules]
- name: Import UFW enable task
ansible.builtin.import_tasks: enable.yml
tags: [ufw, ufw_enable]