fix(ufw, fail2ban): --check passes on a host without the package #478

Open
opened 2026-11-29 15:54:25 +00:00 by Claude · 0 comments
Owner

Part of #419

Problem

On a host where ufw or fail2ban is not installed yet, ansible-playbook --check with either role fails. The package task only reports changed in check mode, so the tasks after it run against a missing binary, a missing config directory or a missing systemd unit. Both READMEs document this as a limit (the ufw and fail2ban READMEs, "check mode" notes). It has to be fixed before #435 removes the baked packages from the molecule images: the scenarios run check before converge, so their first check would then fail.

Proposal

  • Each role registers its package install as __ufw_install or __fail2ban_install.
  • Every task that needs the package is skipped under check mode when that install would change, as the check-mode rule in roles/AGENTS.md describes. That covers config templates, the ufw module, the systemd service, flush_handlers, validation commands, the jail tasks and the handlers.
  • fail2ban uses the standard not ansible_check_mode or <install is not changed> guard.
  • ufw uses its existing check-mode probe instead of ansible_check_mode, because that variable is not set for a play-level check_mode: true inside include_role.
  • Both READMEs drop the "fails without the package" limit and say that a preview on a fresh host skips the configuration.
  • A new ufw scenario, check-absent, runs dependency, create, prepare and check, with no destroy. Its prepare purges ufw and refreshes the APT cache.
  • A bugfix changelog fragment is added.

Acceptance criteria

  • The ufw check-absent scenario passes in CI: --check succeeds on a host without ufw (Molecule check).
  • The ufw and fail2ban default scenarios still pass, including idempotence (Molecule check).
  • Neither README says --check fails without the package (review).
  • A bugfix fragment exists in changelogs/fragments/, and pre-commit run --all-files passes.
  • python3 -m unittest discover -s tests/scripts passes, including the scenario-structure tests for the new scenario.

Assisted-by: Claude Code

Part of #419 ### Problem On a host where `ufw` or `fail2ban` is not installed yet, `ansible-playbook --check` with either role fails. The package task only reports `changed` in check mode, so the tasks after it run against a missing binary, a missing config directory or a missing systemd unit. Both READMEs document this as a limit (the ufw and fail2ban READMEs, "check mode" notes). It has to be fixed before #435 removes the baked packages from the molecule images: the scenarios run `check` before `converge`, so their first check would then fail. ### Proposal - Each role registers its package install as `__ufw_install` or `__fail2ban_install`. - Every task that needs the package is skipped under check mode when that install would change, as the check-mode rule in `roles/AGENTS.md` describes. That covers config templates, the ufw module, the systemd service, `flush_handlers`, validation commands, the jail tasks and the handlers. - fail2ban uses the standard `not ansible_check_mode or <install is not changed>` guard. - ufw uses its existing check-mode probe instead of `ansible_check_mode`, because that variable is not set for a play-level `check_mode: true` inside `include_role`. - Both READMEs drop the "fails without the package" limit and say that a preview on a fresh host skips the configuration. - A new ufw scenario, `check-absent`, runs `dependency`, `create`, `prepare` and `check`, with no `destroy`. Its prepare purges ufw and refreshes the APT cache. - A bugfix changelog fragment is added. ### Acceptance criteria - [ ] The ufw `check-absent` scenario passes in CI: `--check` succeeds on a host without ufw (Molecule check). - [ ] The ufw and fail2ban default scenarios still pass, including idempotence (Molecule check). - [ ] Neither README says `--check` fails without the package (review). - [ ] A bugfix fragment exists in `changelogs/fragments/`, and `pre-commit run --all-files` passes. - [ ] `python3 -m unittest discover -s tests/scripts` passes, including the scenario-structure tests for the new scenario. Assisted-by: Claude Code
Claude added this to the CI velocity (emergency) milestone 2026-11-29 15:54:25 +00:00
Claude added the Kind/Bug
Status
Ready for Agent
labels 2026-11-29 15:54:25 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: Mortis/Kamino#478