据我所知,使用ansible-inventory-plugins而不是dynamic-inventory-provisioners是一种处理动态主机的新方法,比如云提供商等等。
所以,首先我已经在我的环境中设置了azure凭证:
± env | grep AZ
AZURE_SECRET=asdf
AZURE_TENANT=asdf
AZURE_SUBSCRIPTION_ID=asdf
AZURE_CLIENT_ID=asdf接下来,我编写了一个包含以下内容的ansible.cfg:
± cat ansible.cfg
[inventory]
enable_plugins = azure_rm最后,我使用ansible inventory plugin页面中所示的最小设置编写了yaml文件:
± cat foo.azure_rm.yaml
---
plugin: azure_rm当我在该文件上运行ansible-inventory二进制文件时,我得到:
± ansible-inventory -i foo.azure_rm.yaml --list
[WARNING]: * Failed to parse /path/to/foo.azure_rm.yaml with azure_rm plugin: Unicode-objects must be encoded before hashing
[WARNING]: Unable to parse /path/to/foo.azure_rm.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
"_meta": {
"hostvars": {}
},
"all": {
"children": [
"ungrouped"
]
},
"ungrouped": {}
}总结:主要的问题似乎是线路:
[WARNING]: * Failed to parse /path/to/foo.azure_rm.yaml with azure_rm plugin: Unicode-objects must be encoded before hashing帮帮忙,有人吗?
发布于 2019-04-10 03:57:04
我已经在github fork中修复了它,并使用pipenv将此版本包含在我的环境中。实际上,它应该是devel的一个备份端口,那里的问题已经解决了。也许我会在接下来的几天里解决这个问题,在ansible做一个公关,把它包含到稳定的2.7中,但也许更好的选择是等到5月份的2.8。
发布于 2019-02-19 23:39:14
我认为这是脚本中的一个错误。将调试标志添加到Ansible会给出以下堆栈跟踪:
File "/usr/local/lib/python3.6/site-packages/ansible/inventory/manager.py", line 273, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/local/lib/python3.6/site-packages/ansible/plugins/inventory/azure_rm.py", line 235, in parse
self._get_hosts()
File "/usr/local/lib/python3.6/site-packages/ansible/plugins/inventory/azure_rm.py", line 292, in _get_hosts
self._process_queue_batch()
File "/usr/local/lib/python3.6/site-packages/ansible/plugins/inventory/azure_rm.py", line 412, in _process_queue_batch
result.handler(r['content'], **result.handler_args)
File "/usr/local/lib/python3.6/site-packages/ansible/plugins/inventory/azure_rm.py", line 357, in _on_vm_page_response
self._hosts.append(AzureHost(h, self, vmss=vmss))
File "/usr/local/lib/python3.6/site-packages/ansible/plugins/inventory/azure_rm.py", line 466, in __init__
self.default_inventory_hostname = '{0}_{1}'.format(vm_model['name'], hashlib.sha1(vm_model['id']).hexdigest()[0:4])这似乎是最近才修复的:https://github.com/ansible/ansible/pull/46608。所以你要么等到2.8版本,要么使用开发版本。
发布于 2020-04-16 16:08:25
我也遇到过同样的问题,并通过使用python3解决了它
您可以使用以下命令检查您的ansible python版本
ansible --version | grep "python version"
python version = 2.7.17 (default, Nov 7 2019, 10:07:09) [GCC 7.4.0]安装所有python3包
pip3 install ansible azure azure-cli如果需要,导出用于身份验证的环境变量
export ANSIBLE_AZURE_AUTH_SOURCE=cli然后运行ansible inventory
python3 $(which ansible-inventory) -i my.azure_rm.yaml --graphmy.azure_rm.yml文件如下所示:
plugin: azure_rm
include_vm_resource_groups:
- my_resource_group_rg
auth_source: clihttps://stackoverflow.com/questions/54478989
复制相似问题