Ansible基于Proxmox构建动态库存遇解析错误求助
Proxmox生成Ansible动态库存报错问题
我在尝试用Proxmox生成Ansible动态库存时遇到问题,创建的inventory.proxmox.yml配置文件内容如下:
plugin: community.general.proxmox url: https://MyIP:8006 user: ansible@pve password: my_password validate_certs: false want_proxmox_nodes_ansible_host: false
执行命令 ansible-inventory -i inventory.proxmox.yml --list 后出现以下错误:
/usr/lib/python3/dist-packages/urllib3/connectionpool.py:1015: InsecureRequestWarning: Unverified HTTPS request is being made to host 'myIP'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings warnings.warn( [WARNING]: * Failed to parse /home/user/ansible/inventory/inventory.proxmox.yml with auto plugin: 'NoneType' object is not subscriptable [WARNING]: * Failed to parse /home/user/ansible/inventory/inventory.proxmox.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory [WARNING]: * Failed to parse /home/user/ansible/inventory/inventory.proxmox.yml with ini plugin: Invalid host pattern 'plugin:' supplied, ending in ':' is not allowed, this character is reserved to provide a port. [WARNING]: * Failed to parse /home/user/ansible/inventory/inventory.proxmox.yml with ansible_collections.community.general.plugins.inventory.proxmox plugin: 'NoneType' object is not subscriptable [WARNING]: Unable to parse /home/user/ansible/inventory/inventory.proxmox.yml as an inventory source [WARNING]: No inventory was parsed, only implicit localhost is available
把配置文件里的url改成http能消除HTTPS警告,但Proxmox并没有监听HTTP端口。
解决方法
1. 修复'NoneType' object is not subscriptable错误
- 检查用户权限:确保
ansible@pve用户拥有Proxmox API的访问权限,至少需要查看节点和虚拟机的权限。在Proxmox web界面的数据中心 > 权限 > 用户中,给该用户分配PVEAuditor角色,或者自定义包含API读取权限的角色。 - 验证配置参数:确认
url中的IP地址正确无误;如果密码包含特殊字符(如!、@、#),需要用双引号包裹,比如password: "my_password"。 - 更新插件版本:旧版
community.general插件可能存在bug,执行命令更新插件:ansible-galaxy collection install community.general --upgrade
2. 消除HTTPS警告(不切换到HTTP)
Proxmox默认仅启用HTTPS,不要改用HTTP,可通过导入自签名证书解决警告:
- 从Proxmox节点导出证书:
openssl s_client -connect MyIP:8006 < /dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > proxmox.crt - 将证书复制到Ansible控制节点的系统信任目录(以Debian/Ubuntu为例):
sudo cp proxmox.crt /usr/local/share/ca-certificates/ sudo update-ca-certificates - 修改
inventory.proxmox.yml中的参数:validate_certs: true
内容的提问来源于stack exchange,提问作者twet
相关产品推荐
相关产品推荐

