test(fail2ban): match the validation message in the ignoreip rejection cases
Build / build (pull_request) Successful in 13s
Lint / lint (pull_request) Successful in 28s
Molecule / molecule (pull_request) Successful in 1m2s

The three rejection cases only printed "Rejected as expected", so they would
also pass when the role failed for another reason. Assert that the failure
carries the validation message of fail2ban_ignoreip.

Assisted-by: Claude Code
This commit is contained in:
Dragonish committed 2026-11-15 13:35:14 +00:00
1 parent 0703ab85dc
commit 9dcb933bf9
1 file changed
+12 -9
+12 -9
View File
@@ -80,9 +80,10 @@
ansible.builtin.fail:
msg: fail2ban accepted an ignoreip entry with whitespace
rescue:
- name: The role refused the input
ansible.builtin.debug:
msg: Rejected as expected
- name: The role refused the input for the right reason
ansible.builtin.assert:
that: "'fail2ban_ignoreip must be' in ansible_failed_result.msg"
quiet: true
# argument_specs accepts a plain string for a list option and leaves it a string, which would render one character per entry.
# validate.yml refuses it; the verify step proves it never reached jail.local.
@@ -100,9 +101,10 @@
ansible.builtin.fail:
msg: fail2ban accepted a scalar string for fail2ban_ignoreip
rescue:
- name: The role refused the input
ansible.builtin.debug:
msg: Rejected as expected
- name: The role refused the input for the right reason
ansible.builtin.assert:
that: "'fail2ban_ignoreip must be' in ansible_failed_result.msg"
quiet: true
# A semicolon after whitespace starts an inline comment in Fail2Ban's config files, which would drop the rest of the ignoreip line
# without an error, so validate.yml refuses it. The verify step proves it never reached jail.local.
@@ -122,6 +124,7 @@
ansible.builtin.fail:
msg: fail2ban accepted an ignoreip entry that starts with a semicolon
rescue:
- name: The role refused the input
ansible.builtin.debug:
msg: Rejected as expected
- name: The role refused the input for the right reason
ansible.builtin.assert:
that: "'fail2ban_ignoreip must be' in ansible_failed_result.msg"
quiet: true