Skip to content

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

Merged
merged 3 commits into from
Jul 4, 2025

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?

@cidrblock
Copy link
Contributor

I think it's a great contribution. No concern about additional CLI params.

@dbrennand
Copy link
Contributor Author

Awesome! Thanks @cidrblock 🙂 - Are we good to go then? @ssbarnea?

@github-project-automation github-project-automation bot moved this from In Progress to Review in 🧰 devtools project board Jul 1, 2025
@ssbarnea ssbarnea changed the title feat(args): yamllint-file Allow loading of yamllint config from a different location Jul 1, 2025
@ssbarnea ssbarnea enabled auto-merge July 1, 2025 14:41
@ssbarnea ssbarnea added this pull request to the merge queue Jul 1, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 1, 2025
@ssbarnea ssbarnea added this pull request to the merge queue Jul 1, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jul 1, 2025
@audgirka audgirka added this pull request to the merge queue Jul 2, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 2, 2025
@shatakshiiii shatakshiiii added this pull request to the merge queue Jul 3, 2025
@shatakshiiii shatakshiiii removed this pull request from the merge queue due to a manual request Jul 3, 2025
@shatakshiiii shatakshiiii added this pull request to the merge queue Jul 3, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jul 3, 2025
@shatakshiiii shatakshiiii added this pull request to the merge queue Jul 4, 2025
@shatakshiiii shatakshiiii removed this pull request from the merge queue due to a manual request Jul 4, 2025
@shatakshiiii shatakshiiii added this pull request to the merge queue Jul 4, 2025
@shatakshiiii shatakshiiii removed this pull request from the merge queue due to the queue being cleared Jul 4, 2025
@github-project-automation github-project-automation bot moved this from Review to Done in 🧰 devtools project board Jul 4, 2025
@shatakshiiii shatakshiiii reopened this Jul 4, 2025
@github-project-automation github-project-automation bot moved this from Done to Review in 🧰 devtools project board Jul 4, 2025
@shatakshiiii shatakshiiii enabled auto-merge July 4, 2025 06:29
@shatakshiiii shatakshiiii disabled auto-merge July 4, 2025 06:41
@shatakshiiii shatakshiiii added this pull request to the merge queue Jul 4, 2025
github-merge-queue bot pushed a commit that referenced this pull request Jul 4, 2025
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
@shatakshiiii shatakshiiii removed this pull request from the merge queue due to a manual request Jul 4, 2025
@ssbarnea ssbarnea merged commit 193bc72 into ansible:main Jul 4, 2025
45 checks passed
@github-project-automation github-project-automation bot moved this from Review to Done in 🧰 devtools project board Jul 4, 2025
@dbrennand
Copy link
Contributor Author

Thanks folks! ❤️ 😁 @ssbarnea @shatakshiiii @cidrblock @audgirka

@dbrennand dbrennand deleted the dbrennand-yamllint-load branch July 4, 2025 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants