I'm unable to create an Ansible dynamic inventory for Azure. I get the following error:
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:
The inventory_azure_rm.yaml file is:
plugin: azure.azcollection.azure_rm
auth_source: credential_file
plain_host_names: yes
include_vm_resource_groups:
- <redacted>
keyed_groups:
- key: tags.applicationRole
separator: ""
The ansible.cfg file is:
[defaults]
inventory = inventory_azure_rm.yaml
[inventory]
enable_plugins = host_list, script, auto, yaml, ini, toml
Ansible Azure collection version
bash-5.1# ansible-galaxy collection list
# /root/.ansible/collections/ansible_collections
Collection Version
------------------ -------
azure.azcollection 1.11.0
I would appreciate any help on trying to solve this. Thank you.
Update:
- Fixed
inventory_azure_rm.yamlfile permissions.bash-5.1# ls -la inventory_azure_rm.yaml -rw-r--r-- 1 root root 200 Feb 24 17:27 inventory_azure_rm.yaml - Updated the error stacktrace on the problem description running the command again.
Update2:
The Azure credentials file looks like this:
bash-5.1# cat ~/.azure/credentials
[default]
subscription_id=<redacted>
client_id=<redacted>
secret=<redacted>
tenant=<redacted>
cloud_environment=AzureCloud