From 546f316df072f4eb6a4fb55032804b22db2edbae Mon Sep 17 00:00:00 2001 From: Klaus Sperner Date: Wed, 26 Apr 2023 17:07:49 +0200 Subject: [PATCH] Find changed not only in first when condition Prior to this change, the rule no_handler did not find changed if it was in the second when condition or any later when condition. This commit fixes the implementation so that it finds changed in the following when conditions as well. --- examples/playbooks/no_handler_fail.yml | 7 +++++++ src/ansiblelint/rules/no_handler.py | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/playbooks/no_handler_fail.yml b/examples/playbooks/no_handler_fail.yml index efad891994..505527f6cc 100644 --- a/examples/playbooks/no_handler_fail.yml +++ b/examples/playbooks/no_handler_fail.yml @@ -32,3 +32,10 @@ when: - result['changed'] == true - another_condition + + - name: This should be a handler 6 + ansible.builtin.debug: + msg: why isn't this a handler + when: + - first_condition + - result.changed diff --git a/src/ansiblelint/rules/no_handler.py b/src/ansiblelint/rules/no_handler.py index 11e3c24d7e..40ec5554f7 100644 --- a/src/ansiblelint/rules/no_handler.py +++ b/src/ansiblelint/rules/no_handler.py @@ -75,7 +75,8 @@ def matchtask( if isinstance(when, list): for item in when: - return _changed_in_when(item) + if _changed_in_when(item): + return True if isinstance(when, str): return _changed_in_when(when) return False @@ -90,7 +91,7 @@ def matchtask( @pytest.mark.parametrize( ("test_file", "failures"), ( - pytest.param("examples/playbooks/no_handler_fail.yml", 6, id="fail"), + pytest.param("examples/playbooks/no_handler_fail.yml", 7, id="fail"), pytest.param("examples/playbooks/no_handler_pass.yml", 0, id="pass"), ), )