ansible / vscode-ansible

vscode/vscodium extension for providing Ansible auto-completion and integrating quality assurance tools like ansible-lint, ansible syntax check, yamllint, molecule and ansible-test.
https://ansible.readthedocs.io/projects/vscode-ansible/
MIT License
357 stars 85 forks source link

Modules from collections are not recognized when COLLECTIONS_PATH is set via env var #1263

Open vicmunoz opened 5 months ago

vicmunoz commented 5 months ago

Summary

TLDR: Modules from collections are not recognized (no definition found) when COLLECTIONS_PATH is set via environment variable.

1) ansible.cfg does not have collections_path (https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths) setting in file. However env var ANSIBLE_COLLECTIONS_PATH is set

Screenshot 2024-04-22 at 13 02 53

❯ ansible-config dump | grep COLLECTIONS_PATHS COLLECTIONS_PATHS(env: ANSIBLE_COLLECTIONS_PATH) = ['/Users/victor/Code/Sandbox/automation/.collections']

2) ansible.cfg have collections_path setting in file. Works fine, modules are recognized.

Screenshot 2024-04-22 at 13 03 40

Extension version

v24.4.0

VS Code version

1.88.1

Ansible Version

❯ ansible --version
ansible [core 2.16.5]
  config file = /Users/victor/Code/Sandbox/automation/ansible.cfg
  configured module search path = ['/Users/victor/Code/Sandbox/automation/plugins/modules']
  ansible python module location = /Users/victor/Code/Sandbox/automation/.venv/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/victor/Code/Sandbox/automation/.collections
  executable location = /Users/victor/Code/Sandbox/automation/.venv/bin/ansible
  python version = 3.11.6 (main, Mar 24 2024, 10:42:30) [Clang 15.0.0 (clang-1500.3.9.4)] (/Users/victor/Code/Sandbox/automation/.venv/bin/python)
  jinja version = 3.1.3
  libyaml = True

OS / Environment

MACOS 14.4

Relevant log output

No response

vicmunoz commented 4 months ago

Similar behaviour is observed with ansible-lint validation. When using ANSIBLE_VAULT_IDENTITY and ANSIBLE_VAULT_IDENTITY_LIST with environment variables I get syntax errors:

Unexpected error code 1 from execution of: ansible-playbook -i localhost, --syntax-check site.sample.production.yml

internal-error: Unexpected error code 1 from execution of: ansible-playbook -i localhost, --syntax-check site.sample.production.yml

site.sample.production.yml:1 [WARNING]: Error getting vault password file (credentials): The vault password

However using settings vault_identity and vault_identity_list into ansible.cfg clear all above errors and all runs fine.

Issues that could be related: https://github.com/ansible/ansible-lint/discussions/2404 https://github.com/ansible/ansible-lint/issues/2443 https://github.com/ansible/ansible-lint/issues/2889