Hi all,
I was looking for some help debugging an unusual issue I’m seeing with azure.azcollection and the azure-cli in an Ansible execution environment.
TL;DR, if I manually build a container, pip install ansible-core, ansible-galaxy install the azure.azcollection, then pip install its requirements, install azure-cli, setup a dynamic inventory plugin, az login and then run ansible-inventory, everything works.
If I use ansible-builder to accomplish the same end result, ansible-inventory fails with the following stack trace:
[root@3209917451f4 runner]# ansible-inventory -i inventory/azure_rm.yml --graph
[WARNING]: * Failed to parse /runner/inventory/azure_rm.yml with auto plugin: Failed to get credentials. Either pass as parameters, set environment variables, define a profile in ~/.azure/credentials, or install Azure CLI and log in (az login
).
[WARNING]: * Failed to parse /runner/inventory/azure_rm.yml with ini plugin: Invalid host pattern ‘plugin:’ supplied, ending in ‘:’ is not allowed, this character is reserved to provide a port.
[WARNING]: Unable to parse /runner/inventory/azure_rm.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
@all:
–@ungrouped:
[root@3209917451f4 runner]# ansible-inventory -vvv -i inventory/azure_rm.yml --graph
ansible-inventory [core 2.15.2]
config file = /runner/project/ansible.cfg
configured module search path = [‘/root/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-inventory
python version = 3.11.4 (main, Jun 7 2023, 00:00:00) [GCC 13.1.1 20230511 (Red Hat 13.1.1-2)] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
Using /runner/project/ansible.cfg as config file
Using inventory plugin ‘ansible_collections.azure.azcollection.plugins.inventory.azure_rm’ to process inventory source ‘/runner/inventory/azure_rm.yml’
[WARNING]: * Failed to parse /runner/inventory/azure_rm.yml with auto plugin: Failed to get credentials. Either pass as parameters, set environment variables, define a profile in ~/.azure/credentials, or install Azure CLI and log in (az login
).
File “/usr/local/lib/python3.11/site-packages/ansible/inventory/manager.py”, line 293, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File “/usr/local/lib/python3.11/site-packages/ansible/plugins/inventory/auto.py”, line 59, in parse
plugin.parse(inventory, loader, path, cache=cache)
File “/usr/share/ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py”, line 221, in parse
self._credential_setup()
File “/usr/share/ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py”, line 242, in _credential_setup
self.azure_auth = AzureRMAuth(**auth_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/share/ansible/collections/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py”, line 1514, in init
self.fail("Failed to get credentials. Either pass as parameters, set environment variables, "
File “/usr/share/ansible/collections/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py”, line 1640, in fail
self._fail_impl(msg)
File “/usr/share/ansible/collections/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py”, line 1643, in _default_fail_impl
raise AzureRMAuthException(msg)
[WARNING]: * Failed to parse /runner/inventory/azure_rm.yml with ini plugin: Invalid host pattern ‘plugin:’ supplied, ending in ‘:’ is not allowed, this character is reserved to provide a port.
File “/usr/local/lib/python3.11/site-packages/ansible/inventory/manager.py”, line 293, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File “/usr/local/lib/python3.11/site-packages/ansible/plugins/inventory/ini.py”, line 137, in parse
raise AnsibleParserError(e)
[WARNING]: Unable to parse /runner/inventory/azure_rm.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
@all:
–@ungrouped:
This is in a running instance of the ansible-builder built container, az login has successfully run, I can az account show/az vm list and see the subscription, tennant ID, resources etc.
I’ve done all the usual Googling and as much RTFMing as I can but haven’t found anything that would explain the difference in behaviour. More debug info below from the non-working ansible-builder container in case it helps. The behaviour persists whether podman or docker is used for the build. The only thing that seems obviously different between the two scenarios is that ansible-builder is building the EE with dumb-init?
Any suggestions are greatly appreciated.
Cheers,
Will.