尝试使用Azure的Ansible动态资源清册插件时出错

尝试使用Azure的Ansible动态资源清册插件时出错,azure,ansible,Azure,Ansible,我正在尝试使用Ansible的azure_rm插件为azure中的VM生成动态资源清册,但在尝试运行健全性检查命令时收到403的“批处理请求”错误: $ ansible all -m ping [WARNING]: * Failed to parse /project/ansible/inventory.azure_rm.yml with ansible_collections.azure.azcollection.plugins.inventory.azure_rm plugin: a b

我正在尝试使用Ansible的azure_rm插件为azure中的VM生成动态资源清册,但在尝试运行健全性检查命令时收到403的“批处理请求”错误:

$ ansible all -m ping 
[WARNING]:  * Failed to parse /project/ansible/inventory.azure_rm.yml with
ansible_collections.azure.azcollection.plugins.inventory.azure_rm plugin: a batched request failed with status code 403, url
/subscriptions/<redacted>/resourceGroups/<redacted>/providers/Microsoft.Compute/virtualMachines
...
这是inventory.azure_rm.yml文件:

plugin: azure_rm
include_vm_resource_groups:
- <redacted>
auth_source: auto

keyed_groups:
- prefix: tag
  key: tags
我还将Azure身份验证的细节定义为环境变量:

$ env | grep AZURE
AZURE_TENANT=<redacted>
AZURE_CLIENT_ID=<redacted>
AZURE_USE_PRIVATE_IP=yes
AZURE_SECRET=<redacted>
AZURE_SUBSCRIPTION_ID=<redacted>
$env| grep AZURE
AZURE_租户=
AZURE\u客户端\u ID=
AZURE\u使用\u私有\u IP=是
天蓝色的秘密=
AZURE\u订阅\u ID=
这些“凭证”与我在Terraform中创建虚拟机时使用的“凭证”相同,我现在正尝试动态清点这些虚拟机,因此它们应该是好的。因此,对于403错误背后的原因有点茫然

然后,我在命令中添加了-vvv选项,并获得了一些附加信息:

$ ansible all -m ping -vvvv
ansible 2.10.3
  config file = /Users/me/project/ansible/ansible.cfg
  configured module search path = ['/Users/me/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.10.3_1/libexec/lib/python3.9/site-packages/ansible
  executable location = /usr/local/Cellar/ansible/2.10.3_1/libexec/bin/ansible
  python version = 3.9.0 (default, Dec  6 2020, 18:02:34) [Clang 12.0.0 (clang-1200.0.32.27)]
Using /Users/me/project/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /Users/me/project/ansible/inventory.azure_rm.yml as it did not pass its verify_file() method
script declined parsing /Users/me/project/ansible/inventory.azure_rm.yml as it did not pass its verify_file() method
redirecting (type: inventory) ansible.builtin.azure_rm to azure.azcollection.azure_rm
Loading collection azure.azcollection from /Users/me/.ansible/collections/ansible_collections/azure/azcollection
toml declined parsing /Users/me/project/ansible/inventory.azure_rm.yml as it did not pass its verify_file() method
[WARNING]:  * Failed to parse /Users/me/project/ansible/inventory.azure_rm.yml with
ansible_collections.azure.azcollection.plugins.inventory.azure_rm  plugin: a batched request failed with status code 403, url
/subscriptions/<redacted>/resourceGroups/<redacted>/providers/Microsoft.Compute/virtualMachines
  File "/usr/local/Cellar/ansible/2.10.3_1/libexec/lib/python3.9/site-packages/ansible/inventory/manager.py", line 289, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/local/Cellar/ansible/2.10.3_1/libexec/lib/python3.9/site-packages/ansible/plugins/inventory/auto.py", line 59, in parse
    plugin.parse(inventory, loader, path, cache=cache)
  File "/Users/me/.ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 206, in parse
    self._get_hosts()
  File "/Users/me/.ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 263, in _get_hosts
    self._process_queue_batch()
  File "/Users/me/.ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 405, in _process_queue_batch
    raise AnsibleError("a batched request failed with status code {0}, url {1}".format(status_code, result.url))
$ansible all-m ping-vv
表2.10.3
配置文件=/Users/me/project/ansible/ansible.cfg
配置的模块搜索路径=['/Users/me/.ansible/plugins/modules','/usr/share/ansible/plugins/modules']
ansible python模块位置=/usr/local/ceral/ansible/2.10.3_1/libexec/lib/python3.9/site-packages/ansible
可执行文件位置=/usr/local/ceral/ansible/2.10.3_1/libexec/bin/ansible
python版本=3.9.0(默认值,2020年12月6日,18:02:34)[Clang 12.0.0(Clang-1200.0.32.27)]
使用/Users/me/project/ansible/ansible.cfg作为配置文件
设置目录插件
主机列表拒绝解析/Users/me/project/ansible/inventory.azure\u rm.yml,因为它没有通过其verify\u file()方法
脚本拒绝解析/Users/me/project/ansible/inventory.azure\u rm.yml,因为它没有通过其verify\u file()方法
正在将(类型:库存)ansible.builtin.azure\u rm重定向到azure.azcollection.azure\u rm
正在从/Users/me/.ansible/collections/ansible\u collections/azure/azcollection加载集合azure.azcollection
toml拒绝解析/Users/me/project/ansible/inventory.azure\u rm.yml,因为它没有通过其verify\u file()方法
[警告]:*无法使用解析/Users/me/project/ansible/inventory.azure_rm.yml
ansible_collections.azure.azcollection.plugins.inventory.azure_rm插件:批处理请求失败,状态代码403,url
/订阅//资源组//提供者/Microsoft.Compute/virtualMachines
文件“/usr/local/cillar/ansible/2.10.3_1/libexec/lib/python3.9/site packages/ansible/inventory/manager.py”,第289行,在parse_source中
解析(self.\u目录,self.\u加载器,源,cache=cache)
文件“/usr/local/Cellar/ansible/2.10.3_1/libexec/lib/python3.9/site packages/ansible/plugins/inventory/auto.py”,第59行,解析
parse(清单、加载程序、路径、缓存=缓存)
解析中第206行的文件“/Users/me/.ansible/collections/ansible\u collections/azure/azcollection/plugins/inventory/azure\u rm.py”
self.\u获取\u主机()
文件“/Users/me/.ansible/collections/ansible\u collections/azure/azcollection/plugins/inventory/azure\u rm.py”,第263行,位于主机中
self.\u进程\u队列\u批处理()
文件“/Users/me/.ansible/collections/ansible\u collections/azure/azcollection/plugins/inventory/azure\u rm.py”,第405行,在批处理队列中
raise AnsibleError(“批处理请求失败,状态代码为{0},url为{1}”)。格式(状态代码,result.url))

