ansible-lint
ansible-lint copied to clipboard
no-handler: should not react on when-conditions containing "and" or "or"
Summary
Right now the rule Tasks that run when changed should likely be handlers
(which BTW, i am a big fan of) would produce findings for all of this lines:
when: mytask.changed
when: mytask is changed
...
when: mytask is changed and wartherIsNice|bool
While i totally agree that the first two examples are bad practices and should produce a linter warning, i would not agree, that the last example should.
Proposed solution
As mentioned in #419 i could imagine of splitting up E503 into two rules, one of which reacts to single conditions and one for more complex conditions involving and
or or
- that way both could be skipped/disabled seperately.
As @ssbarnea pointed out, it might also be a solution to disable the check completeley for complex conditons.
Issue Type
-
Bug Report
-
ansible installation method: OS package
-
ansible-lint installation method: pip
The bug report form states to report bugs only on latest version, 2.6.1 is FEW YEARS OLD, "503" rule id no longer exists, python2.7 is no longer supported either. Please cleanup the report to avoid confusing the reader. I happen to have background knowledge otherwise I would have just closed it ;)
And yes, I would support changing the rule only match the two specific simple syntaxes and ignore more complex ones. It should be quite easy for you to make a first PR that address this issue.
It's possible to add a when
clause to the handlers themselves. so:
- name: mytask
...
- name: example task
...
when: mytask is changed and wartherIsNice|bool
becomes
- name: mytask
...
notify: example handler
---
- name: example handler
when: wartherIsNice|bool
should we really not match on complex conditions?
We talked in our weekly meeting and I think we would support a PR that makes it ignore complex conditions.
As I wrote in the PR making a bugfix to complex condition detection:
Is the information still current that a PR ignoring complex conditions would be supported?
Yes, I think that a PR would be welcomed here.
@StopMotionCuber Do you want to make a PR or should I take over?
@klaus-tux Feel free to go ahead with that. You can ping me to additionally review that PR then