-
Notifications
You must be signed in to change notification settings - Fork 696
Allow loading of yamllint config from a different location #4644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Provides an option to specify the path to the yamllint config file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining well your use case, it makes sense. The only issue is that I want to avoid adding more cli arguments to the tool. Still, adding a configuration option might be ok.
@cidrblock WDYT about this? Should we instead allow it only as an option inside ansible-lint config instead of extra cli argument or leave it like this?
I think it's a great contribution. No concern about additional CLI params. |
Awesome! Thanks @cidrblock 🙂 - Are we good to go then? @ssbarnea? |
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
Thanks folks! ❤️ 😁 @ssbarnea @shatakshiiii @cidrblock @audgirka |
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.