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
35 lines
1.1 KiB
YAML
35 lines
1.1 KiB
YAML
---
|
|
# community.general.ufw runs `ufw -f enable` and `ufw logging` unconditionally
|
|
# (rewriting /etc/ufw/user.rules and re-applying sysctl.conf), so only call it
|
|
# when UFW is inactive or its logging setting differs from ufw_logging.
|
|
- name: Read current UFW status
|
|
become: true
|
|
ansible.builtin.command: ufw status verbose
|
|
register: ufw_status_verbose
|
|
changed_when: false
|
|
check_mode: false
|
|
environment:
|
|
LC_ALL: C
|
|
LANGUAGE: C
|
|
when:
|
|
- ufw_enabled
|
|
- __ufw_can_configure | default(true)
|
|
|
|
- name: Enable UFW
|
|
become: true
|
|
community.general.ufw:
|
|
state: enabled
|
|
logging: "{{ ufw_logging }}"
|
|
vars:
|
|
# "on" matches any level ("Logging: on (low)"); "off" and levels match exactly.
|
|
ufw_logging_expected: >-
|
|
{{ 'Logging: off' if ufw_logging == 'off'
|
|
else 'Logging: on' if ufw_logging == 'on'
|
|
else 'Logging: on (' ~ ufw_logging ~ ')' }}
|
|
when:
|
|
- ufw_enabled
|
|
- __ufw_can_configure | default(true)
|
|
- >-
|
|
'Status: active' not in ufw_status_verbose.stdout
|
|
or ufw_logging_expected not in ufw_status_verbose.stdout
|