Skip to content
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

ANSIBLE_LINT enablement in Megalinter configurations is not checking the ansible yaml validations. #3424

Closed
selvanayaki678 opened this issue Mar 13, 2024 · 12 comments
Labels
bug Something isn't working O: stale 🤖 This issue or pull request is stale, it will be closed if there is no activity

Comments

@selvanayaki678
Copy link

Describe the bug
ANSIBLE_LINT enablement in Megalinter configurations is not checking the ansible yaml validations.
enabled the ansible_lint in megalinter configuration file. In output getting like this

image

Expected behavior
It needs to check the all yaml files inside the directory and subdirectory as well.

Screenshots
Megalinter config file:
image

Additional context
Running meglinter as container
sudo docker run -v $(pwd):/tmp/lint -e MEGALINTER_CONFIG=.mega-linter.yml -e ANSIBLE_DIRECTORY=any -e ANSIBLE_ANSIBLE_LINT_DIRECTORY=any -e VALIDATE_ALL_CODEBASE=true -e ANSIBLE_ANSIBLE_LINT_FILE_EXTENSIONS=[] oxsecurity/megalinter:v7

**Output **
image

I have some wrong ANSIBLE format files inside that directory. But it's not giving anything in output.
Need a guidance for to do that

@selvanayaki678 selvanayaki678 added the bug Something isn't working label Mar 13, 2024
@echoix
Copy link
Collaborator

echoix commented Mar 13, 2024

I'm not sure that any has a special meaning here, I think what your configuration is doing is specifying that you want to the Ansible linter to lint in the directory named any.

@selvanayaki678
Copy link
Author

selvanayaki678 commented Mar 13, 2024

I want ansible-lint to lint the current folder of all files and sub-directory files. I don't want to mention any folder name to lint. it automatically needs to pick current folder

@nvuillam
Copy link
Member

@selvanayaki678 please can you try ANSIBLE_DIRECTORY=. ANSIBLE_ANSIBLE_LINT_DIRECTORY=. ?

@selvanayaki678
Copy link
Author

Will try.Thank you

@alexanderbazhenoff
Copy link
Contributor

I have a slightly similar question: how ML detects to turn on ansible-lint?

I have an ansible project with correct ansible collection directory structure and .ansible-lint file in the root of repo dir. Ansible lint wasn't started, so I add ANSIBLE_DIRECTORY: any to .mega-linter.yml. Nothing happended. Then I decided to add options ANSIBLE_ANSIBLE_LINT_ARGUMENTS: --force-color -p and nothing happened again. Only when I add ANSIBLE_DIRECTORY: . ansible-lint has started.

Please improve detecting ansible in the project: at least, enable them when ansible-lint default config is found.

@echoix
Copy link
Collaborator

echoix commented Mar 24, 2024

ie: projects following the directory structure now documented here https://docs.ansible.com/ansible/latest/tips_tricks/sample_setup.html#sample-directory-layout should work without adjustements. Is the current default config aligned to a previous usage pattern that no longer exists?
Its sure changing our defaults would break all the others that currently "just work" with the current defaults

@alexanderbazhenoff
Copy link
Contributor

alexanderbazhenoff commented Mar 24, 2024

Ok. I'm curious, whats wrong in my repo to automatically detect ansible? :)

Most of ansible collections were usually made with the following structure.

But if your ansible role named as 'common' the directory structure roles -> common from your link will be right. Yes, it looks like I have the same structure.

Why not also check the existence of .ansible-lint (in a project root)?

@plosso
Copy link

plosso commented Mar 26, 2024

Same issue here, did exactly what alexander did. Only when I changed ANSIBLE_DIRECTORY: . did the linter run.

@nvuillam
Copy link
Member

So if I summarize, what would fit the requirement would be something like:

Activate ansible-lint if either ANSIBLE_DIRECTORY is found, either .ansible-lint file is found at the root of the repo ?

@plosso
Copy link

plosso commented Mar 27, 2024

Yes. Not to complicate matters more but we set our LINTER_RULES_PATH to a subdirectory so if it takes that into account.
We use a repo to house our linter rules and the workflow pulls that in and stages in the root of the repo; easier than maintaining the same files in multiple repositories. i.e. ./linter-config/.ansible-lint

@alexanderbazhenoff
Copy link
Contributor

alexanderbazhenoff commented Mar 27, 2024

Activate ansible-lint if either ANSIBLE_DIRECTORY is found, either .ansible-lint file is found at the root of the repo ?

I think, activate ansible-lint when roles folder or .ansible-lint file is found. But if ANSIBLE_DIRECTORY is set run ansible-lint anyway (doesn't matter roles and .ansible-lint is found).

Don't know what other scans ML performed, but expected that ANSIBLE_DIRECTORY=any lint every *.yml in the project.

Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity.
It will be closed in 14 days if no further activity occurs.
Thank you for your contributions.

If you think this issue should stay open, please remove the O: stale 🤖 label or comment on the issue.

@github-actions github-actions bot added the O: stale 🤖 This issue or pull request is stale, it will be closed if there is no activity label Apr 27, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working O: stale 🤖 This issue or pull request is stale, it will be closed if there is no activity
Projects
None yet
Development

No branches or pull requests

5 participants