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

**URL:** <https://forum.ansible.com/t/vmware-inventory-source-error-guest-hostname-guest-is-undefined/4510>\
**Category:** Get Help\
**Tags:** vmware, awx, inventory, ansible-core\
**Created:** [March 22, 2024, 10:23am UTC](https://forum.ansible.com/t/vmware-inventory-source-error-guest-hostname-guest-is-undefined/4510 "2024-03-22T10:23:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karim\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/karim_a/32/2655_2.png) [@Karim\_A](https://forum.ansible.com/u/Karim_A)\
**Post date:** [March 22, 2024, 10:23am UTC](https://forum.ansible.com/t/vmware-inventory-source-error-guest-hostname-guest-is-undefined/4510/1 "2024-03-22T10:23:03Z")

</div>

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:

```auto
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:

```auto
---
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):

```auto
---
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 🙂

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [March 22, 2024, 4:21pm UTC](https://forum.ansible.com/t/vmware-inventory-source-error-guest-hostname-guest-is-undefined/4510/2 "2024-03-22T16:21:55Z")

</div>

`'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.

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

```

---

<div class="post-metadata">

**Author:** ![Karim\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/karim_a/32/2655_2.png) [@Karim\_A](https://forum.ansible.com/u/Karim_A)\
**Post date:** [March 22, 2024, 9:14pm UTC](https://forum.ansible.com/t/vmware-inventory-source-error-guest-hostname-guest-is-undefined/4510/3 "2024-03-22T21:14:27Z")

</div>

yes i found them ! some temporary vm.  
thank you 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 8, 2024, 4:24pm UTC](https://forum.ansible.com/t/vmware-inventory-source-error-guest-hostname-guest-is-undefined/4510/4 "2024-07-08T16:24:09Z")

</div>

Closed on July 8, 2024, 4:24pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
