-
Notifications
You must be signed in to change notification settings - Fork 703
Closed
Description
Summary
Files other than "pattern" type—specifically those ending in "pattern.json"—are being flagged for validation by the schema[pattern]
validator.
Issue Type
- Bug Report
OS / ENVIRONMENT
[WARNING]: log file at '/var/log/ansible.log' is not writeable and we cannot create it, aborting
ansible-lint 25.7.0 using ansible-core:2.18.6 ansible-compat:25.6.0 ruamel-yaml:0.18.14 ruamel-yaml-clib:0.2.12
You are using a pre-release version of ansible-lint.
Note: I'm not sure why the output above includes the "pre-release" note; today is Aug 4 and 25.7.0 was released on July 29.
- ansible installation method: pip - 2.18.6
- ansible-lint installation method: pip - 25.7.0
- OS: mac OS 15.5
- python: 3.11.2
STEPS TO REPRODUCE
- In a "files" directory, create a file with JSON content with a filename that ends with "pattern.json", e.g. some-filename-ending-with-pattern.json with contents like:
{
"data": "of some kind",
"nested_data": {
"goes": [
"here"
]
}
}
- Create a playbook that reads the JSON file:
---
- name: Sample playbook to print JSON file content
hosts:
- localhost
tasks:
- name: Print JSON file content
ansible.builtin.debug:
msg: "{{ lookup('file', 'some-filename-ending-with-pattern.json') | from_json }}"
- Alternatively, create a role and place the example JSON file and task within the role and run the role from the playbook (it makes no difference)
- Run
ansible-lint
Desired Behavior
Files ending in "pattern.json" (like some-filename-ending-with-pattern.json) should not be parsed as "pattern" files and validated as-such.
Actual Behavior
$ ansible-lint -vvvv
DEBUG Logging initialized to level 10
INFO Identified / as project root due file system root.
DEBUG Options: Options(_skip_ansible_syntax_check=False, cache_dir=PosixPath('/Users/lgoolsbee/testing/ansible-pattern-schema-example/.direnv/python-3.11/.ansible'), colored=True, configured=True, cwd=PosixPath('/Users/lgoolsbee/testing/ansible-pattern-schema-example'), display_relative_path=True, exclude_paths=['.cache', '.git', '.hg', '.svn', '.tox'], format=None, lintables=[], list_rules=False, list_tags=False, write_list=[], write_exclude_list=[], parseable=False, quiet=0, rulesdirs=[PosixPath('/Users/lgoolsbee/testing/ansible-pattern-schema-example/.direnv/python-3.11/lib/python3.11/site-packages/ansiblelint/rules')], skip_list=[], tags=[], verbosity=4, warn_list=['experimental', 'jinja[spacing]', 'fqcn[deep]'], 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=None, task_name_prefix='{stem} | ', sarif_file=None, config_file=None, generate_ignore=False, rulesdir=[], use_default_rules=False, version=False, list_profiles=False, ignore_file=None, yamllint_file=None, max_tasks=100, max_block_depth=20, supported_ansible_also=[])[/]
DEBUG CWD: /Users/lgoolsbee/testing/ansible-pattern-schema-example
WARNING Project directory /.ansible cannot be used for caching as it is not writable.
DEBUG Logging initialized to level 10
INFO Collection paths was patched to include extra directories /Users/lgoolsbee/.ansible/collections,/usr/share/ansible/collections,/Users/lgoolsbee/testing/ansible-pattern-schema-example/.direnv/python-3.11/lib/python3.11/site-packages
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=/Users/lgoolsbee/testing/ansible-pattern-schema-example/.ansible/modules:/Users/lgoolsbee/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO Set ANSIBLE_COLLECTIONS_PATH=/Users/lgoolsbee/testing/ansible-pattern-schema-example/.ansible/collections:/Users/lgoolsbee/.ansible/collections:/usr/share/ansible/collections:/Users/lgoolsbee/testing/ansible-pattern-schema-example/.direnv/python-3.11/lib/python3.11/site-packages
INFO Set ANSIBLE_ROLES_PATH=/Users/lgoolsbee/testing/ansible-pattern-schema-example/.ansible/roles:/Users/lgoolsbee/.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}}
INFO Loading ignores from .gitignore
DEBUG Excluded: .DS_Store
DEBUG Excluded: .ansible
DEBUG Excluded: .direnv
DEBUG Excluded: .python-version
DEBUG data set to None for files/some-filename-ending-with-pattern.json due to being 'pattern' (text/json) kind.
DEBUG data set to None for requirements.txt due to being '' (unknown) kind.
DEBUG data set to None for .gitignore due to being '' (unknown) kind.
DEBUG data set to None for .envrc due to being '' (unknown) kind.
INFO Executing syntax check on playbook pb.test.yml (0.27s)
DEBUG Examining files/some-filename-ending-with-pattern.json of type pattern
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 args
DEBUG Running rule avoid-implicit
DEBUG Running rule command-instead-of-module
DEBUG Running rule command-instead-of-shell
DEBUG Running rule complexity
DEBUG Running rule deprecated-bare-vars
DEBUG Running rule deprecated-local-action
DEBUG Running rule deprecated-module
DEBUG Running rule fqcn
DEBUG Running rule galaxy
DEBUG Running rule ignore-errors
DEBUG Running rule inline-env-var
DEBUG Running rule jinja
DEBUG Running rule key-order
DEBUG Running rule latest
DEBUG Running rule literal-compare
DEBUG Running rule loop-var-prefix
DEBUG Running rule meta-incorrect
DEBUG Running rule meta-no-tags
DEBUG Running rule meta-runtime
DEBUG Running rule meta-video-links
DEBUG Running rule name
DEBUG Running rule no-changed-when
DEBUG Running rule no-free-form
DEBUG Running rule no-handler
DEBUG Running rule no-jinja-when
DEBUG Running rule no-relative-paths
DEBUG Running rule no-tabs
DEBUG Running rule package-latest
DEBUG Running rule partial-become
DEBUG Running rule pattern
WARNING Ignored exception from PatternRule.matchyaml while processing files/some-filename-ending-with-pattern.json (pattern): 'Could not extract playbook name'
DEBUG Ignored exception details
Traceback (most recent call last):
File "/Users/lgoolsbee/testing/ansible-pattern-schema-example/.direnv/python-3.11/lib/python3.11/site-packages/ansiblelint/rules/pattern.py", line 147, in values_from_pattern_json
playbook_name = data["aap_resources"]["controller_job_templates"][0][
~~~~^^^^^^^^^^^^^^^^^
KeyError: 'aap_resources'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/lgoolsbee/testing/ansible-pattern-schema-example/.direnv/python-3.11/lib/python3.11/site-packages/ansiblelint/_internal/rules.py", line 105, in getmatches
matches.extend(method(file))
^^^^^^^^^^^^
File "/Users/lgoolsbee/testing/ansible-pattern-schema-example/.direnv/python-3.11/lib/python3.11/site-packages/ansiblelint/rules/pattern.py", line 74, in matchyaml
values = values_from_pattern_json(file.path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/lgoolsbee/testing/ansible-pattern-schema-example/.direnv/python-3.11/lib/python3.11/site-packages/ansiblelint/rules/pattern.py", line 153, in values_from_pattern_json
raise KeyError(msg) from exc
KeyError: 'Could not extract playbook name'[/]
DEBUG Running rule playbook-extension
DEBUG Running rule risky-file-permissions
DEBUG Running rule risky-octal
DEBUG Running rule risky-shell-pipe
DEBUG Running rule role-name
DEBUG Running rule run-once
DEBUG Running rule sanity
DEBUG Running rule schema
DEBUG Running rule var-naming
DEBUG Examining pb.test.yml of type playbook
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 args
DEBUG Running rule avoid-implicit
DEBUG Running rule command-instead-of-module
DEBUG Running rule command-instead-of-shell
DEBUG Running rule complexity
DEBUG Running rule deprecated-bare-vars
DEBUG Running rule deprecated-local-action
DEBUG Running rule deprecated-module
DEBUG Running rule fqcn
DEBUG Running rule galaxy
DEBUG Running rule ignore-errors
DEBUG Running rule inline-env-var
DEBUG Running rule jinja
DEBUG NAME 'lookup' (prefix='')
DEBUG LPAR '(' (prefix='')
DEBUG STRING "'file'" (prefix='')
DEBUG COMMA ',' (prefix='')
DEBUG STRING "'some-filename-ending-with-pattern.json'" (prefix=' ')
DEBUG RPAR ')' (prefix='')
DEBUG VBAR '|' (prefix=' ')
DEBUG NAME 'from_json' (prefix=' ')
DEBUG NEWLINE '\n' (prefix=' ')
DEBUG ENDMARKER '' (prefix='')
DEBUG Stop.
DEBUG NAME 'lookup' (prefix='')
DEBUG LPAR '(' (prefix='')
DEBUG STRING "'file'" (prefix='')
DEBUG COMMA ',' (prefix='')
DEBUG STRING "'some-filename-ending-with-pattern.json'" (prefix=' ')
DEBUG RPAR ')' (prefix='')
DEBUG VBAR '|' (prefix=' ')
DEBUG NAME 'from_json' (prefix=' ')
DEBUG NEWLINE '\n' (prefix='')
DEBUG ENDMARKER '' (prefix='')
DEBUG Stop.
DEBUG Running rule key-order
DEBUG Running rule latest
DEBUG Running rule literal-compare
DEBUG Running rule loop-var-prefix
DEBUG Running rule meta-incorrect
DEBUG Running rule meta-no-tags
DEBUG Running rule meta-runtime
DEBUG Running rule meta-video-links
DEBUG Running rule name
DEBUG Running rule no-changed-when
DEBUG Running rule no-free-form
DEBUG Running rule no-handler
DEBUG Running rule no-jinja-when
DEBUG Running rule no-relative-paths
DEBUG Running rule no-tabs
DEBUG Running rule package-latest
DEBUG Running rule partial-become
DEBUG Running rule pattern
DEBUG Running rule playbook-extension
DEBUG Running rule risky-file-permissions
DEBUG Running rule risky-octal
DEBUG Running rule risky-shell-pipe
DEBUG Running rule role-name
DEBUG Running rule run-once
DEBUG Running rule sanity
DEBUG Running rule schema
DEBUG Running rule var-naming
WARNING Listing 1 violation(s) that are fatal
schema[pattern]: $ 'schema_version' is a required property
files/some-filename-ending-with-pattern.json:1 Returned errors will not include exact line numbers, but they will mention
the schema name being used as a tag, like ``schema[playbook]``,
``schema[tasks]``.
This rule is not skippable and stops further processing of the file.
If incorrect schema was picked, you might want to either:
* move the file to standard location, so its file is detected correctly.
* use ``kinds:`` option in linter config to help it pick correct file type.
[/]
DEBUG Attempting to release lock 4372445584 on /Users/lgoolsbee/testing/ansible-pattern-schema-example/.direnv/python-3.11/.ansible/.lock
DEBUG Lock 4372445584 released on /Users/lgoolsbee/testing/ansible-pattern-schema-example/.direnv/python-3.11/.ansible/.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[template]': (23, 'moderate'), 'name[imperative]': (24, 'moderate'), 'name[casing]': (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'), 'pattern': (48, 'production'), 'avoid-dot-notation': (49, 'production'), 'sanity': (50, 'production'), 'fqcn': (51, 'production'), 'import-task-no-when': (52, 'production'), 'meta-no-dependencies': (53, 'production'), 'single-entry-point': (54, 'production'), 'use-loop': (55, 'production')}[/]
# Rule Violation Summary
1 schema profile:basic tags:core
DEBUG Found virtualenv, assuming `pip3 install` will work.
DEBUG Registered VCS backend: bzr
DEBUG Registered VCS backend: git
DEBUG Registered VCS backend: hg
DEBUG Registered VCS backend: svn
DEBUG Found ansible-lint 25.7.0 dist
Failed: 1 failure(s), 0 warning(s) on 5 files. Last profile that met the validation criteria was 'min'.
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Done