You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让所有用户共享Ansible-Galaxy Collection模块及安装故障排查

Ansible模块无法共享及核心安装失败问题

问题现象

运行Playbook时触发以下错误:

ERROR! couldn't resolve module/action 'mount'. This often indicates a misspelling, missing collection, or incorrect module path.

以root身份执行ansible-galaxy collection install ansible.posix可临时解决,但切换为普通用户运行Playbook时,错误会再次出现,推测该问题与通过pip安装Ansible核心未完全成功有关。

Ansible核心安装失败报错信息

执行命令python3 -m pip install --upgrade --user ansible时,出现如下安装失败报错:

#python3 -m pip install --upgrade --user ansible
Collecting ansible
  Using cached ansible-4.10.0.tar.gz (36.8 MB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: ansible-core~=2.11.7 in /usr/local/lib/python3.6/site-packages (from ansible) (2.11.12)
Requirement already satisfied: jinja2 in /usr/local/lib/python3.6/site-packages (from ansible-core~=2.11.7->ansible) (3.0.3)
...
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.6/site-packages (from packaging->ansible-core~=2.11.7->ansible) (3.0.9)
Requirement already satisfied: pycparser in /usr/local/lib/python3.6/site-packages (from cffi>=1.12->cryptography->ansible-core~=2.11.7->ansible) (2.21)
Building wheels for collected packages: ansible
  Building wheel for ansible (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-j1e8ee0o/ansible_739f732c70454ae68e5938304ea21a71/setup.py'"'"'; __file__='"'"'/tmp/pip-install-j1e8ee0o/ansible_739f732c70454ae68e5938304ea21a71/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'
'"'"', '"'"'
'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-188w1992
       cwd: /tmp/pip-install-j1e8ee0o/ansible_739f732c70454ae68e5938304ea21a71/
  Complete output (4095 lines):
  running bdist_wheel
  running build
  running build_py
  package init file 'ansible_collections/__init__.py' not found (or not a regular file)
  creating build
  creating build/lib
  creating build/lib/ansible_collections
  copying ansible_collections/ansible_release.py -> build/lib/ansible_collections
...
... final error
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3cu3mwhw/ansible_acd23d78d456418e9c4c2c02e0e9312a/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3cu3mwhw/ansible_acd23d78d456418e9c4c2c02e0e9312a/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'
'"'"', '"'"'
'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-dysgpttw/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /root/.local/include/python3.6m/ansible Check the logs for full command output.

安装wheel时的提示信息

执行/root/.local/bin/pip install wheel时,输出如下内容:

#/root/.local/bin/pip install wheel
Requirement already satisfied: wheel in /usr/local/lib/python3.6/site-packages (0.37.1)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

临时解决方法

  • 手动安装所需集合:
ansible-galaxy collection install ansible.posix
ansible-galaxy collection install community.general
  • 复制集合文件到系统级目录,实现所有用户共享:
cp -r /root/.ansible/collections/ansible_collections /usr/share/ansible/collections/
chmod -R a+rX /usr/share/ansible/collections/
  • 在ansible.cfg中添加集合路径配置:
collections_paths = /usr/share/ansible/collections/

内容的提问来源于stack exchange,提问作者andrew

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 17:23:13