Files
Kamino/roles/ufw/molecule/default/prepare.yml
T
Defame1297andClaude Opus 5.5 e18db424ec
Build / build (pull_request) Successful in 11s
Lint / lint (pull_request) Failing after 25s
Molecule / molecule (pull_request) Failing after 5m42s
feat(ufw): add the ufw role
Copied from the environment repository's local role. The files are
identical except: galaxy namespace mortis; comments, argument_specs
descriptions and the README scrubbed of environment references (issue
numbers, CI runs, playbooks, inventory paths and groups, scripts and
caller roles by name), with the technical explanation kept and reworded
generically; the stray-variable guard's fail message drops its issue
reference; the molecule scenario calls the role by its FQCN
(mortis.kamino.ufw), follows the Kamino scenario conventions
(kamino-molecule header, scenario.test_sequence) and no longer sets
ANSIBLE_COLLECTIONS_PATH or ANSIBLE_ROLES_PATH. No variable, default,
argument_specs type or task logic changed; the test coverage is the same.

The README follows the other Kamino roles: purpose, the main,
service_rules and orphan_rules entry points, variables, and example
plays with the FQCN and tasks_from. The meta licence stays
GPL-3.0-or-later AND GPL-3.0-only (templates/before.rules.j2 is derived
from ufw's own file, already annotated in REUSE.toml and NOTICE).
galaxy.yml's dependency comment names ufw as a community.general user.

Not verified locally: the molecule scenario (it runs on the
kamino-molecule runner in CI) and ansible-test sanity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
2026-11-14 16:43:29 +00:00

75 lines
3.9 KiB
YAML

---
# Rules that must already be stored before the role runs, so converge stays
# idempotent while still exercising the purge: a second converge finds them
# deleted (or kept, for the report-only owner) and changes nothing. ufw is
# installed here; it stays inactive until the role enables it.
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Install ufw
ansible.builtin.package:
name: mortis.kamino.ufw
state: present
# An application profile whose name holds openssh, for the orphan seeds below.
- name: Define an application profile named like SSH
ansible.builtin.copy:
dest: /etc/ufw/applications.d/orphan-openssh
mode: "0644"
content: |
[OrphanOpenSSH]
title=Orphan test
description=Test profile for the orphan_rules molecule seeds
ports=22/tcp
- name: Store a manual rule without a tag
community.general.ufw:
rule: allow
port: "7777"
proto: tcp
comment: manual
# Owners svc_c, svc_d and svc_e keep rules in converge.yml that these entries are
# not part of: a stale rule to purge, a rule of a removed service, a stale rule
# that is only reported.
- name: Store tagged rules that are no longer wanted
community.general.ufw:
rule: allow
port: "{{ ufw_prepare_rule.port | default(omit) }}"
proto: "{{ 'tcp' if ufw_prepare_rule.port is defined else omit }}"
from: "{{ ufw_prepare_rule.from | default(omit) }}"
interface: "{{ ufw_prepare_rule.interface | default(omit) }}"
direction: "{{ ufw_prepare_rule.direction | default(omit) }}"
name: "{{ ufw_prepare_rule.name | default(omit) }}"
comment: "{{ ufw_prepare_rule.comment }}"
loop:
# svc_c: the old spec of a rule whose port changed (key of allow|7001|tcp||||in)
- {port: 7001, comment: "ansible-ufw[svc_c:128c086248]: old"}
- {port: 7002, comment: "ansible-ufw[svc_d:abcdef0123]: gone"}
- {port: 7003, comment: "ansible-ufw[svc_e:aaaaaaaaaa]: kept"}
# svc_h: a stale rule that looks like an SSH rule, which a purge must skip
- {port: 22, from: 10.9.0.0/16, comment: "ansible-ufw[svc_h:bbbbbbbbbb]: old"}
# orphan_rules: svc_o1 and svc_o2 are never listed as managed owners in converge.yml.
# svc_o2's rule looks like the SSH rule and must survive a purge; svc_m is managed
# but its role is never called, so its rule must survive too.
- {port: 7401, comment: "ansible-ufw[svc_o1:1111111111]: orphan one"}
- {port: 7402, comment: "ansible-ufw[svc_o1:2222222222]: orphan two"}
- {port: 22, from: 10.9.1.0/24, comment: "ansible-ufw[svc_o2:3333333333]: orphan ssh lookalike"}
- {port: 7501, comment: "ansible-ufw[svc_m:4444444444]: managed, never called"}
# orphan_rules, owner svc_o3: tagged orphans that may carry SSH and must be kept by a
# purge: no port (interface only), no port (source only), a range spanning 22, an
# application profile named like SSH.
- {interface: tailscale0, direction: in, comment: "ansible-ufw[svc_o3:5555555551]: no port"}
- {from: 10.20.0.0/24, comment: "ansible-ufw[svc_o3:5555555552]: source only"}
- {port: "20:30", comment: "ansible-ufw[svc_o3:5555555553]: range over 22"}
- {name: OrphanOpenSSH, comment: "ansible-ufw[svc_o3:5555555554]: openssh profile"}
# service_rules purge of svc_p (converge.yml keeps only a rule for 7602): 7601 is stale
# and deleted, the other three are stale and may carry SSH, so they stay.
- {port: 7601, comment: "ansible-ufw[svc_p:6666666664]: stale numeric"}
- {interface: wg0, direction: in, comment: "ansible-ufw[svc_p:6666666661]: no port"}
- {from: 10.30.0.0/24, comment: "ansible-ufw[svc_p:6666666662]: source only"}
- {port: "40:50", comment: "ansible-ufw[svc_p:6666666663]: range"}
loop_control:
loop_var: ufw_prepare_rule