【问题标题】:ansible-inventory --list command failing with gce plugin error: gce inventory plugin cannot startansible-inventory --list 命令失败并出现 gce 插件错误:gce 库存插件无法启动
【发布时间】: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


【解决方案1】:

我在通过 pip 按照ansible docs 的规定安装 Ansible 和“apt”之间来回切换。

我终于让这个动态库存与这个设置一起工作:

来自 GCP 的 Debian11 基础 VM,然后以 root 身份执行所有操作: python -- 已安装 (/usr/bin/python3) 点子 可靠的 谷歌身份验证

我确保以 root 身份添加所有附加包,而不是让我的安装面向单个用户:

pip --installed pip with apt: sudo apt install python3-pip

ansible -- 安装了 apt: sudo apt install ansible

google-auth -- 也以 root 身份安装:sudo pip3 install google-auth

似乎主要问题是pipapt 之间的安装方法不匹配。在这种情况下,当我通过 apt 完成所有操作并且没有通过 pip 安装 Ansible 时,一切都会自行解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-02
    • 1970-01-01
    • 2018-10-10
    • 2017-08-14
    • 2013-06-26
    • 1970-01-01
    • 2018-11-25
    相关资源
    最近更新 更多