以前有没有人遇到过这个问题并找到了解决办法?我假设我使用的服务主体缺少某些角色或权限,但我不知道它被赋予了什么,因为同一个SP首先用于配置VM。

添加集合以获取最新版本,然后尝试以下操作:

插件:azure.azcollection.azure\u rm


这将确保您使用的是最新版本,而不是内置版本,该版本不包含错误修复并支持较新的api版本。

添加集合以获取最新版本,然后尝试以下操作:

插件:azure.azcollection.azure\u rm


这将确保您使用的是最新版本,而不是内置版本,该版本不会包含错误修复并支持较新的api版本。

至少简要解释一下。这是怎么一回事?如何使用它?使用它的好处等等……至少简单地解释一下。这是怎么一回事?如何使用它?使用它的好处等等…你有没有找到原因?你有没有找到原因?
$ env | grep AZURE
AZURE_TENANT=<redacted>
AZURE_CLIENT_ID=<redacted>
AZURE_USE_PRIVATE_IP=yes
AZURE_SECRET=<redacted>
AZURE_SUBSCRIPTION_ID=<redacted>
$ ansible all -m ping -vvvv
ansible 2.10.3
  config file = /Users/me/project/ansible/ansible.cfg
  configured module search path = ['/Users/me/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.10.3_1/libexec/lib/python3.9/site-packages/ansible
  executable location = /usr/local/Cellar/ansible/2.10.3_1/libexec/bin/ansible
  python version = 3.9.0 (default, Dec  6 2020, 18:02:34) [Clang 12.0.0 (clang-1200.0.32.27)]
Using /Users/me/project/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /Users/me/project/ansible/inventory.azure_rm.yml as it did not pass its verify_file() method
script declined parsing /Users/me/project/ansible/inventory.azure_rm.yml as it did not pass its verify_file() method
redirecting (type: inventory) ansible.builtin.azure_rm to azure.azcollection.azure_rm
Loading collection azure.azcollection from /Users/me/.ansible/collections/ansible_collections/azure/azcollection
toml declined parsing /Users/me/project/ansible/inventory.azure_rm.yml as it did not pass its verify_file() method
[WARNING]:  * Failed to parse /Users/me/project/ansible/inventory.azure_rm.yml with
ansible_collections.azure.azcollection.plugins.inventory.azure_rm  plugin: a batched request failed with status code 403, url
/subscriptions/<redacted>/resourceGroups/<redacted>/providers/Microsoft.Compute/virtualMachines
  File "/usr/local/Cellar/ansible/2.10.3_1/libexec/lib/python3.9/site-packages/ansible/inventory/manager.py", line 289, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/local/Cellar/ansible/2.10.3_1/libexec/lib/python3.9/site-packages/ansible/plugins/inventory/auto.py", line 59, in parse
    plugin.parse(inventory, loader, path, cache=cache)
  File "/Users/me/.ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 206, in parse
    self._get_hosts()
  File "/Users/me/.ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 263, in _get_hosts
    self._process_queue_batch()
  File "/Users/me/.ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 405, in _process_queue_batch
    raise AnsibleError("a batched request failed with status code {0}, url {1}".format(status_code, result.url))