feat(args): yamllint-file #4644
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Short Description
This PR implements a new CLI option named
--yamllint-file
. It accepts a path to ayamllint
config file containing yamllint rules to be loaded byansible-lint
.Reason for Implementation
Current behaviour of
ansible-lint
is to search the current working directory for the followingyamllint
config files. This becomes an issue when you runansible-lint
from a directory which is not relative to theyamllint
config file. I've hit this issue when we have a monorepo structure and our Ansible collection is located in theansible
subdirectory, but our project'syamllint
config is located at the root of the project. For example:I'd like to mention that this wouldn't be an issue if
--project-dir
installed the Ansible collection itself at runtime, but as mentioned in #3957 here, it doesn't seem to do this. It only does this when you runansible-lint
relative to where the collection is located. So we hit a scenario where we either:ansible-lint
relative to where the collection is located, andansible-lint
installs our collection at runtime, but then doesn't load our customyamllint
rules.--project-dir
and our customyamllint
rules are loaded but then the collection isn't installed at runtime and we get[syntax-check]
errors as the roles cannot be found from our collection.Implementing this new option means we can specify the exact path to our custom
yamllint
config file no matter where it is located. We could have used theYAMLLINT_CONFIG_FILE
environment variable, but it's not as obvious where that configuration is set, if we can specify directly as a CLI option, then it's clear and straightforward. Furthermore, there are other CLI options for specifying paths to other config files, so it makes sense to do it for theyamllint
config file too. Finally, I'd like to mention that this feature should be backwards compatible, as we check if the option is not provided, then it uses the previous behaviour.