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

auto-detect modules with collection layouts #778

Closed
ssbarnea opened this issue May 8, 2020 · 3 comments · Fixed by #1226
Closed

auto-detect modules with collection layouts #778

ssbarnea opened this issue May 8, 2020 · 3 comments · Fixed by #1226
Labels

Comments

@ssbarnea
Copy link
Member

ssbarnea commented May 8, 2020

Ansible-lint ability to just work without any extra tuning can be improved by making it automatically define ANSIBLE_LIBRARY=plugins/modules when the variable is not already defined.

This would follow the official collection repository layout and make ansible-lint more likely work without extra configuration.

This feature should be enabled only with auto-detection mode because it needs to know what is the repository root location. That is because the tool could be called from any subdirectory and we do expect to give the same kind of results.

When implement this feature should allow people to remove extra code added to files like tox.ini or .pre-commit-config.yaml that define ANSIBLE_LIBRARY in order to be able perform the linting.

@ssbarnea
Copy link
Member Author

@webknjaz While trying to fix this I discovered one problem inside main, where I tried to alter ANSIBLE_LIBRARY in order to make it discoverable.

By the time main runs, we already imported ansible and altering it will no longer work. That is happening because we do import from ansiblelint.utils which imports from ansible.

Fixing this is not very easy because we host initialize_logger() inside utils, which needs to run ASAP, clearly before our detection code.

@webknjaz
Copy link
Member

@ssbarnea I think this could be done by splitting the utils.

This was referenced May 27, 2020
@ssbarnea
Copy link
Member Author

While spliting utils may move us into a good direction it will not be enough to address it.

Mainly we are affected by ansible/ansible#69758 and we need to find a way to config Ansible to rediscover its modules after some ansible module imports already happened.

ssbarnea added a commit that referenced this issue Jan 11, 2021
Makes local modules available to ansible when the plugins/modules exists
on disk but only if the user did not already define ANSIBLE_LIBRARY.

This means that from now on users are not forced to use use the old
hack of defining ANSIBLE_LIBRARY=plugins/modules before running the
linter, something that made it harder to use with pre-commit, tox, CI.

If the variable is already defined or the folder does not exist,
nothing is done.

Fixes: #778
ssbarnea added a commit that referenced this issue Jan 11, 2021
Makes local modules available to ansible when the plugins/modules exists
on disk but only if the user did not already define ANSIBLE_LIBRARY.

This means that from now on users are not forced to use use the old
hack of defining ANSIBLE_LIBRARY=plugins/modules before running the
linter, something that made it harder to use with pre-commit, tox, CI.

If the variable is already defined or the folder does not exist,
nothing is done.

Fixes: #778
ssbarnea added a commit that referenced this issue Jan 11, 2021
Makes local modules available to ansible when the plugins/modules exists
on disk but only if the user did not already define ANSIBLE_LIBRARY.

This means that from now on users are not forced to use use the old
hack of defining ANSIBLE_LIBRARY=plugins/modules before running the
linter, something that made it harder to use with pre-commit, tox, CI.

If the variable is already defined or the folder does not exist,
nothing is done.

Fixes: #778
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants