You need to enable JavaScript to run this app. Ansible运行gcp_compute inventory插件失败问题求助
优惠活动
大模型
产品
解决方案
定价
更多

Ansible运行gcp_compute inventory插件失败问题求助

问题根因

你当前使用的Ansible 2.5.1版本过低,gcp_compute inventory插件是Ansible 2.7版本才正式纳入官方内置插件列表,因此你本地的Ansible插件库中不存在该组件,同时还存在依赖缺失、插件未启用的问题,可按以下步骤解决:

解决步骤

  1. 升级Ansible到兼容版本
    Ansible 2.10是最后一个支持Python 2.7的大版本,如果你暂时需要保留当前Python 2.7环境,可安装适配的最高兼容版:
# 卸载旧版Ansible
sudo pip uninstall ansible -y
# 安装Python2.7兼容的Ansible版本
sudo pip install 'ansible<2.11'

如果可以升级运行环境,建议切换到Python 3安装最新版Ansible,兼容性更好:

sudo pip3 install ansible
  1. 安装GCP依赖库
    gcp_compute插件依赖Google Cloud的Python SDK,执行对应命令安装:
# Python2环境
sudo pip install requests google-auth
# Python3环境
sudo pip3 install requests google-auth
  1. 启用gcp_compute插件
    修改Ansible配置文件(全局配置为/etc/ansible/ansible.cfg,用户级配置为~/.ansible.cfg),在[inventory]配置段的enable_plugins列表中添加gcp_compute:
[inventory]
enable_plugins = host_list, script, auto, yaml, ini, gcp_compute, constructed
  1. 调整inventory文件命名(可选)
    gcp_compute插件默认会自动识别后缀为.gcp.yml或.gcp.yaml的inventory文件,你可以把gcp_test.yaml重命名为gcp_test.gcp.yaml,避免自动识别失败。

验证配置

配置完成后执行以下命令验证插件是否正常加载:

ansible-doc -t inventory gcp_compute

如果没有出现not found的警告,再重新执行inventory查询命令即可正常获取GCP资源清单。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.15 04:15:02