ansible / ansible-lint

ansible-lint checks playbooks for practices and behavior that could potentially be improved and can fix some of the most common ones for you
https://ansible.readthedocs.io/projects/lint/
GNU General Public License v3.0
3.49k stars 660 forks source link

`ansible-lint --fix` remove quotes arround "YES" string which then trigger `yaml[truthy]` #4174

Open Alabate opened 5 months ago

Alabate commented 5 months ago
Summary

ansible-lint --fix remove quotes arround "YES" string which then trigger yaml[truthy]

Issue Type
OS / ENVIRONMENT
$ ansible-lint --version
ansible-lint 24.5.0 using ansible-core:2.15.9 ansible-compat:24.5.1 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8
$ python --version
Python 3.11.6

I also tested with ansible-lint 6.22.2, I had the same behaviour

STEPS TO REPRODUCE

Create two files in an empty directory

# .ansible-lint
---
profile: basic
# file.yml
---
this_should_be_a_str: "YES"
Verbose output ``` 130 ↵ DEBUG Logging initialized to level 10 INFO Identified /home/alabate/Projects/products.tests.ci/tmp as project root due config file /home/alabate/Projects/products.tests.ci/tmp/.ansible-lint. DEBUG Options: Options(_skip_ansible_syntax_check=False, cache_dir=PosixPath('/home/alabate/.cache/ansible-compat/cf10d3'), colored=True, configured=True, cwd=PosixPath('/home/alabate/Projects/products.tests.ci/tmp'), display_relative_path=True, exclude_paths=['.cache', '.git', '.hg', '.svn', '.tox'], format=None, lintables=[], list_rules=False, list_tags=False, write_list=['all'], parseable=False, quiet=False, rulesdirs=[PosixPath('/home/alabate/Projects/products.tests.ci/.venv/lib/python3.11/site-packages/ansiblelint/rules')], skip_list=[], tags=[], verbosity=6, warn_list=['experimental', 'jinja', 'fqcn'], mock_filters=[], mock_modules=[], mock_roles=[], loop_var_prefix=None, only_builtins_allow_collections=[], only_builtins_allow_modules=[], var_naming_pattern=None, offline=False, project_dir='.', extra_vars=None, enable_list=[], skip_action_validation=True, strict=False, rules={}, profile='basic', task_name_prefix='{stem} | ', sarif_file=None, config_file='/home/alabate/Projects/products.tests.ci/tmp/.ansible-lint', generate_ignore=False, rulesdir=[], use_default_rules=False, version=False, list_profiles=False, ignore_file=None, max_tasks=100, max_block_depth=20) DEBUG CWD: /home/alabate/Projects/products.tests.ci/tmp DEBUG Logging initialized to level 10 DEBUG Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}} INFO Set ANSIBLE_LIBRARY=/home/alabate/.cache/ansible-compat/cf10d3/modules:/home/alabate/.ansible/plugins/modules:/usr/share/ansible/plugins/modules INFO Set ANSIBLE_COLLECTIONS_PATH=/home/alabate/.cache/ansible-compat/cf10d3/collections:/home/alabate/.ansible/collections:/usr/share/ansible/collections:/home/alabate/Projects/products.tests.ci INFO Set ANSIBLE_ROLES_PATH=/home/alabate/.cache/ansible-compat/cf10d3/roles:/home/alabate/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles DEBUG Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}} DEBUG Activating rule `command-instead-of-module` due to profile `basic` DEBUG Activating rule `command-instead-of-shell` due to profile `basic` DEBUG Activating rule `deprecated-bare-vars` due to profile `basic` DEBUG Activating rule `deprecated-local-action` due to profile `basic` DEBUG Activating rule `deprecated-module` due to profile `basic` DEBUG Activating rule `inline-env-var` due to profile `basic` DEBUG Activating rule `key-order` due to profile `basic` DEBUG Activating rule `literal-compare` due to profile `basic` DEBUG Activating rule `jinja` due to profile `basic` DEBUG Activating rule `no-free-form` due to profile `basic` DEBUG Activating rule `no-jinja-when` due to profile `basic` DEBUG Activating rule `no-tabs` due to profile `basic` DEBUG Activating rule `partial-become` due to profile `basic` DEBUG Activating rule `playbook-extension` due to profile `basic` DEBUG Activating rule `role-name` due to profile `basic` DEBUG Activating rule `schema` due to profile `basic` DEBUG Activating rule `name` due to profile `basic` DEBUG Activating rule `var-naming` due to profile `basic` DEBUG Activating rule `yaml` due to profile `basic` DEBUG Activating rule `internal-error` due to profile `min` DEBUG Activating rule `load-failure` due to profile `min` DEBUG Activating rule `parser-error` due to profile `min` DEBUG Activating rule `syntax-check` due to profile `min` DEBUG Unloading args rule due to not being part of basic profile. DEBUG Unloading avoid-implicit rule due to not being part of basic profile. DEBUG Unloading complexity rule due to not being part of basic profile. DEBUG Unloading empty-string-compare rule due to not being part of basic profile. DEBUG Unloading fqcn rule due to not being part of basic profile. DEBUG Unloading galaxy rule due to not being part of basic profile. DEBUG Unloading ignore-errors rule due to not being part of basic profile. DEBUG Unloading latest rule due to not being part of basic profile. DEBUG Unloading loop-var-prefix rule due to not being part of basic profile. DEBUG Unloading meta-incorrect rule due to not being part of basic profile. DEBUG Unloading meta-no-tags rule due to not being part of basic profile. DEBUG Unloading meta-runtime rule due to not being part of basic profile. DEBUG Unloading meta-video-links rule due to not being part of basic profile. DEBUG Unloading no-changed-when rule due to not being part of basic profile. DEBUG Unloading no-handler rule due to not being part of basic profile. DEBUG Unloading no-log-password rule due to not being part of basic profile. DEBUG Unloading no-prompting rule due to not being part of basic profile. DEBUG Unloading no-relative-paths rule due to not being part of basic profile. DEBUG Unloading no-same-owner rule due to not being part of basic profile. DEBUG Unloading only-builtins rule due to not being part of basic profile. DEBUG Unloading package-latest rule due to not being part of basic profile. DEBUG Unloading risky-file-permissions rule due to not being part of basic profile. DEBUG Unloading risky-octal rule due to not being part of basic profile. DEBUG Unloading risky-shell-pipe rule due to not being part of basic profile. DEBUG Unloading run-once rule due to not being part of basic profile. DEBUG Unloading sanity rule due to not being part of basic profile. DEBUG 24/50 rules included in the profile DEBUG Passed 'file.yml' positional argument was identified as generic 'yaml' file kind. DEBUG Logging initialized to level 10 DEBUG Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}} INFO Set ANSIBLE_LIBRARY=/home/alabate/.cache/ansible-compat/cf10d3/modules:/home/alabate/.ansible/plugins/modules:/usr/share/ansible/plugins/modules INFO Set ANSIBLE_COLLECTIONS_PATH=/home/alabate/.cache/ansible-compat/cf10d3/collections:/home/alabate/.ansible/collections:/usr/share/ansible/collections:/home/alabate/Projects/products.tests.ci INFO Set ANSIBLE_ROLES_PATH=/home/alabate/.cache/ansible-compat/cf10d3/roles:/home/alabate/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles DEBUG Examining file.yml of type yaml DEBUG Running rule internal-error DEBUG Running rule load-failure DEBUG Running rule parser-error DEBUG Running rule warning DEBUG Running rule yaml DEBUG Running rule command-instead-of-module DEBUG Running rule command-instead-of-shell DEBUG Running rule deprecated-bare-vars DEBUG Running rule deprecated-local-action DEBUG Running rule deprecated-module DEBUG Running rule inline-env-var DEBUG Running rule jinja DEBUG Running rule key-order DEBUG Running rule literal-compare DEBUG Running rule name DEBUG Running rule no-free-form DEBUG Running rule no-jinja-when DEBUG Running rule no-tabs DEBUG Running rule partial-become DEBUG Running rule playbook-extension DEBUG Running rule role-name DEBUG Running rule schema DEBUG Running rule var-naming DEBUG Examining .ansible-lint of type ansible-lint-config DEBUG Running rule internal-error DEBUG Running rule load-failure DEBUG Running rule parser-error DEBUG Running rule warning DEBUG Running rule yaml DEBUG Running rule command-instead-of-module DEBUG Running rule command-instead-of-shell DEBUG Running rule deprecated-bare-vars DEBUG Running rule deprecated-local-action DEBUG Running rule deprecated-module DEBUG Running rule inline-env-var DEBUG Running rule jinja DEBUG Running rule key-order DEBUG Running rule literal-compare DEBUG Running rule name DEBUG Running rule no-free-form DEBUG Running rule no-jinja-when DEBUG Running rule no-tabs DEBUG Running rule partial-become DEBUG Running rule playbook-extension DEBUG Running rule role-name DEBUG Running rule schema DEBUG Running rule var-naming DEBUG Begin fixing: 0 matches DEBUG Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}} DEBUG Rewriting yaml file: file.yml (yaml), version=None DEBUG Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}} DEBUG Rewriting yaml file: .ansible-lint (ansible-lint-config), version=None DEBUG Attempting to release lock 131373068587664 on /home/alabate/.cache/ansible-compat/cf10d3/.lock DEBUG Lock 131373068587664 released on /home/alabate/.cache/ansible-compat/cf10d3/.lock DEBUG Determined rule-profile order: {'internal-error': (0, 'min'), 'load-failure': (1, 'min'), 'parser-error': (2, 'min'), 'syntax-check': (3, 'min'), 'command-instead-of-module': (4, 'basic'), 'command-instead-of-shell': (5, 'basic'), 'deprecated-bare-vars': (6, 'basic'), 'deprecated-local-action': (7, 'basic'), 'deprecated-module': (8, 'basic'), 'inline-env-var': (9, 'basic'), 'key-order': (10, 'basic'), 'literal-compare': (11, 'basic'), 'jinja': (12, 'basic'), 'no-free-form': (13, 'basic'), 'no-jinja-when': (14, 'basic'), 'no-tabs': (15, 'basic'), 'partial-become': (16, 'basic'), 'playbook-extension': (17, 'basic'), 'role-name': (18, 'basic'), 'schema': (19, 'basic'), 'name': (20, 'basic'), 'var-naming': (21, 'basic'), 'yaml': (22, 'basic'), 'name': (23, 'moderate'), 'name': (24, 'moderate'), 'name': (25, 'moderate'), 'spell-var-name': (26, 'moderate'), 'avoid-implicit': (27, 'safety'), 'latest': (28, 'safety'), 'package-latest': (29, 'safety'), 'risky-file-permissions': (30, 'safety'), 'risky-octal': (31, 'safety'), 'risky-shell-pipe': (32, 'safety'), 'galaxy': (33, 'shared'), 'ignore-errors': (34, 'shared'), 'layout': (35, 'shared'), 'meta-incorrect': (36, 'shared'), 'meta-no-tags': (37, 'shared'), 'meta-video-links': (38, 'shared'), 'meta-version': (39, 'shared'), 'meta-runtime': (40, 'shared'), 'no-changed-when': (41, 'shared'), 'no-changelog': (42, 'shared'), 'no-handler': (43, 'shared'), 'no-relative-paths': (44, 'shared'), 'max-block-depth': (45, 'shared'), 'max-tasks': (46, 'shared'), 'unsafe-loop': (47, 'shared'), 'avoid-dot-notation': (48, 'production'), 'sanity': (49, 'production'), 'fqcn': (50, 'production'), 'import-task-no-when': (51, 'production'), 'meta-no-dependencies': (52, 'production'), 'single-entry-point': (53, 'production'), 'use-loop': (54, 'production')} Modified 1 files. Passed: 0 failure(s), 0 warning(s) on 2 files. Profile 'basic' was required, but 'production' profile passed. ```

Then if we start ansible-lint --fix in this directory, we get no error, and the file.yml become

# file.yml
---
this_should_be_a_str: YES

If we start ansible-lint --fix again we get

ERROR    Rule specific fix not applied for: yaml/yaml file.yml:2
WARNING  Listing 1 violation(s) that are fatal
yaml[truthy]: Truthy value should be one of [false, true]
file.yml:2

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

             Rule Violation Summary              
 count tag          profile rule associated tags 
     1 yaml[truthy] basic   formatting, yaml     

Failed: 1 failure(s), 0 warning(s) on 2 files. Profile 'basic' was required, but 'min' profile passed.
Verbose output ``` 130 ↵ DEBUG Logging initialized to level 10 INFO Identified /home/alabate/Projects/products.tests.ci/tmp as project root due config file /home/alabate/Projects/products.tests.ci/tmp/.ansible-lint. DEBUG Options: Options(_skip_ansible_syntax_check=False, cache_dir=PosixPath('/home/alabate/.cache/ansible-compat/cf10d3'), colored=True, configured=True, cwd=PosixPath('/home/alabate/Projects/products.tests.ci/tmp'), display_relative_path=True, exclude_paths=['.cache', '.git', '.hg', '.svn', '.tox'], format=None, lintables=[], list_rules=False, list_tags=False, write_list=['all'], parseable=False, quiet=False, rulesdirs=[PosixPath('/home/alabate/Projects/products.tests.ci/.venv/lib/python3.11/site-packages/ansiblelint/rules')], skip_list=[], tags=[], verbosity=6, warn_list=['experimental', 'jinja', 'fqcn'], mock_filters=[], mock_modules=[], mock_roles=[], loop_var_prefix=None, only_builtins_allow_collections=[], only_builtins_allow_modules=[], var_naming_pattern=None, offline=False, project_dir='.', extra_vars=None, enable_list=[], skip_action_validation=True, strict=False, rules={}, profile='basic', task_name_prefix='{stem} | ', sarif_file=None, config_file='/home/alabate/Projects/products.tests.ci/tmp/.ansible-lint', generate_ignore=False, rulesdir=[], use_default_rules=False, version=False, list_profiles=False, ignore_file=None, max_tasks=100, max_block_depth=20) DEBUG CWD: /home/alabate/Projects/products.tests.ci/tmp DEBUG Logging initialized to level 10 DEBUG Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}} INFO Set ANSIBLE_LIBRARY=/home/alabate/.cache/ansible-compat/cf10d3/modules:/home/alabate/.ansible/plugins/modules:/usr/share/ansible/plugins/modules INFO Set ANSIBLE_COLLECTIONS_PATH=/home/alabate/.cache/ansible-compat/cf10d3/collections:/home/alabate/.ansible/collections:/usr/share/ansible/collections:/home/alabate/Projects/products.tests.ci INFO Set ANSIBLE_ROLES_PATH=/home/alabate/.cache/ansible-compat/cf10d3/roles:/home/alabate/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles DEBUG Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}} DEBUG Activating rule `command-instead-of-module` due to profile `basic` DEBUG Activating rule `command-instead-of-shell` due to profile `basic` DEBUG Activating rule `deprecated-bare-vars` due to profile `basic` DEBUG Activating rule `deprecated-local-action` due to profile `basic` DEBUG Activating rule `deprecated-module` due to profile `basic` DEBUG Activating rule `inline-env-var` due to profile `basic` DEBUG Activating rule `key-order` due to profile `basic` DEBUG Activating rule `literal-compare` due to profile `basic` DEBUG Activating rule `jinja` due to profile `basic` DEBUG Activating rule `no-free-form` due to profile `basic` DEBUG Activating rule `no-jinja-when` due to profile `basic` DEBUG Activating rule `no-tabs` due to profile `basic` DEBUG Activating rule `partial-become` due to profile `basic` DEBUG Activating rule `playbook-extension` due to profile `basic` DEBUG Activating rule `role-name` due to profile `basic` DEBUG Activating rule `schema` due to profile `basic` DEBUG Activating rule `name` due to profile `basic` DEBUG Activating rule `var-naming` due to profile `basic` DEBUG Activating rule `yaml` due to profile `basic` DEBUG Activating rule `internal-error` due to profile `min` DEBUG Activating rule `load-failure` due to profile `min` DEBUG Activating rule `parser-error` due to profile `min` DEBUG Activating rule `syntax-check` due to profile `min` DEBUG Unloading args rule due to not being part of basic profile. DEBUG Unloading avoid-implicit rule due to not being part of basic profile. DEBUG Unloading complexity rule due to not being part of basic profile. DEBUG Unloading empty-string-compare rule due to not being part of basic profile. DEBUG Unloading fqcn rule due to not being part of basic profile. DEBUG Unloading galaxy rule due to not being part of basic profile. DEBUG Unloading ignore-errors rule due to not being part of basic profile. DEBUG Unloading latest rule due to not being part of basic profile. DEBUG Unloading loop-var-prefix rule due to not being part of basic profile. DEBUG Unloading meta-incorrect rule due to not being part of basic profile. DEBUG Unloading meta-no-tags rule due to not being part of basic profile. DEBUG Unloading meta-runtime rule due to not being part of basic profile. DEBUG Unloading meta-video-links rule due to not being part of basic profile. DEBUG Unloading no-changed-when rule due to not being part of basic profile. DEBUG Unloading no-handler rule due to not being part of basic profile. DEBUG Unloading no-log-password rule due to not being part of basic profile. DEBUG Unloading no-prompting rule due to not being part of basic profile. DEBUG Unloading no-relative-paths rule due to not being part of basic profile. DEBUG Unloading no-same-owner rule due to not being part of basic profile. DEBUG Unloading only-builtins rule due to not being part of basic profile. DEBUG Unloading package-latest rule due to not being part of basic profile. DEBUG Unloading risky-file-permissions rule due to not being part of basic profile. DEBUG Unloading risky-octal rule due to not being part of basic profile. DEBUG Unloading risky-shell-pipe rule due to not being part of basic profile. DEBUG Unloading run-once rule due to not being part of basic profile. DEBUG Unloading sanity rule due to not being part of basic profile. DEBUG 24/50 rules included in the profile DEBUG Passed 'file.yml' positional argument was identified as generic 'yaml' file kind. DEBUG Logging initialized to level 10 DEBUG Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}} INFO Set ANSIBLE_LIBRARY=/home/alabate/.cache/ansible-compat/cf10d3/modules:/home/alabate/.ansible/plugins/modules:/usr/share/ansible/plugins/modules INFO Set ANSIBLE_COLLECTIONS_PATH=/home/alabate/.cache/ansible-compat/cf10d3/collections:/home/alabate/.ansible/collections:/usr/share/ansible/collections:/home/alabate/Projects/products.tests.ci INFO Set ANSIBLE_ROLES_PATH=/home/alabate/.cache/ansible-compat/cf10d3/roles:/home/alabate/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles DEBUG Examining file.yml of type yaml DEBUG Running rule internal-error DEBUG Running rule load-failure DEBUG Running rule parser-error DEBUG Running rule warning DEBUG Running rule yaml DEBUG Running rule command-instead-of-module DEBUG Running rule command-instead-of-shell DEBUG Running rule deprecated-bare-vars DEBUG Running rule deprecated-local-action DEBUG Running rule deprecated-module DEBUG Running rule inline-env-var DEBUG Running rule jinja DEBUG Running rule key-order DEBUG Running rule literal-compare DEBUG Running rule name DEBUG Running rule no-free-form DEBUG Running rule no-jinja-when DEBUG Running rule no-tabs DEBUG Running rule partial-become DEBUG Running rule playbook-extension DEBUG Running rule role-name DEBUG Running rule schema DEBUG Running rule var-naming DEBUG Examining .ansible-lint of type ansible-lint-config DEBUG Running rule internal-error DEBUG Running rule load-failure DEBUG Running rule parser-error DEBUG Running rule warning DEBUG Running rule yaml DEBUG Running rule command-instead-of-module DEBUG Running rule command-instead-of-shell DEBUG Running rule deprecated-bare-vars DEBUG Running rule deprecated-local-action DEBUG Running rule deprecated-module DEBUG Running rule inline-env-var DEBUG Running rule jinja DEBUG Running rule key-order DEBUG Running rule literal-compare DEBUG Running rule name DEBUG Running rule no-free-form DEBUG Running rule no-jinja-when DEBUG Running rule no-tabs DEBUG Running rule partial-become DEBUG Running rule playbook-extension DEBUG Running rule role-name DEBUG Running rule schema DEBUG Running rule var-naming DEBUG Begin fixing: 1 matches DEBUG Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}} DEBUG Applying rule specific fix for: yaml/yaml file.yml:2 ERROR Rule specific fix not applied for: yaml/yaml file.yml:2 DEBUG Rewriting yaml file: file.yml (yaml), version=None DEBUG Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}} DEBUG Rewriting yaml file: .ansible-lint (ansible-lint-config), version=None DEBUG Fixing: (1 of 1) (Truthy value should be one of ) matched file.yml:2 DEBUG Rerunning: (Truthy value should be one of ) matched file.yml:2 DEBUG Passed 'file.yml' positional argument was identified as generic 'yaml' file kind. DEBUG Examining file.yml of type yaml DEBUG Skipping rule internal-error DEBUG Skipping rule load-failure DEBUG Skipping rule parser-error DEBUG Skipping rule warning DEBUG Running rule yaml DEBUG Skipping rule command-instead-of-module DEBUG Skipping rule command-instead-of-shell DEBUG Skipping rule deprecated-bare-vars DEBUG Skipping rule deprecated-local-action DEBUG Skipping rule deprecated-module DEBUG Skipping rule inline-env-var DEBUG Skipping rule jinja DEBUG Skipping rule key-order DEBUG Skipping rule literal-compare DEBUG Skipping rule name DEBUG Skipping rule no-free-form DEBUG Skipping rule no-jinja-when DEBUG Skipping rule no-tabs DEBUG Skipping rule partial-become DEBUG Skipping rule playbook-extension DEBUG Skipping rule role-name DEBUG Skipping rule schema DEBUG Skipping rule var-naming DEBUG Still found: (Truthy value should be one of ) matched file.yml:2 WARNING Listing 1 violation(s) that are fatal yaml[truthy]: Truthy value should be one of [false, true] file.yml:2 DEBUG Attempting to release lock 127246885286032 on /home/alabate/.cache/ansible-compat/cf10d3/.lock DEBUG Lock 127246885286032 released on /home/alabate/.cache/ansible-compat/cf10d3/.lock Read documentation for instructions on how to ignore specific rule violations. DEBUG Determined rule-profile order: {'internal-error': (0, 'min'), 'load-failure': (1, 'min'), 'parser-error': (2, 'min'), 'syntax-check': (3, 'min'), 'command-instead-of-module': (4, 'basic'), 'command-instead-of-shell': (5, 'basic'), 'deprecated-bare-vars': (6, 'basic'), 'deprecated-local-action': (7, 'basic'), 'deprecated-module': (8, 'basic'), 'inline-env-var': (9, 'basic'), 'key-order': (10, 'basic'), 'literal-compare': (11, 'basic'), 'jinja': (12, 'basic'), 'no-free-form': (13, 'basic'), 'no-jinja-when': (14, 'basic'), 'no-tabs': (15, 'basic'), 'partial-become': (16, 'basic'), 'playbook-extension': (17, 'basic'), 'role-name': (18, 'basic'), 'schema': (19, 'basic'), 'name': (20, 'basic'), 'var-naming': (21, 'basic'), 'yaml': (22, 'basic'), 'name': (23, 'moderate'), 'name': (24, 'moderate'), 'name': (25, 'moderate'), 'spell-var-name': (26, 'moderate'), 'avoid-implicit': (27, 'safety'), 'latest': (28, 'safety'), 'package-latest': (29, 'safety'), 'risky-file-permissions': (30, 'safety'), 'risky-octal': (31, 'safety'), 'risky-shell-pipe': (32, 'safety'), 'galaxy': (33, 'shared'), 'ignore-errors': (34, 'shared'), 'layout': (35, 'shared'), 'meta-incorrect': (36, 'shared'), 'meta-no-tags': (37, 'shared'), 'meta-video-links': (38, 'shared'), 'meta-version': (39, 'shared'), 'meta-runtime': (40, 'shared'), 'no-changed-when': (41, 'shared'), 'no-changelog': (42, 'shared'), 'no-handler': (43, 'shared'), 'no-relative-paths': (44, 'shared'), 'max-block-depth': (45, 'shared'), 'max-tasks': (46, 'shared'), 'unsafe-loop': (47, 'shared'), 'avoid-dot-notation': (48, 'production'), 'sanity': (49, 'production'), 'fqcn': (50, 'production'), 'import-task-no-when': (51, 'production'), 'meta-no-dependencies': (52, 'production'), 'single-entry-point': (53, 'production'), 'use-loop': (54, 'production')} Rule Violation Summary count tag profile rule associated tags 1 yaml[truthy] basic formatting, yaml Failed: 1 failure(s), 0 warning(s) on 2 files. Profile 'basic' was required, but 'min' profile passed. ```

So If I understand correctly, the file is identified a as generic 'yaml'. So it is formatted with YAML 1.2, which consider that YES is not a boolean, so it removed the quotes. But then the yaml[truthy] sees the issue.

Desired Behavior

I would prefear to keep an uniform codebase and have all my "YES" keep their quotes, no matter the YAML version. Because I don't want to ask myself in which version of YAML and vscode will colorate the value like a boolean no matter the type of file.

But I guess, another valid solution would be to ignore yaml[truthy] for files identified as generic 'yaml'

Workarounds

I tried to use the extra-required field of yamllint but it is ignored by ansible-lint formatter.

So the only solution I found is to indicate to ansible-lint that the file is a var file

kinds:
  - vars: "**/file.yml"

You can check the type detected for your file with

# Before
$ ansible-lint --fix -vv 2>&1 | grep Examining
DEBUG    Examining file.yml of type yaml
DEBUG    Examining .ansible-lint of type ansible-lint-config
DEBUG    Examining file.yml of type yaml

# After
$ ansible-lint --fix -vv 2>&1 | grep Examining
DEBUG    Examining .ansible-lint of type ansible-lint-config
DEBUG    Examining file.yml of type vars
kousu commented 4 months ago

This sounds a lot like https://github.com/ansible/ansible-lint/issues/4166, but in the opposite direction. It's probably the same part of the codebase implicated.