gpt4 book ai didi

azure_rm Ansible 插件无法解析动态 list

转载 作者:行者123 更新时间:2023-12-01 23:04:14 26 4
gpt4 key购买 nike

我无法为 Azure 创建 Ansible 动态 list 。我收到以下错误:

bash-5.1# ansible-inventory -i inventory_azure_rm.yaml --graph -vvv
ansible-inventory [core 2.12.2]
config file = /playbook/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible-inventory
python version = 3.9.7 (default, Nov 24 2021, 21:15:59) [GCC 10.3.1 20211027]
jinja version = 3.0.3
libyaml = False
Using /playbook/ansible.cfg as config file
host_list declined parsing /playbook/inventory_azure_rm.yaml as it did not pass its verify_file() method
toml declined parsing /playbook/inventory_azure_rm.yaml as it did not pass its verify_file() method
[WARNING]: * Failed to parse /playbook/inventory_azure_rm.yaml with script plugin: problem running /playbook/inventory_azure_rm.yaml --list ([Errno 13] Permission denied:
'/playbook/inventory_azure_rm.yaml')
File "/usr/lib/python3.9/site-packages/ansible/inventory/manager.py", line 290, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/lib/python3.9/site-packages/ansible/plugins/inventory/script.py", line 150, in parse
raise AnsibleParserError(to_native(e))
[WARNING]: * Failed to parse /playbook/inventory_azure_rm.yaml with auto plugin: name 'client_secret' is not defined
File "/usr/lib/python3.9/site-packages/ansible/inventory/manager.py", line 290, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/lib/python3.9/site-packages/ansible/plugins/inventory/auto.py", line 58, in parse
plugin.parse(inventory, loader, path, cache=cache)
File "/root/.ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 219, in parse
self._credential_setup()
File "/root/.ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 240, in _credential_setup
self.azure_auth = AzureRMAuth(**auth_options)
File "/root/.ansible/collections/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 1522, in __init__
self.azure_credential_track2 = client_secret.ClientSecretCredential(client_id=self.credentials['client_id'],
[WARNING]: * Failed to parse /playbook/inventory_azure_rm.yaml with yaml plugin: Plugin configuration YAML file, not YAML inventory
File "/usr/lib/python3.9/site-packages/ansible/inventory/manager.py", line 290, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/lib/python3.9/site-packages/ansible/plugins/inventory/yaml.py", line 112, in parse
raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
[WARNING]: * Failed to parse /playbook/inventory_azure_rm.yaml with ini plugin: Invalid host pattern 'plugin:' supplied, ending in ':' is not allowed, this character is reserved to provide a port.
File "/usr/lib/python3.9/site-packages/ansible/inventory/manager.py", line 290, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/usr/lib/python3.9/site-packages/ansible/plugins/inventory/ini.py", line 136, in parse
raise AnsibleParserError(e)
[WARNING]: Unable to parse /playbook/inventory_azure_rm.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
@all:
|--@ungrouped:

inventory_azure_rm.yaml 文件是:

plugin: azure.azcollection.azure_rm
auth_source: credential_file
plain_host_names: yes
include_vm_resource_groups:
- <redacted>
keyed_groups:
- key: tags.applicationRole
separator: ""

ansible.cfg 文件是:

[defaults]
inventory = inventory_azure_rm.yaml

[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml

Ansible Azure 集合版本

bash-5.1# ansible-galaxy collection list

# /root/.ansible/collections/ansible_collections
Collection Version
------------------ -------
azure.azcollection 1.11.0

如果您能帮助我解决这个问题,我将不胜感激。谢谢。

<小时/>

更新:

  • 修复了 inventory_azure_rm.yaml 文件权限。
    bash-5.1# ls -la inventory_azure_rm.yaml
    -rw-r--r-- 1 root root 200 Feb 24 17:27 inventory_azure_rm.yaml
  • 更新了再次运行命令的问题描述的错误堆栈跟踪。
<小时/>

更新2:

Azure credentials 文件如下所示:

bash-5.1# cat ~/.azure/credentials
[default]
subscription_id=<redacted>
client_id=<redacted>
secret=<redacted>
tenant=<redacted>
cloud_environment=AzureCloud

最佳答案

我终于成功解决了解析动态库存的问题。我正在执行以下操作:

pip install -r https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt && \
ansible-galaxy collection install azure.azcollection:1.11.0

我改变了两件事:

  • 颠倒安装集合及其依赖项的顺序。首先,我需要安装 azure.azcollection,然后安装它的依赖项。
  • 从集合本身附带的 requirements.txt 安装 azure.azcollection 依赖项,而不是从 Github 进行安装。

这是有效的代码:

ansible-galaxy collection install azure.azcollection:1.11.0 && \
pip install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt

来自 GitHub 的 requirements.txt 文件之间的区别:https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt 位于 ~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt 的本地 requirements.txt 文件位于 azure-mgmt-网络包版本。在线版本为 19.1.0,本地(工作)版本为 12.0.0

bash-5.1# diff -w requirements-azure.txt ~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt
--- requirements-azure.txt
+++ /root/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt
@@ -19,7 +19,7 @@
azure-mgmt-monitor==3.0.0
azure-mgmt-managedservices==1.0.0
azure-mgmt-managementgroups==0.2.0
-azure-mgmt-network==19.1.0
+azure-mgmt-network==12.0.0
azure-mgmt-nspkg==2.0.0
azure-mgmt-privatedns==0.1.0
azure-mgmt-redis==5.0.0

关于azure_rm Ansible 插件无法解析动态 list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71256239/

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