feat(ufw): let ufw_rules entries delete a rule
An entry with delete: true (a boolean) removes the rule it describes, passed to community.general.ufw's delete option. It lets a consumer replace a base rule, such as an open SSH allow by narrower ones, which the role could only add before. - rules.yml applies the delete entries after every other rule, whatever their place in the list, so the replacement exists before the old rule goes. - validate.yml: the schema check requires a boolean; a new check refuses a rule the list both adds and deletes (compared without the comment, port as a string), because the delete would win while the lock-out guard counted the add; the lock-out guard no longer counts a delete entry. - service_rules keeps its own key list and does not accept delete. Molecule: prepare stores a commented 9091 rule that the base list deletes with an uncommented entry listed first; verify checks it is gone and the untagged count is unchanged; the idempotence pass covers deleting a rule that is gone. Two new refusals: an SSH rule that is only deleted (lock-out guard) and a rule both added and deleted. Verified locally: validate.yml against localhost in check mode (the planned replacement list passes; the conflict, the delete-only SSH list and a non-boolean delete are refused) and the apply order. Not verified locally: the molecule scenario (CI only), including whether ufw matches the commented rule from an uncommented delete. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
1 parent
cb50e6f9a6
commit
10a620a2d9
8 files changed
+114
-8
No files matched your search
@@ -31,7 +31,8 @@
|
||||
changed_when: false
|
||||
environment: {LC_ALL: C}
|
||||
|
||||
# The four base rules plus the manual rule from prepare.yml. The refused runs
|
||||
# The four base rules plus the manual 7777 rule from prepare.yml (the base list deleted
|
||||
# its 9091 rule). The refused runs
|
||||
# (guard, invalid service inputs) added none.
|
||||
- name: Exactly the five untagged rules exist
|
||||
ansible.builtin.assert:
|
||||
@@ -48,6 +49,13 @@
|
||||
- ufw_verify_ufw.stdout is not search('7999')
|
||||
quiet: true
|
||||
|
||||
- name: The rule marked delete in the base list is gone
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ufw_verify_added.stdout_lines | select('search', '9091') | list | length == 0
|
||||
- ufw_verify_ufw.stdout is not search('9091')
|
||||
quiet: true
|
||||
|
||||
- name: The manual rule and the SSH rule were not touched
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
|
||||
Reference in new issue
Block a user