Skip to content

v3.9.0 breaks inventory plugin #2074

@TiTi

Description

@TiTi
SUMMARY

After upgrading from 3.8.0 to 3.9.0, we have errors during processing of dynamic inventory and thus end up with:
ERROR! Specified inventory, host pattern and/or --limit leaves us with no hosts to target.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

plugins/inventory/azure_rm.py
3.9.0 only change is #2055

ANSIBLE VERSION
ansible-playbook [core 2.18.7]
  config file = /agent/_work/2/s/ansible-windows/ansible.cfg
  configured module search path = ['/home/AzDevOps/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/venv/lib/python3.12/site-packages/ansible
  ansible collection location = /home/AzDevOps/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/venv/bin/ansible-playbook
  python version = 3.12.11 (main, Jun  4 2025, 08:56:18) [GCC 11.4.0] (/usr/venv/bin/python3.12)
  jinja version = 3.1.6
  libyaml = True
COLLECTION VERSION
# /home/AzDevOps/.ansible/collections/ansible_collections
Collection                               Version
---------------------------------------- -------
azure.azcollection                       3.9.0  

# /usr/venv/lib/python3.12/site-packages/ansible_collections
Collection                               Version
---------------------------------------- -------
azure.azcollection                       3.6.0  
CONFIGURATION
N/A
OS / ENVIRONMENT

Python 3.12

STEPS TO REPRODUCE
  • Have a dynamic azure inventory
  • Execute a simple playbook
ansible-playbook -i "inventories/infra1/europe/" --diff --limit "vm1" --tags all --skip-tags none -vvv  ping.yml

In our case, we also use Azure Stack HCI objects. Maybe it's related, maybe not, i don't know at this point.
Here is our europe.prd.inventory.azure_rm.yml

---

plugin: azure.azcollection.azure_rm
auth_source: auto
include_vm_resource_groups: []
include_hcivm_resource_groups:
  - "*"
subscription_id: xxxxxxxxxxxxx
plain_host_names: true
default_host_filters:
  - powerstate != 'running'
  - provisioning_state != 'succeeded'
hostvar_expressions:
  ansible_host: (private_ipv4_addresses | first) if os_disk.operating_system_type == 'linux' else computer_name | default(name, true)
conditional_groups:
  windows: os_disk.operating_system_type == 'windows'
  linux: os_disk.operating_system_type == 'linux'
  hci: true
  europe: true
keyed_groups:
  # places each host in a group named 'tag_(tag name)_(tag value)' for each tag on a VM.
  - prefix: tag
    key: tags
  - prefix: geo
    key: customLocation | default(location)

Please note presence of include_hcivm_resource_groups (which i helped develop in a previous PR).

EXPECTED RESULTS

Inventory should be parsed without errors

ACTUAL RESULTS

Exception in compute_client.virtual_machines.instance_view

  File "/usr/venv/lib/python3.12/site-packages/ansible/inventory/manager.py", line 292, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/venv/lib/python3.12/site-packages/ansible/plugins/inventory/auto.py", line 58, in parse
    plugin.parse(inventory, loader, path, cache=cache)
  File "/home/AzDevOps/.ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 292, in parse
    results = self._serialize(self._hosts)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/AzDevOps/.ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 304, in _serialize
    hostvars=h.hostvars))
             ^^^^^^^^^^
  File "/home/AzDevOps/.ansible/collections/ansible_collections/azure/azcollection/plugins/inventory/azure_rm.py", line 938, in hostvars
    instance_view = compute_client.virtual_machines.instance_view(new_hostvars['resource_group'], new_hostvars['name'])
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/venv/lib/python3.12/site-packages/azure/core/tracing/decorator.py", line 94, in wrapper_use_tracer
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/venv/lib/python3.12/site-packages/azure/mgmt/compute/v2024_07_01/operations/_operations.py", line 16047, in instance_view
    map_error(status_code=response.status_code, response=response, error_map=error_map)
  File "/usr/venv/lib/python3.12/site-packages/azure/core/exceptions.py", line 161, in map_error
    raise error
  File "/usr/venv/lib/python3.12/site-packages/ansible/inventory/manager.py", line 292, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/venv/lib/python3.12/site-packages/ansible/plugins/inventory/yaml.py", line 113, in parse
    raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
  File "/usr/venv/lib/python3.12/site-packages/ansible/inventory/manager.py", line 292, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/venv/lib/python3.12/site-packages/ansible/plugins/inventory/ini.py", line 137, in parse
    raise AnsibleParserError(e)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghas_prPR fixes have been madehigh_priorityHigh prioritywork inIn trying to solve, or in working with contributors

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions