gpt4 book ai didi

Azure ansible - 动态 list 不起作用

转载 作者:行者123 更新时间:2023-12-02 06:56:57 25 4
gpt4 key购买 nike

我已经配置了凭据,并且可以运行 playbook 来创建虚拟机。但我无法使用动态库存插件列出库存。我在同一目录中有 azure_rm.py

azure_rm.yml

plugin: azure_rm
include_vm_resource_groups:
- readit-app-rg
auth_source: auto

ansible-inventory -vvvv -i myazure_rm.yml --list

ansible-inventory [core 2.11.2] 
config file = /home/ansible/azure_ansible/ansible.cfg
configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-inventory
python version = 3.8.5 (default, May 27 2021, 13:30:53) [GCC 9.3.0]
jinja version = 3.0.1
libyaml = True
Using /home/ansible/azure_ansible/ansible.cfg as config file
setting up inventory plugins
redirecting (type: inventory) ansible.builtin.azure_rm to azure.azcollection.azure_rm
Loading collection azure.azcollection from /usr/local/lib/python3.8/dist-packages/ansible_collections/azure/azcollection
[WARNING]: Failed to load inventory plugin, skipping yml
Skipping due to inventory source not existing or not being readable by the current user
ansible_collections.azure.azcollection.plugins.inventory.azure_rm declined parsing /home/ansible/azure_ansible/myazure_rm.yml as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /home/ansible/azure_ansible/myazure_rm.yml as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /home/ansible/azure_ansible/myazure_rm.yml as it did not pass its verify_file() method
[WARNING]: Unable to parse /home/ansible/azure_ansible/myazure_rm.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
"_meta": {
"hostvars": {}
},
"all": {
"children": [
"ungrouped"
]
}
}

最佳答案

解决了问题。有几个问题。

问题 1:

[警告]:无法加载库存插件,跳过 yml

删除 [inventory] 并将其更改为 ansible.cfg 中的 [defaults] 后得到解决

[defaults]
inventory = test.azure_rm.yml
enable_plugins = host_list, script, auto, yaml, yml, ini, azure_rm

问题 2:(不确定这是否是一个问题,但我读到文件名应以 .azure.rm.yml

结尾

将文件从 myazure_rm.yml 重命名为 test.azure_rm.yml

问题 3:

当我们使用命令 ansible-inventory -vvvv -i test.azure_rm.yml --list 列出 list 时,仅显示使用 Ansible playbook 创建的虚拟机。

在AWS中,我们有ec2.py,它列出了AWS控制台中的所有虚拟机。但在 Azure 中,我手动创建了很少的虚拟机,并且脚本返回空列表。在我运行剧本并创建了几个虚拟机后,脚本仅返回由 Ansible 创建的虚拟机。

注意:凭据应存储在 ~/.azure/credentials 中或使用 az login

关于Azure ansible - 动态 list 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69642975/

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