Skip to content
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

Find "changed" not only in first "when" condition #3358

Merged
merged 3 commits into from
Apr 26, 2023

Conversation

klaus-tux
Copy link
Contributor

Prior to this change, the rule no_handler did not find the string "changed" if it was in the second when condition or any later when condition:

- name: This should be a handler 1
  ansible.builtin.debug:
    msg: why isn't this a handler
  when:
    - result.changed # ansible-lint finds this
    - second_condition

- name: This should be a handler 2
  ansible.builtin.debug:
    msg: why isn't this a handler
  when:
    - first_condition
    - result.changed # ansible-lint misses this

This change fixes the implementation so that it finds the second case as well.

@klaus-tux klaus-tux requested a review from a team as a code owner April 26, 2023 15:55
@klaus-tux klaus-tux requested review from a team, ssbarnea, priyamsahoo and Ruchip16 April 26, 2023 15:55
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.
@klaus-tux klaus-tux changed the title Find "changed" not only in first "when" condition Bug: Find "changed" not only in first "when" condition Apr 26, 2023
@ssbarnea ssbarnea changed the title Bug: Find "changed" not only in first "when" condition Find "changed" not only in first "when" condition Apr 26, 2023
@ssbarnea ssbarnea added the bug label Apr 26, 2023
@ssbarnea ssbarnea enabled auto-merge (squash) April 26, 2023 17:57
@ssbarnea ssbarnea merged commit a0b2c90 into ansible:main Apr 26, 2023
@klaus-tux klaus-tux deleted the find-changed-in-last-when branch April 27, 2023 06:06
@StopMotionCuber
Copy link
Contributor

StopMotionCuber commented May 10, 2023

I just stumbled upon that as this PR broke our CI on ansible-lint and raise that something into this direction was discussed on #1632

While I agree that it should be consistent (either match on any when condition or none at all if there is more than 1 line available), I'm not sure whether these cases with multiple conditions should be linted. Internally on our team, we added a noqa on the violated tasks

@klaus-tux
Copy link
Contributor Author

I was not aware of #1632 when I created the PR. I just spotted an inconsistency and fixed it.

@ssbarnea What is the desired behaviour here? Should we disable the check for complex conditions or should we leave the implementation as it is?

