Skip to content

feat(args): yamllint-file #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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dbrennand
Copy link
Contributor

@dbrennand dbrennand commented Jun 18, 2025

Short Description

This PR implements a new CLI option named --yamllint-file. It accepts a path to a yamllint config file containing yamllint rules to be loaded by ansible-lint.

Reason for Implementation

Current behaviour of ansible-lint is to search the current working directory for the following yamllint config files. This becomes an issue when you run ansible-lint from a directory which is not relative to the yamllint config file. I've hit this issue when we have a monorepo structure and our Ansible collection is located in the ansible subdirectory, but our project's yamllint config is located at the root of the project. For example:

/home/user/project/.yamllint.yml <--- Yamllint config file located here
/home/user/project/ansible/galaxy.yml <--- Ansible collection is located in this subdirectory

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 run ansible-lint relative to where the collection is located. So we hit a scenario where we either:

  • Run ansible-lint relative to where the collection is located, and ansible-lint installs our collection at runtime, but then doesn't load our custom yamllint rules.
  • Or we run ansible-lint at the root of our project, specifying --project-dir and our custom yamllint 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 the YAMLLINT_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 the yamllint 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.

Provides an option to specify the path to the yamllint config file.
Copy link
Member

@ssbarnea ssbarnea left a 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants