Skip to content

Commit

Permalink
Update no-handler rule to accept 'not changed'
Browse files Browse the repository at this point in the history
  • Loading branch information
jpopelka authored and ssbarnea committed Mar 31, 2023
1 parent f888a6a commit 248930c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ansiblelint/rules/no_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
def _changed_in_when(item: str) -> bool:
item_list = item.split()

if not isinstance(item, str) or "and" in item_list:
if not isinstance(item, str) or {"and", "not"} & set(item_list):
return False
return any(
changed in item
Expand Down Expand Up @@ -89,7 +89,7 @@ def matchtask(
changed_when: true
"""

SUCCEED_WHEN_AND = """
SUCCEED_WHEN = """
- hosts: all
tasks:
- name: Registering task 1
Expand All @@ -105,6 +105,15 @@ def matchtask(
- name: Use when task
command: echo Hello
when: r1.changed and r2.changed
- name: Registering task
command: echo Hello
register: r
changed_when: true
- name: When task not changed
command: echo Not changed
when: not r.changed
"""

FAIL_RESULT_IS_CHANGED = """
Expand Down Expand Up @@ -137,7 +146,7 @@ def test_succeed_changed_when(rule_runner: Any) -> None:
)
def test_succeed_when_and(rule_runner: Any) -> None:
"""See https://github.com/ansible/ansible-lint/issues/1526."""
results = rule_runner.run_playbook(SUCCEED_WHEN_AND)
results = rule_runner.run_playbook(SUCCEED_WHEN)
assert len(results) == 0

@pytest.mark.parametrize(
Expand Down

0 comments on commit 248930c

Please sign in to comment.