我遇到 Ansible Lint 未找到community.general
模块的问题:
> ansible-lint <redacted>.yml
WARNING Listing 1 violation(s) that are fatal
syntax-check[unknown-module]: couldn't resolve module/action 'community.general.locale_gen'. This often indicates a misspelling, missing collection, or incorrect module path.
<readacted>.yml:16:3
这个动作是:
- name: Set locale
community.general.locale_gen:
name: en_US.UTF-8
我使用的是 macOS Sonoma 14.4.1,并且我已经通过Homebrew安装了 Ansible (版本详细信息在最后)。据我所知,这包括许多社区模块,而无需通过 Ansible Galaxy 安装它们:
> ansible-galaxy collection list | grep community.general
community.general 8.6.0
所以剧本运行得很好,但ansilbe-lint
找不到模块。
我确实在顶部注意到了这一点ansible-galaxy collection list
:
# /opt/homebrew/Cellar/ansible/9.5.1/libexec/lib/python3.12/site-packages/ansible_collections
Collection Version
---------------------------------------- -------
如果我设置ANSIBLE_COLLECTIONS_PATH
为该/opt/homebrew/.../ansible_collections
路径,那么它就可以工作。但我似乎不必这样做?如果ansible-playbook
能找到,为什么找不到ansible-lint
?如何自动ansible-lint
查找内置集合路径?
版本信息:
> ansible --version
ansible [core 2.16.6]
config file = /Users/dave/work/ansible/dribin-infra/ansible.cfg
configured module search path = ['/Users/dave/work/ansible/dribin-infra/library']
ansible python module location = /opt/homebrew/Cellar/ansible/9.5.1/libexec/lib/python3.12/site-packages/ansible
ansible collection location = /Users/dave/.ansible/collections:/usr/share/ansible/collections
executable location = /opt/homebrew/bin/ansible
python version = 3.12.3 (main, Apr 9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)] (/opt/homebrew/Cellar/ansible/9.5.1/libexec/bin/python)
jinja version = 3.1.3
libyaml = True
==> ansible: stable 9.5.1 (bottled), HEAD
Automate deployment, configuration, and upgrading
https://www.ansible.com/
Installed
/opt/homebrew/Cellar/ansible/9.5.1 (31,927 files, 365.5MB) *
Poured from bottle using the formulae.brew.sh API on 2024-04-26 at 23:40:10
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/a/ansible.rb
...