使用Ansible Azure动态插件生成Inventory时遇报错求助
解决Ansible Azure动态Inventory解析错误
问题原因
报错Plugin configuration YAML file, not YAML inventory表明Ansible未将你的配置文件识别为Azure动态inventory插件的配置,核心原因通常是缺少azure.azcollection集合(azure_rm插件属于该集合),或者集合未正确加载。
解决步骤
安装azure.azcollection集合
执行以下命令安装官方Azure集合:ansible-galaxy collection install azure.azcollection同时安装依赖的Python SDK包:
pip install azure-core azure-mgmt-compute azure-mgmt-network azure-mgmt-resource azure-mgmt-storage验证CLI认证有效性
你的inventory配置使用auth_source: cli,确保Azure CLI已正确登录并有权限访问目标资源组:az account show如果未登录,执行
az login完成认证。重新测试inventory解析
再次运行原命令验证:ansible-inventory -i inventory_azure_rm.yml --graph -vv额外检查(若问题仍存在)
- 确认ansible.cfg中未错误限制inventory插件路径,默认安装集合后插件会被自动识别;
- 检查inventory文件的缩进是否符合YAML规范(你的当前配置缩进是正确的,但可再次确认);
- 若使用的Ansible版本过低(如2.12.x),尝试升级到较新版本(如2.15+)以获得更好的兼容性。
内容的提问来源于stack exchange,提问作者N Hunt
相关产品推荐
相关产品推荐

