Skip to content

Commit

Permalink
Find changed not only in first when condition
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
klaus-tux committed Apr 26, 2023
1 parent 3c103b4 commit 546f316
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions examples/playbooks/no_handler_fail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/no_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"),
),
)
Expand Down

0 comments on commit 546f316

Please sign in to comment.