-
Notifications
You must be signed in to change notification settings - Fork 660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive no-handler
with and
in when
#1526
Comments
Hi @MarcinWieczorek, can you supply a playbook with an example of when logical Using - name: handler 'and' testcase
hosts: localhost
tasks:
- name: registering task 1
command: echo "Task 1"
register: r1
changed_when: true
- name: registering task 2
command: echo "Task 2"
register: r2
changed_when: false
- name: registering task 3
command: echo "Task 3"
register: r3
changed_when: true
- name: registering handler task 1
command: echo "Handler task 1"
register: r4
when: r1.changed and (not r2.changed and r3.changed)
notify:
- Debug handler task
handlers:
- name: Debug handler task
debug:
msg: "r1: {{ r1.stdout_lines }} r2: {{ r2.stdout_lines }} r3: {{ r3.stdout_lines }} r4: {{ r4.stdout_lines }}" PLAY [handler 'and' testcase] *******************************************************
TASK [Gathering Facts] **************************************************************
ok: [127.0.0.1]
TASK [registering task 1] *************************************************************
changed: [127.0.0.1]
TASK [registering task 2] ************************************************************
ok: [127.0.0.1]
TASK [registering task 3] ************************************************************
changed: [127.0.0.1]
TASK [registering handler task 1] ****************************************************
changed: [127.0.0.1]
RUNNING HANDLER [Debug handler task] ******************************************
ok: [127.0.0.1] => {
"msg": "r1: ['Task 1'] r2: ['Task 2'] r3: ['Task 3'] r4: ['Handler task 1']"
}
PLAY RECAP ************************************************************************
127.0.0.1 : ok=6 changed=3 |
Your example works properly, but doesn't pass the lint:
|
Ah, I thought the issue somehow was related handlers not accepting |
Thank you, I'll make sure to return with some feedback when I get a chance to test this fix. |
Summary
no-handler
rule recommends to use handlers whenwhen
is anand
condition.Example:
when: r1.changed and r2.changed
.Afaik handlers can only be used for single conditions and using
notify
on multiple tasks acts as a logicalor
, but here logicaland
is needed.I have discussed this issue some time ago on IRC and we came to the conclusion that this is a bug. Forgive me if I missed something.
Issue Type
Ansible and Ansible Lint details
pip install .
in venv)OS / ENVIRONMENT
Linux samluks 5.11.11-arch1-1 SMP PREEMPT Tue, 30 Mar 2021 14:10:17 +0000 x86_64 GNU/Linux
STEPS TO REPRODUCE
when: r1.changed and r2.changed
)Playbook at
examples/playbooks/rule-no-handler-and.yml
Desired Behaviour
No warning given as this case seems to be impossible to be solved with handlers.
Actual Behaviour
Testcase
Assumes playbook given above (that should not show warnings)
Possible fix
Searching for string
and
would be bad for variable names with that string inside (legal).Searching for
and
(surrounded with spaces) seems to be a better idea, but I'm not sure what are the other options. There could be a line break or something.The text was updated successfully, but these errors were encountered: