Vmware inventory source error "guest.hostName: 'guest' is undefined."

hello

i recently updated AWX to 23.5.1
Ansible-core 2.16.4 and with these collections:
community.general version: 7.0.0
community.mysql version: 3.3.0
ansible.posix version: 1.4.0
community.vmware version: 2.7.0

python 3.11.7
jinja 3.1.3

I have an inventory with 3 vmware inventory sources with the same variables. 2 of them work but the 3rd gives me the following error:

Using inventory plugin 'ansible_collections.community.vmware.plugins.inventory.vmware_vm_inventory' to process inventory source '/runner/inventory/vmware_vm_inventory.yml'
[WARNING]: * Failed to parse /runner/inventory/vmware_vm_inventory.yml with
auto plugin: Could not template any hostname for host, errors for each
preference: guest.hostName: 'guest' is undefined. 'guest' is undefined
   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/community/vmware/plugins/inventory/vmware_vm_inventory.py", line 680, in parse
     cacheable_results = self._populate_from_source()
                         ^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/usr/share/ansible/collections/ansible_collections/community/vmware/plugins/inventory/vmware_vm_inventory.py", line 791, in _populate_from_source
     host = self._get_hostname(host_properties, hostnames, strict=strict)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^
   File "/usr/share/ansible/collections/ansible_collections/community/vmware/plugins/inventory/vmware_vm_inventory.py", line 816, in _get_hostname
     raise AnsibleError(
[WARNING]: Unable to parse /runner/inventory/vmware_vm_inventory.yml as an
inventory source
ERROR! No inventory was parsed, please check your configuration and options.

here is the source configuration that does not work:

---
groupby_custom_field: True
strict: False
with_tags: True
hostnames:
   - 'guest.hostName'
compound:
   ansible_host:guest.hostName
properties:
- 'name'
- 'config.name'
- 'config.uuid'
- 'guest.ipAddress'
- 'summary.runtime.powerState'
- 'guest.guestFamily'
- 'config.template'
- 'config.guestId'
- 'config.annotation'
- 'guest.hostName'
keyed_groups:
- key: 'config.annotation.split("_")[1].split(" ")[0]'
   prefix: "moodle"
   separator: ""
with_nested_properties: True
filters:
- 'config.annotation is defined and config.annotation.startswith("Moodle_") and not config.template'

I don’t know why it doesn’t work for this source when it worked fine before the update

here is one of the sources that works (only the filter changes):

---
groupby_custom_field: True
strict: False
with_tags: True
hostnames:
   - 'guest.hostName'
compound:
   ansible_host:guest.hostName
properties:
- 'name'
- 'config.name'
- 'guest.ipAddress'
- 'summary.runtime.powerState'
- 'guest.guestFamily'
- 'config.template'
- 'config.guestId'
- 'config.annotation'
- 'guest.hostName'
keyed_groups:
- key: 'config.annotation.split("_")[2]'
   prefix: "moodleDb"
   separator: ""
with_nested_properties: True
filters:
- 'config.annotation is defined and config.annotation.startswith("DB_Moodle_") and not config.template'

thank you for your help :slight_smile:

'guest' is undefined tells me that that particular VM doesn’t have the vmware guest agent installed, and therefore has no guest.hostName property for you to define the hostname with.

edit: Looking at the documentation for the inventory plugin, you can list multiple values for hostnames, and the first one wins.

hostnames:
  - guest.hostName # preferred inventory_hostname
  - config.name # fallback inventory_hostname

yes i found them ! some temporary vm.
thank you :slight_smile: