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

ansible-lint incompatible with some yamllint settings #4118

Closed
pb82 opened this issue Apr 19, 2024 · 2 comments · Fixed by #4139
Closed

ansible-lint incompatible with some yamllint settings #4118

pb82 opened this issue Apr 19, 2024 · 2 comments · Fixed by #4139
Assignees
Labels

Comments

@pb82
Copy link

pb82 commented Apr 19, 2024

Summary

When running ansible-lint with --fix and write_list set to all, it will remove quotes from strings where possible.

From what I understand, ansible-lint does run yamllint if it is present on the system. yamllint has a setting for string quotes, e.g. quoted-strings: 'enable': this requires all strings to be quoted.

This leads to the situation where, when I run ansible-lint twice:

  • the first time it will remove quotes from strings where it can
  • the second time it complains about all the quotes it removed
Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint 24.2.0 using ansible-core:2.16.4 ansible-compat:4.1.11 ruamel-yaml:0.18.5 ruamel-yaml-clib:0.2.7
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

Here is a minimal repo to demonstrate the issue: https://github.com/pb82/ansible-lint-issue.git

$ git clone https://github.com/pb82/ansible-lint-issue.git
$ cd ansible-lint-issue
$ ansible-lint --fix # this will work
$ ansible-lint --fix # this will fail
Desired Behavior

A few options:

  1. some configuration option for ansible-lint to leave quotes alone
  2. ansible-lint respecting the quoted-strings rule in .yamllint
Actual Behavior

As described above, will lint will fail the second time running.

[peter@fedora ansible-lint-issue]$ ansible-lint --fix

Modified 2 files.
Passed: 0 failure(s), 0 warning(s) on 2 files. Last profile that met the validation criteria was 'production'.
A new release of ansible-lint is available: 24.2.0 → 24.2.2 Upgrade by running: pip3 install --user --upgrade ansible-lint

[peter@fedora ansible-lint-issue]$ ansible-lint --fix
WARNING  Listing 5 violation(s) that are fatal
yaml[quoted-strings]: String value is not quoted with any quotes
.ansible-lint:3

yaml[quoted-strings]: String value is not quoted with any quotes
.yamllint:2

yaml[quoted-strings]: String value is not quoted with any quotes
.yamllint:5

yaml[quoted-strings]: String value is not quoted with any quotes
.yamllint:10

yaml[quoted-strings]: String value is not quoted with any quotes
.yamllint:11

Read documentation for instructions on how to ignore specific rule violations.

                 Rule Violation Summary                  
 count tag                  profile rule associated tags 
     5 yaml[quoted-strings] basic   formatting, yaml     

Failed: 5 failure(s), 0 warning(s) on 2 files. Last profile that met the validation criteria was 'min'.
A new release of ansible-lint is available: 24.2.0 → 24.2.2 Upgrade by running: pip3 install --user --upgrade ansible-lint

@pb82 pb82 added bug new Triage required labels Apr 19, 2024
@audgirka audgirka removed the new Triage required label Apr 24, 2024
@Qalthos
Copy link
Contributor

Qalthos commented Apr 24, 2024

Your issue is in fact correct: ansible-lint is incompatible with this option in yamllint. In fact, it is so incompatible with ansible-lint, that the likely solution is going to be to refuse to run ansible-lint --fix while that setting is enabled.

@pb82
Copy link
Author

pb82 commented Apr 25, 2024

@Qalthos thanks for the confirmation. If this is the expected behaviour, then refusing to run --fix makes sense 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants