Skip to content

Regression of #1771 -- collections_paths from ansible.cfg is ignored, even though other variables are honored. #4851

@otheus

Description

@otheus
Summary

[!note] This may be specific to the Mac/Brew version of this project.

When ansible-lint is run, and sync_path is disabled, ansible-lint choses its own values for the collection_path, ignoring what it reads from ansible.cfg. This can be seen in comparing the output of --version and from -vvvv.

Issue Type
  • Bug Report
OS / ENVIRONMENT
$ uname -s -r
Darwin 24.5.0

$ ansible-lint --version -vvvv
DEBUG    Logging initialized to level 10
INFO     Identified /Users/me/projects/osdb-deployment as project root due .git directory.
DEBUG    Options: Options(_skip_ansible_syntax_check=False, cache_dir=PosixPath('/Users/me/projects/osdb-deployment/.ansible'), colored=True, configured=True, cwd=PosixPath('/Users/me/projects/osdb-deployment'), display_relative_path=True, exclude_paths=['.cache', '.git', '.hg', '.svn', '.tox'], format=None, lintables=[], list_rules=False, list_tags=False, write_list=[], write_exclude_list=[], parseable=False, quiet=0, rulesdirs=[PosixPath('/opt/homebrew/Cellar/ansible-lint/25.11.0_1/libexec/lib/python3.14/site-packages/ansiblelint/rules')], skip_list=[], tags=[], verbosity=4, warn_list=['experimental', 'jinja[spacing]', 'fqcn[deep]'], mock_filters=[], mock_modules=[], mock_roles=[], loop_var_prefix=None, only_builtins_allow_collections=[], only_builtins_allow_modules=[], var_naming_pattern=None, offline=False, project_dir='.', extra_vars=None, enable_list=[], skip_action_validation=True, strict=False, rules={}, profile=None, task_name_prefix='{stem} | ', sarif_file=None, config_file=None, generate_ignore=False, rulesdir=[], use_default_rules=False, version=True, list_profiles=False, ignore_file=None, yamllint_file=None, max_tasks=100, max_block_depth=20, supported_ansible_also=[])[/]
DEBUG    CWD: /Users/me/projects/osdb-deployment
DEBUG    Attempting to release lock 4392823712 on /Users/me/projects/osdb-deployment/.ansible/.lock
DEBUG    Lock 4392823712 released on /Users/me/projects/osdb-deployment/.ansible/.lock


$ ansible --version
ansible [core 2.16.3]
  config file = /Users/me/projects/osdb-deployment/ansible.cfg
  configured module search path = ['/Users/me/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/me/projects/osdb-deployment:/opt/homebrew/lib/python3.10/site-packages/ansible_collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.10.9 (main, Dec 15 2022, 10:44:50) [Clang 14.0.0 (clang-1400.0.29.202)] (/opt/homebrew/opt/[email protected]/bin/python3.10)
  jinja version = 3.1.3
  libyaml = True

Yes, there is a mismatch in version numbers, due to the fact that ansible 2.14 broke backward compatibility with legacy hosts, which unfortunately, must still be supported in my environment. Immutably.

For probably related reasons, ANSIBLE_COLLECTIONS_SCAN_SYS_PATH is also disabled because otherwise, ansible-lint tries to use the sys.path from Python 3.14 and not 3.10.

Local environment setup:

$ pwd
/Users/me/projects/osdb-deployment

$ printenv|grep ANSIBLE
ANSIBLE_GATHERING=explicit

$ grep collection ansible.cfg
collections_scan_sys_path = false
collections_paths = :/opt/homebrew/lib/python3.10/site-packages/ansible_collections
STEPS TO REPRODUCE

this varies from the ansible command above.

Actual Behavior

Whether the project's ansible.cfg file or the user's $HOME/.ansible.cfg has the collections_paths variable, it is ignored.

When running ansible-lint -vvvv, the output includes:

INFO     Set ANSIBLE_COLLECTIONS_PATH=/Users/me/projects/osdb-deployment/.ansible/collections:/Users/me/.ansible/collections:/usr/share/ansible/collections

... and the requisite modules from the general collections is never found, resulting in standard errors for a given playbook.

It is possible to resolve the issue (sort of) by explicitly setting the environment variable ANSIBLE_COLLECTIONS_PATH to the location configured in the project's ansible.cfg. Other tests indicate that ansible-lint is reading the ansible.cfg file for other configuration items, (such as COLLECTIONS_SCAN_SYS_PATH) but that this one is simply ignored.

Desired Behavior

ansible-lint should use the collections_path from ansible.cfg if it is set, or there should be a way to prepend that value if necessary somehow.

Presumably this problem was identified and fixed with Issue #1771, back in "version 6.0.0". Either it wasn't or it has reappeared.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnewTriage required

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions