azure_rm Ansible 插件无法解析动态清单

Jos*_*los 2 yaml azure ansible

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

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:
Run Code Online (Sandbox Code Playgroud)

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: ""
Run Code Online (Sandbox Code Playgroud)

ansible.cfg文件是:

[defaults]
inventory = inventory_azure_rm.yaml

[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml
Run Code Online (Sandbox Code Playgroud)

Ansible Azure 集合版本

bash-5.1# ansible-galaxy collection list

# /root/.ansible/collections/ansible_collections
Collection         Version
------------------ -------
azure.azcollection 1.11.0
Run Code Online (Sandbox Code Playgroud)

对于尝试解决此问题的任何帮助,我将不胜感激。谢谢。


更新:

  • 固定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
    
    Run Code Online (Sandbox Code Playgroud)
  • 更新了再次运行命令的问题描述的错误堆栈跟踪。

更新2:

Azurecredentials文件如下所示:

bash-5.1# cat ~/.azure/credentials
[default]
subscription_id=<redacted>
client_id=<redacted>
secret=<redacted>
tenant=<redacted>
cloud_environment=AzureCloud
Run Code Online (Sandbox Code Playgroud)

Jos*_*los 6

我终于设法解决了解析动态库存的问题。我正在做以下事情:

pip install -r https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt && \
ansible-galaxy collection install azure.azcollection:1.11.0
Run Code Online (Sandbox Code Playgroud)

我改变了两件事:

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

这是工作代码:

ansible-galaxy collection install azure.azcollection:1.11.0 && \
pip install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt 
Run Code Online (Sandbox Code Playgroud)

requirements.txtGitHub at 的文件https://raw.githubusercontent.com/ansible-collections/azure/dev/requirements-azure.txt与本地requirements.txt文件 at的区别~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt在于azure-mgmt-network包版本。在线版本是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
Run Code Online (Sandbox Code Playgroud)