nrdufour added a commit to nrdufour/home-ops that referenced this pull request Jul 27, 2023
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ansible-lint](https://github.com/ansible/ansible-lint) ([changelog](https://github.com/ansible/ansible-lint/releases)) | minor | `==6.15.0` -> `==6.17.2` |

---

### Release Notes

<details>
<summary>ansible/ansible-lint (ansible-lint)</summary>

### [`v6.17.2`](https://github.com/ansible/ansible-lint/releases/tag/v6.17.2)

[Compare Source](ansible/ansible-lint@v6.17.1...v6.17.2)

#### Bugfixes

-   Allow use as a reusable github action ([#&#8203;3513](ansible/ansible-lint#3513)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Add action and args properties to task class ([#&#8203;3576](ansible/ansible-lint#3576)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Fixed error when sarif file option is provided ([#&#8203;3587](ansible/ansible-lint#3587)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Add NetBSD as a recognized platform ([#&#8203;3586](ansible/ansible-lint#3586)) [@&#8203;he32](https://github.com/he32)
-   Display ansible-compat version alongwith with other deps ([#&#8203;3584](ansible/ansible-lint#3584)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Refactored syntax-checking ([#&#8203;3568](ansible/ansible-lint#3568)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Avoid app reinitialization during syntax-check ([#&#8203;3563](ansible/ansible-lint#3563)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Allow config file to have `.yaml` extension ([#&#8203;3559](ansible/ansible-lint#3559)) [@&#8203;bdsoha](https://github.com/bdsoha)
-   Allow lists of lists of strings for vars_files ([#&#8203;3561](ansible/ansible-lint#3561)) [@&#8203;ajinkyau](https://github.com/ajinkyau)

### [`v6.17.1`](https://github.com/ansible/ansible-lint/releases/tag/v6.17.1)

[Compare Source](ansible/ansible-lint@v6.17.0...v6.17.1)

#### Bugfixes

-   Update guess install method check ([#&#8203;3553](ansible/ansible-lint#3553)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Fix exclude logic bug that can cause cause partial linting ([#&#8203;3552](ansible/ansible-lint#3552)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Make profile information on summary line more clear ([#&#8203;3545](ansible/ansible-lint#3545)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Avoid adding pip related messages if installation method is different ([#&#8203;3551](ansible/ansible-lint#3551)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Avoid false positive with var-naming\[no-role-prefix] ([#&#8203;3550](ansible/ansible-lint#3550)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Make refresh_schemas handle firewalls that cut the file transfer midway ([#&#8203;3546](ansible/ansible-lint#3546)) [@&#8203;sverrehu](https://github.com/sverrehu)
-   Rename marketplace action ([#&#8203;3548](ansible/ansible-lint#3548)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Fix action name ([#&#8203;3536](ansible/ansible-lint#3536)) [@&#8203;coaxial](https://github.com/coaxial)
-   Handling of exclude paths with trailing slashs ([#&#8203;3527](ansible/ansible-lint#3527)) [@&#8203;hille721](https://github.com/hille721)
-   Ensure that rules collections use Runtime in offline mode ([#&#8203;3526](ansible/ansible-lint#3526)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Avoid using get_app() from inside the rule ([#&#8203;3525](ansible/ansible-lint#3525)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Avoid dependency error from rich ([#&#8203;3517](ansible/ansible-lint#3517)) [@&#8203;ssbarnea](https://github.com/ssbarnea)

### [`v6.17.0`](https://github.com/ansible/ansible-lint/releases/tag/v6.17.0)

[Compare Source](ansible/ansible-lint@v6.16.2...v6.17.0)

#### Minor Changes

-   fqcn\[deep]: detect deep plugins ([#&#8203;3502](ansible/ansible-lint#3502)) [@&#8203;ssbarnea](https://github.com/ssbarnea)

#### Bugfixes

-   Reimplement file exclusion logic ([#&#8203;3507](ansible/ansible-lint#3507)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Check validity of 'become_method' values from code ([#&#8203;3499](ansible/ansible-lint#3499)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Fix role_name\_ prefix include_role var name error ([#&#8203;3500](ansible/ansible-lint#3500)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Hide pip error if not present ([#&#8203;3494](ansible/ansible-lint#3494)) [@&#8203;Et7f3](https://github.com/Et7f3)
-   Update formatter to avoid reporting paths with .. ([#&#8203;3496](ansible/ansible-lint#3496)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Remove false positive on 'cacheable' property of set_fact ([#&#8203;3490](ansible/ansible-lint#3490)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Add missing become_method plugins to the schema ([#&#8203;3484](ansible/ansible-lint#3484)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Add support for ansible-builder v3 schema ([#&#8203;3480](ansible/ansible-lint#3480)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Add Github Marketplace Action ([#&#8203;3476](ansible/ansible-lint#3476)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Add oracle linux 8.8 ([#&#8203;3479](ansible/ansible-lint#3479)) [@&#8203;facorazza](https://github.com/facorazza)
-   Revert ansible-compat vendoring ([#&#8203;3478](ansible/ansible-lint#3478)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Updated file or dir not found message ([#&#8203;3474](ansible/ansible-lint#3474)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Check for included role prefix instead of current one ([#&#8203;3473](ansible/ansible-lint#3473)) [@&#8203;ssbarnea](https://github.com/ssbarnea)

### [`v6.16.2`](https://github.com/ansible/ansible-lint/releases/tag/v6.16.2)

[Compare Source](ansible/ansible-lint@v6.16.1...v6.16.2)

#### Bugfixes

-   Update test dependencies ([#&#8203;3470](ansible/ansible-lint#3470)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Fix and document installing of requirements.yml files ([#&#8203;3471](ansible/ansible-lint#3471)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Do not ever exclude files given as arguments ([#&#8203;3468](ansible/ansible-lint#3468)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Ensure we return error if argument gives are not present ([#&#8203;3467](ansible/ansible-lint#3467)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Allow rules to expose all tags they can produce ([#&#8203;3464](ansible/ansible-lint#3464)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Enable var-name rule to detect read-only variables ([#&#8203;3462](ansible/ansible-lint#3462)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Add Oracle Enterprise Linux 7.\* ([#&#8203;3463](ansible/ansible-lint#3463)) [@&#8203;Rylon](https://github.com/Rylon)
-   Fix for var-naming rule to not break on include_tasks and vars ([#&#8203;3458](ansible/ansible-lint#3458)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   var-naming now prevents use of Ansible reserved names ([#&#8203;3460](ansible/ansible-lint#3460)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Ensure that we also lint files from git submodules ([#&#8203;3431](ansible/ansible-lint#3431)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Adding 2.16 to the list of allowed ansible-core versions in meta-runtime rule ([#&#8203;3455](ansible/ansible-lint#3455)) [@&#8203;alisonlhart](https://github.com/alisonlhart)

### [`v6.16.1`](https://github.com/ansible/ansible-lint/releases/tag/v6.16.1)

[Compare Source](ansible/ansible-lint@v6.16.0...v6.16.1)

#### Bugfixes

-   Update lock file to use ansible-core 2.15.0 ([#&#8203;3449](ansible/ansible-lint#3449)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Install requirements from galaxy.yml and tests/requirements.yml ([#&#8203;3446](ansible/ansible-lint#3446)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Add Kali Linux as a supported platform ([#&#8203;3448](ansible/ansible-lint#3448)) [@&#8203;mcdonnnj](https://github.com/mcdonnnj)
-   Do not trigger no_handler upon complex conditions ([#&#8203;3437](ansible/ansible-lint#3437)) [@&#8203;klaus-tux](https://github.com/klaus-tux)
-   Hide warning about unique filter originating from core ([#&#8203;3436](ansible/ansible-lint#3436)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Relax ruamel-yaml requirements ([#&#8203;3433](ansible/ansible-lint#3433)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Suggest correct alternative for `with_filetree` ([#&#8203;3432](ansible/ansible-lint#3432)) [@&#8203;ErwinJanssen](https://github.com/ErwinJanssen)
-   Upgrade var-naming rule to include role name prefix ([#&#8203;3422](ansible/ansible-lint#3422)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Fix exception when using reformatting on scalars ([#&#8203;3423](ansible/ansible-lint#3423)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Find and lint imported playbooks ([#&#8203;3413](ansible/ansible-lint#3413)) [@&#8203;ajinkyau](https://github.com/ajinkyau)

### [`v6.16.0`](https://github.com/ansible/ansible-lint/releases/tag/v6.16.0)

[Compare Source](ansible/ansible-lint@v6.15.0...v6.16.0)

#### Minor Changes

-   Capture python warnings and report some of them as matches ([#&#8203;3324](ansible/ansible-lint#3324)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Capture and hide ansible core warnings by default ([#&#8203;3361](ansible/ansible-lint#3361)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Remove progressive mode ([#&#8203;3350](ansible/ansible-lint#3350)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Enforce use of lineno variable name inside the library ([#&#8203;3326](ansible/ansible-lint#3326)) [@&#8203;ssbarnea](https://github.com/ssbarnea)

#### Bugfixes

-   Add Amazon Linux 2023 as a supported platform ([#&#8203;3405](ansible/ansible-lint#3405)) [@&#8203;artis3n](https://github.com/artis3n)
-   Capture python warnings and report some of them as matches ([#&#8203;3324](ansible/ansible-lint#3324)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Fix missing required arguments issue from args rule ([#&#8203;3402](ansible/ansible-lint#3402)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Change matchtask to receive a Task instance ([#&#8203;3403](ansible/ansible-lint#3403)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Require ruamel.yaml>=0.17.24 ([#&#8203;3406](ansible/ansible-lint#3406)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Avoid exception when trying to load invalid text files ([#&#8203;3399](ansible/ansible-lint#3399)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Fix ansible collection path detection ([#&#8203;3398](ansible/ansible-lint#3398)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   ruff: Address FBT002 ([#&#8203;3389](ansible/ansible-lint#3389)) [@&#8203;shatakshiiii](https://github.com/shatakshiiii)
-   More pathlib adoption ([#&#8203;3390](ansible/ansible-lint#3390)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Avoid dropping comments on YAML transformation ([#&#8203;3392](ansible/ansible-lint#3392)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Correct docs on navigator schema location ([#&#8203;3394](ansible/ansible-lint#3394)) [@&#8203;yajo](https://github.com/yajo)
-   Fix changelog schema for connection plugins ([#&#8203;3388](ansible/ansible-lint#3388)) [@&#8203;Qalthos](https://github.com/Qalthos)
-   Migrate from os.path to pathlib ([#&#8203;3384](ansible/ansible-lint#3384)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Remove resolvelib from requirements lock ([#&#8203;3387](ansible/ansible-lint#3387)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Make cwd use pathlib ([#&#8203;3383](ansible/ansible-lint#3383)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   ruff: Address PGH ([#&#8203;3380](ansible/ansible-lint#3380)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   ruff: Address A ([#&#8203;3379](ansible/ansible-lint#3379)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   ruff: Address B ([#&#8203;3377](ansible/ansible-lint#3377)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   ruff: Address SLF ([#&#8203;3372](ansible/ansible-lint#3372)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   ruff: Address `SIM` ([#&#8203;3373](ansible/ansible-lint#3373)) [@&#8203;shatakshiiii](https://github.com/shatakshiiii)
-   ruff: Address EXE ([#&#8203;3367](ansible/ansible-lint#3367)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   ruff: Address BLE ([#&#8203;3368](ansible/ansible-lint#3368)) [@&#8203;shatakshiiii](https://github.com/shatakshiiii)
-   ruff: Address INP and PLW ([#&#8203;3366](ansible/ansible-lint#3366)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Add initial handling of submodules to contribution docs ([#&#8203;3362](ansible/ansible-lint#3362)) [@&#8203;klaus-tux](https://github.com/klaus-tux)
-   ruff: Address T and RET ([#&#8203;3364](ansible/ansible-lint#3364)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Find "changed" not only in first "when" condition ([#&#8203;3358](ansible/ansible-lint#3358)) [@&#8203;klaus-tux](https://github.com/klaus-tux)
-   ruff: fix S rule ([#&#8203;3363](ansible/ansible-lint#3363)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Make MatchError a dataclass ([#&#8203;3345](ansible/ansible-lint#3345)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Remove `EM` from ruff ignores ([#&#8203;3356](ansible/ansible-lint#3356)) [@&#8203;shatakshiiii](https://github.com/shatakshiiii)
-   Mock jinja filters to prevent templating errors ([#&#8203;3355](ansible/ansible-lint#3355)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Update schema files ([#&#8203;3354](ansible/ansible-lint#3354)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Add Fedora 38 to meta.json schema file ([#&#8203;3353](ansible/ansible-lint#3353)) [@&#8203;Marek-Mantaj-Mobica](https://github.com/Marek-Mantaj-Mobica)
-   Remove `RUF` from ruff ignores ([#&#8203;3346](ansible/ansible-lint#3346)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Remove `G` from ruff ignores ([#&#8203;3332](ansible/ansible-lint#3332)) [@&#8203;shatakshiiii](https://github.com/shatakshiiii)
-   Remove `ISC` from ruff ignores ([#&#8203;3342](ansible/ansible-lint#3342)) [@&#8203;shatakshiiii](https://github.com/shatakshiiii)
-   Remove `C` from ruff ignores ([#&#8203;3343](ansible/ansible-lint#3343)) [@&#8203;ajinkyau](https://github.com/ajinkyau)
-   Make linter configuration a dataclass ([#&#8203;3334](ansible/ansible-lint#3334)) [@&#8203;ssbarnea](https://github.com/ssbarnea)
-   Remove `N` from ruff ignores ([#&#8203;3328](ansible/ansible-lint#3328)) [@&#8203;shatakshiiii](https://github.com/shatakshiiii)
-   Remove useless . from additional_dependencies in pre-commit hook ([#&#8203;3327](ansible/ansible-lint#3327)) [@&#8203;trallnag](https://github.com/trallnag)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yMy4yIiwidXBkYXRlZEluVmVyIjoiMzYuMjMuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: Nicolas Dufour <nrdufour@gmail.com>
Reviewed-on: https://git.home/nrdufour/home-ops/pulls/9
Co-authored-by: Renovate <renovate@ptinem.io>
Co-committed-by: Renovate <renovate@ptinem.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants