Inconsistent results when run ansible-lint command and run ansible-lint with pre-commit #1758
Replies: 2 comments
-
Not a bug, documented behavior. I am sure that the example for using internet with pre-commit does have pass_filenames disabled. |
Beta Was this translation helpful? Give feedback.
-
Look at https://github.com/ansible-community/ansible-lint/blob/main/.pre-commit-hooks.yaml#L13 and https://ansible-lint.readthedocs.io/en/latest/configuring.html#pre-commit-setup If you follow that guideline you will get the same kind of behavior for running ansible-lint without arguments when running with pre-commit. Ansible-lint cannot reliably be run against specific files because it needs context. For example a task file cannot be evaluated in absence of a playbook or role that includes it. |
Beta Was this translation helpful? Give feedback.
-
Summary
If you run
ansible-lint
in an Ansible project (without any positional arguments), yaml files are detected as yaml files.If you run ansible-lint with
pre-commit
, as pre-commit send each changed yaml file as a positional argument to ansible-lint,yaml files are detected as playbook.
This results from the changes in PR #1273:
https://github.com/ansible-community/ansible-lint/pull/1273/files#diff-d453523679145f511ca4e8fb97be96e7dd664ae88373e2e5e9a90a65fd751cabR760-R768
Sadly the PR and commit doesn't tell us why files provided as positional argument to ansible-lint are always treated as playbooks, maybe @ssbarnea can tell us here more.
Issue Type
Ansible and Ansible Lint details
OS / ENVIRONMENT
Ubuntu 20.04
STEPS TO REPRODUCE
ansible-lint
(test.yaml is detected as yaml file and shows no error)ansible-lint test.yaml
(test.yaml is detected as playbook and shows an error)pre-commit run --files test.yaml ansible-lint
(test.yaml is detected as playbook and shows an error)Desired Behaviour
Yaml files provided to ansible-lint as positional argument should not always be treated as playbooks.
Actual Behaviour
Yaml files provided to ansible-lint as positional argument are always be treated as playbooks.
Beta Was this translation helpful? Give feedback.
All reactions