ansible-lint icon indicating copy to clipboard operation
ansible-lint copied to clipboard

no-handler: should not react on when-conditions containing "and" or "or"

Open phgogo opened this issue 3 years ago • 3 comments

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

phgogo avatar Jun 17 '21 09:06 phgogo

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.

ssbarnea avatar Jun 17 '21 10:06 ssbarnea

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?

lilatomic avatar Oct 02 '21 19:10 lilatomic

We talked in our weekly meeting and I think we would support a PR that makes it ignore complex conditions.

ssbarnea avatar Jul 06 '22 13:07 ssbarnea

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?

StopMotionCuber avatar May 10 '23 08:05 StopMotionCuber

Yes, I think that a PR would be welcomed here.

ssbarnea avatar May 10 '23 10:05 ssbarnea

@StopMotionCuber Do you want to make a PR or should I take over?

klaus-tux avatar May 10 '23 10:05 klaus-tux

@klaus-tux Feel free to go ahead with that. You can ping me to additionally review that PR then

StopMotionCuber avatar May 10 '23 11:05 StopMotionCuber