From 9dcb933bf936c77045a0143282224e2a844d3f17 Mon Sep 17 00:00:00 2001 From: Dragonish Date: Sun, 15 Nov 2026 13:35:14 +0000 Subject: [PATCH] test(fail2ban): match the validation message in the ignoreip rejection cases 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 --- roles/fail2ban/molecule/default/converge.yml | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/roles/fail2ban/molecule/default/converge.yml b/roles/fail2ban/molecule/default/converge.yml index c0537ff..769c870 100644 --- a/roles/fail2ban/molecule/default/converge.yml +++ b/roles/fail2ban/molecule/default/converge.yml @@ -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