-
Notifications
You must be signed in to change notification settings - Fork 648
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
Version 6.12.0 contains regression for resolving modules/actions. #2969
Comments
same here – just spent two hours trying to figure out why all of my ansible projects are failing pre-commit after updating today ... |
Sorry but this reports sounds more of a support ticket than a bug and I will likely have to convert it to a discussion. What I see for sure here is that lack of use of fully qualified module names. Read https://ansible-lint.readthedocs.io/rules/fqcn/#correct-code Also remember that "collections" keyword is not supported. |
@ssbarnea this bug also exists for FQCNs |
@hollow In this case, please try to produce a minimal example that reproduces this bug an nothing else. This should help us reproduce it and produce a fix. While using pre-commit you need to be careful because their SaaS version does not have network access, so it cannot install required collections. If you run it yourself, you do not have this problem. Also, you could use https://github.com/ansible/ansible-lint-action which is the GHA we maintain. Still, with the action there is a slight delay of few days as we do not update it instantly after releasing a new linter, especially if the release was not a patch version. |
@ssbarnea while trying to come up with a minimal example I have realized that the actual issue seems to be burried in a lot of warnings that ansible-lint 6.12.0+ produces:
the list goes on and on, but eventually ansible-lint fails with:
I have extracted the affected task and reproduced the error with the ansible-lint action without pre-commit here: https://github.com/hollow/ansible-lint-regression/actions/runs/4083566375/jobs/7039250446 Not sure if the issue is related to all the new warnings about not being able to load modules though. |
@hollow @ssbarnea here is the minimal # syntax=docker/dockerfile:1
FROM debian
RUN apt-get update && apt install -y git python3-pip python3-wheel
RUN pip install ansible-core==2.13.7 && ansible --version
RUN ansible-galaxy collection install community.general:==6.3.0
RUN pip install ansible-lint==6.12.1 && ansible-lint --version
COPY <<-EOF /playbook.yml
---
- name: Test ansible-lint
hosts: all
vars:
pam_rhel_modules: []
tasks:
- name: Ensure pam modules are configured
community.general.pamd:
foo: bar
bar: foo
loop_control:
label: "{{ item.name }}"
loop: "{{ pam_rhel_modules }}"
EOF
ENTRYPOINT [ "ansible-lint", "-v", "/playbook.yml" ]
Output of the container:
For previous version ansible-lint everything works fine:
|
|
@kristof-mattei In my case installing of the pytest module resolves only the first warning. Check this out. # syntax=docker/dockerfile:1
FROM debian
RUN apt-get update && apt install -y git python3-pip python3-wheel
RUN pip install ansible-core==2.13.7 && ansible --version
RUN ansible-galaxy collection install community.general:==6.3.0
RUN pip install pytest ansible-lint==6.12.0 && ansible-lint --version
COPY <<-EOF /playbook.yml
---
- name: Test ansible-lint
hosts: all
vars:
pam_rhel_modules: []
tasks:
- name: Ensure pam modules are configured
community.general.pamd:
foo: bar
bar: foo
loop_control:
label: "{{ item.name }}"
loop: "{{ pam_rhel_modules }}"
EOF
ENTRYPOINT [ "ansible-lint", "-v", "/playbook.yml" ] docker build -t test-ansible-lint . docker run --rm test-ansible-lint We are expecting error message from linter about missed parameters:
But gets only this:
|
@hollow are you using offline mode? I am seeing also a ton of those warnings + errors, it seems everything outside of Edit: going back to 6.11 and everything works again. |
@bluikko I'm not using offline mode. Despite the warnings (which I ignore for now) I have mitigated the one remaining error (that I have reproduced in the linked repo above) with a |
hm. After seeing the same issue, I may have an idea of what's going on.
|
@apatard it works! # syntax=docker/dockerfile:1
FROM debian
RUN apt-get update && apt install -y git python3-pip python3-wheel
RUN pip install ansible-core==2.13.7 && ansible --version
RUN ansible-galaxy collection install community.general:==6.3.0
RUN pip install pytest ansible-lint==6.12.2 && ansible-lint --version
COPY <<-EOF /runtime.patch
--- ansiblelint/_vendor/ansible_compat/runtime.py.orig 2023-02-13 15:42:31.266911773 +0100
+++ ansiblelint/_vendor/ansible_compat/runtime.py 2023-02-13 15:44:51.132685168 +0100
@@ -142,11 +142,10 @@ class Runtime:
# noinspection PyProtectedMember
# pylint: disable=protected-access
- _AnsibleCollectionFinder(
- paths=[
- os.path.dirname(os.environ.get(ansible_collections_path(), "."))
- ]
- )._install() # pylint: disable=protected-access
+ col_path = [f"{self.cache_dir}/collections"]
+ col_path += self.config.collections_paths
+ col_path += [os.path.dirname(os.environ.get(ansible_collections_path(), "."))]
+ _AnsibleCollectionFinder(paths=col_path)._install() # pylint: disable=protected-access
Runtime.initialized = True
def clean(self) -> None:
EOF
RUN patch /usr/local/lib/python3.9/dist-packages/ansiblelint/_vendor/ansible_compat/runtime.py /runtime.patch
COPY <<-EOF /playbook.yml
---
- name: Test ansible-lint
hosts: all
vars:
pam_rhel_modules: []
tasks:
- name: Ensure pam modules are configured
community.general.pamd:
foo: bar
bar: foo
loop_control:
label: "{{ item.name }}"
loop: "{{ pam_rhel_modules }}"
EOF
ENTRYPOINT [ "ansible-lint", "-v", "/playbook.yml" ] Output:
|
- Ensure the cache dir is added to the collection loader path, in order to allow linting a collection role against a module this collection is providing - Add missing default collection path to the loader for ansible version prior 2.15.0.dev0, as done by ansible's _configure_collection_loader(). The only remaining difference is the missing handling of COLLECTIONS_SCAN_SYS_PATH. See ansible/ansible-lint#2969 for reference. Signed-off-by: Arnaud Patard <apatard@hupstream.com>
@skokhanovskiy thanks for testing. I'm working on a PR for ansible-compat. If it gets merged, then the local version needs to be updated. |
- Ensure the cache dir is added to the collection loader path, in order to allow linting a collection role against a module this collection is providing - Add missing default collection path to the loader for ansible version prior 2.15.0.dev0, as done by ansible's _configure_collection_loader(). The only remaining difference is the missing handling of COLLECTIONS_SCAN_SYS_PATH. See ansible/ansible-lint#2969 for reference. Signed-off-by: Arnaud Patard <apatard@hupstream.com>
* src/ansible_compat/runtime.py: Fix collection loading - Ensure the cache dir is added to the collection loader path, in order to allow linting a collection role against a module this collection is providing - Add missing default collection path to the loader for ansible version prior 2.15.0.dev0, as done by ansible's _configure_collection_loader(). The only remaining difference is the missing handling of COLLECTIONS_SCAN_SYS_PATH. See ansible/ansible-lint#2969 for reference. Signed-off-by: Arnaud Patard <apatard@hupstream.com> * Collection path is a list --------- Signed-off-by: Arnaud Patard <apatard@hupstream.com> Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
Summary
Ansible-lint fails to resolve some modules/actions in playbooks.
Issue Type
OS / ENVIRONMENT
ansible-lint --version # 6.12.0
STEPS TO REPRODUCE
ansible-lint
Desired Behavior
< 6.12.0 (specifically 6.11.0):
Actual Behavior
>= 6.12.0:
Issue was first identified when running newly released version with trunk
The text was updated successfully, but these errors were encountered: