Skip to content

quote-style single leads to fatal errors & YAML not being fixed/rewritten at all #4858

@mbunkus

Description

@mbunkus
Summary

Having no yamllint config at all or one with quote-style: "double" makes ansible-lint convert single quotes into double quotes when fixing anything. That's as expected. However, with quote-style: 'single' ansible-lint spits out an error for each double-quoted string & does not fix that entry at all (or anything else as it cannot rewrite YAML at all).

Issue Type
  • Bug Report
OS / ENVIRONMENT
WARNING: PATH altered to include /home/mosu/opt/ansible/2.19/.venv/bin, /home/mosu/opt/ansible/2.19/.venv/bin :: This is usually a sign of broken local setup, which can cause unexpected behaviors.
ansible-lint 25.11.1 using ansible-core:2.19.4 ansible-compat:25.11.0 ruamel-yaml:0.18.16 ruamel-yaml-clib:0.2.15
WARNING  Project directory /.ansible cannot be used for caching as it is not writable.
WARNING  Using unique temporary directory /tmp/.ansible-0aaa for caching.
  • ansible installation method: uv venv followed by activation & uv pip install "ansible-core >= 2.19, < 2.20" "ansible >= 12.0, < 13.0" (cannot go newer as I have machines whose Python is too old for 2.20)
  • ansible-lint installation method: same venv as Ansible, activation & uv pip install ansible-lint (no version limitation here)
STEPS TO REPRODUCE

Starting with an empty directory (let's call it test03) & no yamllint & ansible-lint configurations at all, I first create a minimal yamllint configuration that would be acceptable to ansible-lint & that enables single quotes. This is now test03/.yamllint.yml:

---
extends: 'default'

rules:
  comments:
    min-spaces-from-content: 1
  comments-indentation: false
  braces:
    max-spaces-inside: 1
  octal-values:
    forbid-implicit-octal: true
    forbid-explicit-octal: true
  quoted-strings:
    quote-type: 'single'
    required: false
    check-keys: false

Now create a minimal test test03/inventory.yml with a single double-quoted string so that ansible-lint has something to fix:

---
hosts:
  test01:
    vars:
      chunky: "bacon"

In test03 run yamllint inventory.yml for confirming it doesn't like the quotes:

[0 mosu@sweet-chili 0.000s ~/ansible/test03] yamllint inventory.yml
inventory.yml
  5:15      error    string value is not quoted with single quotes  (quoted-strings)

Now run ansible-lint --fix=yaml & observe fatal errors:

[1 mosu@sweet-chili 0.042s ~/ansible/test03] ansible-lint --fix=yaml
WARNING: PATH altered to include /home/mosu/opt/ansible/2.19/.venv/bin, /home/mosu/opt/ansible/2.19/.venv/bin :: This is usually a sign of broken local setup, which can cause unexpected behaviors.
WARNING  Project directory /.ansible cannot be used for caching as it is not writable.
WARNING  Using unique temporary directory /tmp/.ansible-0aaa for caching.
ERROR    Rule specific fix not applied for: yaml[quoted-strings]/yaml inventory.yml:5
WARNING  Listing 1 violation(s) that are fatal
yaml[quoted-strings]: String value is not quoted with single quotes
inventory.yml:5

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

# Rule Violation Summary

  1 yaml profile:basic tags:formatting,yaml

Failed: 1 failure(s), 0 warning(s) in 2 files processed of 2 encountered. Last profile that met the validation criteria was 'min'.

Verify that inventory.yml was not modified:

[2 mosu@sweet-chili 1.005s ~/ansible/test03] rg bacon inventory.yml
5:      chunky: "bacon"

I can run the test the other way, too: configure yamllint to want double quotes, give ansible-lint an inventory.yml that contains single-quoted string. Here ansible-lint will still print an error but actually fix the YAML.

Same setup, but in test02 with .yamllint.yml:

---
extends: "default"

rules:
  comments:
    min-spaces-from-content: 1
  comments-indentation: false
  braces:
    max-spaces-inside: 1
  octal-values:
    forbid-implicit-octal: true
    forbid-explicit-octal: true
  quoted-strings:
    quote-type: "double"
    required: false
    check-keys: false

and inventory.yml:

---
hosts:
  test01:
    vars:
      chunky: 'bacon'

Verify that yamllint complains & that ansible-lint actually fixes things:

[0 mosu@sweet-chili 0.012s ~/ansible/test02] yamllint inventory.yml
inventory.yml
  5:15      error    string value is not quoted with double quotes  (quoted-strings)

[1 mosu@sweet-chili 0.044s ~/ansible/test02] ansible-lint --fix=yaml
WARNING: PATH altered to include /home/mosu/opt/ansible/2.19/.venv/bin, /home/mosu/opt/ansible/2.19/.venv/bin :: This is usually a sign of broken local setup, which can cause unexpected behaviors.
WARNING  Project directory /.ansible cannot be used for caching as it is not writable.
WARNING  Using unique temporary directory /tmp/.ansible-0aaa for caching.
ERROR    Rule specific fix not applied for: yaml[quoted-strings]/yaml inventory.yml:5

Modified 1 file.
Passed: 0 failure(s), 0 warning(s) in 2 files processed of 2 encountered. Last profile that met the validation criteria was 'production'.
[0 mosu@sweet-chili 0.992s ~/ansible/test02] rg bacon inventory.yml
5:      chunky: "bacon"

Note that there's still an ERROR output, which I find highly confusing, given that the YAML is actually fixed.

Now for the last test in test01: no yamllint config at all, meaning built-in defaults for ansible-lint. We now only have test01/inventory.yml:

---
hosts:
  test01:
    vars:
      chunky: 'bacon'

Same program calls to lint, fix & verify:

[0 mosu@sweet-chili 0.004s ~/ansible/test01] yamllint inventory.yml
[0 mosu@sweet-chili 0.042s ~/ansible/test01] ansible-lint --fix=yaml
WARNING: PATH altered to include /home/mosu/opt/ansible/2.19/.venv/bin, /home/mosu/opt/ansible/2.19/.venv/bin :: This is usually a sign of broken local setup, which can cause unexpected behaviors.
WARNING  Project directory /.ansible cannot be used for caching as it is not writable.
WARNING  Using unique temporary directory /tmp/.ansible-0aaa for caching.

Modified 1 file.
Passed: 0 failure(s), 0 warning(s) in 1 files processed of 1 encountered. Last profile that met the validation criteria was 'production'.
[0 mosu@sweet-chili 0.971s ~/ansible/test01] rg bacon inventory.yml
5:      chunky: "bacon"

Note that:

  1. yamllint doesn't show an error as there's no yamlling config to apply on my system for test01, nor a global one
  2. ansible-lint does NOT show an error, unlike in test02, and it still fixed the YAML
Desired Behavior

For test03 (yamllint configured to single quotes) I would expect:

  • no ERRORs shown by ansible-lint
  • ansible-ilnt actually fixing the YAML to use single quotes

For test02 (yamllint configured to double quotes) I would expect:

  • no ERRORs shown by ansible-lint so that behavior is completely identical to test01 case (the one without a yamllint config)
Actual Behavior

Described in detail in the "STEPS TO REPRODUCE" section

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnewTriage required

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions