gpt4 book ai didi

azure - azure 的 Ansible 库存插件抛出编码错误

转载 作者:行者123 更新时间:2023-12-02 08:01:55 24 4
gpt4 key购买 nike

据我了解,使用 ansible-inventory-plugins 而不是动态库存-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

最后,我使用最小设置编写了 yaml 文件,如 ansible inventory plugin 所示。页面:

± 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

有人帮忙吗?

最佳答案

我认为这是脚本中的错误。将调试标志添加到 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,要么使用开发版本。

关于azure - azure 的 Ansible 库存插件抛出编码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54478989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com