【发布时间】:2022-08-21 04:14:26
【问题描述】:
我已经在新的 Ansible 控制服务器(Debian 11)上验证了我的 Python3 、模块路径和集合路径。但是,当将 ansible-inventory --list 命令指向 Google 云 gcp.yml 库存文件时,我收到此错误:
[WARNING]: * Failed to parse /home/user/CODE/ops/ansible/inventory/gcp-dynamic/demo3/gcp.yml with
ansible_collections.google.cloud.plugins.inventory.gcp_compute plugin: gce inventory plugin cannot start: Failed to import the required Python library
(google-auth) on server\'s Python /usr/bin/python3. Please read the module documentation and install it in the appropriate location
这是完整的清单命令:
ansible-inventory --list -i /path/to/gcp.yml
这是 gcp.yml 文件:
---
plugin: gcp_compute
projects:
- project9
auth_kind: serviceaccount
service_account_file: /home/user/.config/credentials.json
# setup group parasing prefix=inventory label
keyed_groups:
- key: labels
prefix: demo3
这是我的ansible --version 输出:
ansible [core 2.13.2]
config file = /home/user/.ansible.cfg
configured module search path = [\'/home/user/.local/lib/python3.9/site-packages/ansible/modules\']
ansible python module location = /home/user/.local/lib/python3.9/site-packages/ansible
ansible collection location = /home/user/.local/lib/python3.9/site-packages/ansible_collections
executable location = /home/user/.local/bin/ansible
python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
jinja version = 3.1.2
libyaml = True
这是pip3 show google-auth 的输出:
Name: google-auth
Version: 2.10.0
Summary: Google Authentication Library
Home-page: https://github.com/googleapis/google-auth-library-python
Author: Google Cloud Platform
Author-email: googleapis-packages@google.com
License: Apache 2.0
Location: /home/user/.local/lib/python3.9/site-packages
Requires: cachetools, pyasn1-modules, rsa, six
Required-by:
在我的 ~/.ansible.cfg 我有这个:
# (pathspec) Colon separated paths in which Ansible will search for Modules.
library=/home/user/.local/lib/python3.9/site-packages/ansible/modules:/home/user/.local/lib/python3.9/site-packages
关于下一步尝试什么的任何建议?
-
我对 Ansible 不熟悉,但对 Google Cloud 很熟悉。 Python 库使用
google-auth使用应用程序默认凭据(用于服务帐户)进行身份验证。您的 Ansible 配置中似乎缺少此 Python 模块。你有办法添加特定的模块吗?如果 Ansible 正在利用您的默认 Python 环境,那么如果您pip install google-auth再试一次,它可能会起作用。 -
pip3 install google-auth,很可能,pip install google-auth会将其安装在 OP\ 的 Python 2.x 版本上。 -
我肯定安装了 google-auth 模块。我可以在 CLI 上运行 python3 并执行
import google.auth,这工作得很好。 -
pip3 show google-auth给了你什么? (将其添加到您的问题的edit 中,最好不要在评论中)。
标签: python-3.x google-cloud-platform ansible