ansible-lint icon indicating copy to clipboard operation
ansible-lint copied to clipboard

Unable to load module / resolve FQCN for module on initial run of ansible-lint

Open dbrennand opened this issue 1 year ago • 5 comments

Summary

Invoking ansible-lint 24.9.2 on my example collection, ansible-lint shows warnings about being unable to load module and resolve FQCN for a dependent collection module:

In this example, it's community.general.pip_package_info:

INFO     Set ANSIBLE_LIBRARY=/Users/dab/.cache/ansible-compat/0cb87f/modules:/Users/dab/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_ROLES_PATH=/Users/dab/.cache/ansible-compat/0cb87f/roles:roles:/Users/dab/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Provisioning collection community.general:10.0.1 from galaxy.yml
INFO     Running from /Users/dab/repos/repro/ansible : ansible-galaxy collection install -vvv community.general:10.0.1
INFO     Running from /Users/dab/repos/repro/ansible : ansible-galaxy collection install -vvv --force /Users/dab/repos/repro/ansible
WARNING  Unable to load module community.general.pip_package_info at roles/example/tasks/main.yml:3 for options validation
WARNING  Unable to resolve FQCN for module community.general.pip_package_info

The dependent collection is successfully installed to the ansible-compat cache during the initial run:

❯ ls -lah /Users/dab/.cache/ansible-compat/0cb87f/collections/ansible_collections 
Permissions Size User Date Modified Name
drwxr-xr-x     - dab  11 Nov 21:21  community
drwxr-xr-x     - dab  11 Nov 21:21  community.general-10.0.1.info
drwxr-xr-x     - dab  11 Nov 21:21  dbrennand

This only happends on the first run of ansible-lint, once the ~/.cache/ansible-compat/ is established, the warning disappears. This is not ideal when running ansible-lint in one-shot scenarios such as a CI/CD pipeline.

Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint 24.9.2 using ansible-core:2.18.0 ansible-compat:24.9.1 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.12
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE
git clone [email protected]:dbrennand/repro.git
cd repro
mkdir -pv ~/.virtualenvs/
python -m venv ~/.virtualenvs/repro
source ~/.virtualenvs/repro/bin/activate
pip install -r requirements.txt
cd ansible/
ansible-lint -v
# Observe WARNINGs
Desired Behavior

No warnings are shown and the module and FQCN are resolved.

Actual Behavior

Minimal repro example:

❯ ansible-lint -v
INFO     Identified /Users/dab/repos/repro as project root due .git directory.
INFO     Set ANSIBLE_LIBRARY=/Users/dab/.cache/ansible-compat/0cb87f/modules:/Users/dab/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_ROLES_PATH=/Users/dab/.cache/ansible-compat/0cb87f/roles:roles:/Users/dab/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Provisioning collection community.general:10.0.1 from galaxy.yml
INFO     Running from /Users/dab/repos/repro/ansible : ansible-galaxy collection install -vvv community.general:10.0.1
INFO     Running from /Users/dab/repos/repro/ansible : ansible-galaxy collection install -vvv --force /Users/dab/repos/repro/ansible
INFO     Executing syntax check on playbook roles/example/tests/test.yml (0.24s)
INFO     Executing syntax check on role roles/example (0.24s)
...
WARNING  Unable to load module community.general.pip_package_info at roles/example/tasks/main.yml:3 for options validation
WARNING  Unable to resolve FQCN for module community.general.pip_package_info

dbrennand avatar Nov 11 '24 21:11 dbrennand

https://github.com/ansible/ansible-lint/pull/4402 is likely to fix that. Either update ansible-compat manually and test again or wait till we make the next linter release and check if this is sorted.

ssbarnea avatar Nov 13 '24 14:11 ssbarnea

Hi @ssbarnea - Tested the latest ansible-lint release - unfortunately, I'm still seeing this issue.

# Ensure ansible-compat cache is clear
rm -rf ~/.cache/ansible-compat/
❯ cat requirements.txt 
ansible-core==2.18.0
ansible-lint==24.10.0
❯ pip install -r requirements.txt
❯ pip list | grep -E 'ansible-lint|ansible-compat'
ansible-compat            24.10.0
ansible-lint              24.10.0
❯ cd ansible
❯ ansible-lint -v
INFO     Identified /Users/dab/repos/repro as project root due .git directory.
WARNING  <unknown>:1: SyntaxWarning: invalid decimal literal

INFO     Set ANSIBLE_LIBRARY=/Users/dab/.cache/ansible-compat/0cb87f/modules:/Users/dab/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_ROLES_PATH=/Users/dab/.cache/ansible-compat/0cb87f/roles:roles:/Users/dab/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
INFO     Provisioning collection community.general:10.0.1 from galaxy.yml
INFO     Running from /Users/dab/repos/repro/ansible : ansible-galaxy collection install -vvv community.general:10.0.1
INFO     Running from /Users/dab/repos/repro/ansible : ansible-galaxy collection install -vvv --force /Users/dab/repos/repro/ansible
INFO     Executing syntax check on playbook roles/example/tests/test.yml (0.24s)
INFO     Executing syntax check on role roles/example (0.24s)
WARNING  Ignored exception from CheckRequiresAnsibleVersion.matchyaml while processing meta/runtime.yml (meta-runtime): 'NoneType' object has no attribute 'get'
WARNING  Unable to load module community.general.pip_package_info at roles/example/tasks/main.yml:3 for options validation
WARNING  Unable to resolve FQCN for module community.general.pip_package_info

Please let me know how I can assist further with troubleshooting this.

dbrennand avatar Nov 15 '24 08:11 dbrennand

Issue persists

kominoshja avatar Dec 18 '24 19:12 kominoshja

As a workaround for this issue, in my CI/CD pipeline I have the following as part of my job:

if [[ -f "ansible/galaxy.yml" ]]; then
        yq -r '.dependencies | to_entries | .[] | "\(.key) \(.value)"' ansible/galaxy.yml \
        | while read -r collection_name version; do echo "Installing Ansible collection ${collection_name}@${version}"; \
        ansible-galaxy collection install -vvv "${collection_name}:${version}"; done
      fi

dbrennand avatar Jul 25 '25 08:07 dbrennand

Good news! I think this was fixed in Ansible-Lint v25.8.1 by #4722 🙂

I can no longer reproduce this with the same repro example.

❯ uv pip list | grep ansible
Using Python 3.13.1 environment at: /Users/dab/repos/repro/.venv
ansible-compat            25.8.1
ansible-core              2.18.7
ansible-lint              25.8.1

❯ ansible-lint --version
ansible-lint 25.8.1 using ansible-core:2.18.7 ansible-compat:25.8.1 ruamel-yaml:0.18.14 ruamel-yaml-clib:0.2.12

dbrennand avatar Aug 17 '25 11:08 dbrennand