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

ansible-lint incompatible with some yamllint settings

Open pb82 opened this issue 10 months ago • 2 comments

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 avatar Apr 19 '24 13:04 pb82

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.

Qalthos avatar Apr 24 '24 13:04 Qalthos

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

pb82 avatar Apr 25 '24 09:04 pb82