Troubleshooting Dynamic Inventory in vmware.vmware.vms

Troubleshooting Dynamic Inventory in vmware.vmware.vms.

My goal is simply to configure ansible against my vcenter for dynamic inventory to start. When I run the script - even with a bad vcenter hostname - it runs instantly and fails - meaning I’m not even getting the point of connecting to vcenter and failing that way.

I started by creating my project in poetry:

poetry init --no-interaction --author "$(git config --get user.name)" --name "myproject"
# edit pyproject.toml to set package-mode = false
poetry config --local virtualenvs.in-project true
poetry install

I then activated my source and started installing all the things:

source .venv/bin/activate
poetry add ansible ansible-core
# to be safe:
ansible-galaxy collection install vmware.vmware
poetry add $(cat ~/.ansible/collections/ansible_collections/vmware/vmware/requirements.txt)

I created my playbook yaml:

mkdir -p ansible/playbooks/dynamic_inventory/
vi ansible/playbooks/dynamic_inventory/vmware.yml

Here’s my file with password obviously obfuscated

---
plugin: vmware.vmware.vms
hostname: vcenter.lab.myhome.com
username: administrator@vsphere.local
password: xxxxxxxx
validate_certs: False

Here’s the command I ran to try and figure out what’s going on and its output:

 ANSIBLE_DEBUG=1 ansible-inventory -i ansible/playbooks/dynamic_inventory/vmware.yml --list -vvvvv
 37908 1757478878.41400: starting run
 37908 1757478878.41419: Created the '/home/bzaks1424/.ansible' directory
ansible-inventory [core 2.19.2]
  config file = /home/bzaks1424/workspace/myproject/ansible.cfg
  configured module search path = ['/home/bzaks1424/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/ansible
  ansible collection location = /home/bzaks1424/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/bzaks1424/workspace/myproject/.venv/bin/ansible-inventory
  python version = 3.12.3 (main, Aug 14 2025, 17:47:21) [GCC 13.3.0] (/home/bzaks1424/workspace/myproject/.venv/bin/python)
  jinja version = 3.1.6
  pyyaml version = 6.0.2 (with libyaml v0.2.5)
Using /home/bzaks1424/workspace/myproject/ansible.cfg as config file
 37908 1757478878.41605: Added group all to inventory
 37908 1757478878.41608: Added group ungrouped to inventory
 37908 1757478878.41612: Group all now contains ungrouped
 37908 1757478878.41614: Examining possible inventory source: /home/bzaks1424/workspace/myproject/ansible/playbooks/dynamic_inventory/vmware.yml
setting up inventory plugins
Loading collection vmware.vmware from /home/bzaks1424/.ansible/collections/ansible_collections/vmware/vmware
Loading collection ansible.builtin from 
/home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/vmware/vapi/l10n/bundle.py:59: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  from pkg_resources import resource_string
 37908 1757478878.65551: Loading ModuleDocFragment 'ansible_collections.vmware.vmware.plugins.doc_fragments.base_options' from /home/bzaks1424/.ansible/collections/ansible_collections/vmware/vmware/plugins/doc_fragments/base_options.py
 37908 1757478878.65651: Loading ModuleDocFragment 'ansible_collections.vmware.vmware.plugins.doc_fragments.additional_rest_options' from /home/bzaks1424/.ansible/collections/ansible_collections/vmware/vmware/plugins/doc_fragments/additional_rest_options.py
 37908 1757478878.65695: Loading ModuleDocFragment 'ansible_collections.vmware.vmware.plugins.doc_fragments.plugin_base_options' from /home/bzaks1424/.ansible/collections/ansible_collections/vmware/vmware/plugins/doc_fragments/plugin_base_options.py
 37908 1757478878.65871: Loading ModuleDocFragment 'ansible_collections.ansible.builtin.plugins.doc_fragments.inventory_cache' from /home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/ansible/plugins/doc_fragments/inventory_cache.py
 37908 1757478878.66009: Loading ModuleDocFragment 'ansible_collections.ansible.builtin.plugins.doc_fragments.constructed' from /home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/ansible/plugins/doc_fragments/constructed.py
 37908 1757478878.66134: Loaded config def from plugin (inventory/ansible_collections.vmware.vmware.plugins.inventory.vms)
 37908 1757478878.66136: Loading InventoryModule 'ansible_collections.vmware.vmware.plugins.inventory.vms' from /home/bzaks1424/.ansible/collections/ansible_collections/vmware/vmware/plugins/inventory/vms.py
 37908 1757478878.66141: Attempting to use plugin ansible_collections.vmware.vmware.plugins.inventory.vms (/home/bzaks1424/.ansible/collections/ansible_collections/vmware/vmware/plugins/inventory/vms.py)
ansible_collections.vmware.vmware.plugins.inventory.vms declined parsing /home/bzaks1424/workspace/myproject/ansible/playbooks/dynamic_inventory/vmware.yml as it did not pass its verify_file() method
[WARNING]: Unable to parse /home/bzaks1424/workspace/myproject/ansible/playbooks/dynamic_inventory/vmware.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
 37908 1757478878.66233: '/home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/ansible/plugins/vars/__init__' skipped due to reserved name
 37908 1757478878.66349: trying /home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/ansible/plugins/doc_fragments
 37908 1757478878.66378: Loading ModuleDocFragment 'vars_plugin_staging' from /home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/ansible/plugins/doc_fragments/vars_plugin_staging.py
 37908 1757478878.66413: Loaded config def from plugin (vars/host_group_vars)
 37908 1757478878.66415: Loading VarsModule 'host_group_vars' from /home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/ansible/plugins/vars/host_group_vars.py (found_in_cache=False, class_only=True)
 37908 1757478878.66421: trying /home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/ansible/plugins/vars
 37908 1757478878.66426: Loading VarsModule 'host_group_vars' from /home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/ansible/plugins/vars/host_group_vars.py (found_in_cache=True, class_only=False)
 37908 1757478878.66450: trying /home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/ansible/plugins/cache
 37908 1757478878.66497: Loading CacheModule 'memory' from /home/bzaks1424/workspace/myproject/.venv/lib/python3.12/site-packages/ansible/plugins/cache/memory.py
{
    "_meta": {
        "hostvars": {},
        "profile": "inventory_legacy"
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

I genuinely cannot see smoking guns in this debug output to give me a place to start looking to fix my problem. I spent several hours with a couple of bad LLMs who led me in circles - so I’m going to the real experts for help.

I was able to reproduce this, with one tweak I got more information. Its not a solution, but it might help.

Based on this doc on the dynamic vmware inventory plugin, I added

[inventory]
enable_plugins = vmware.vmware_vm_inventory

to my local ansible.cfg

(This file doesn’t automatically exist, so I generated a “default” one with ansible-config init --disabled > ansible.cfg and then added that one change to it).

After that, I get the following additional information on the failure.

[WARNING]: Failed to load inventory plugin, skipping vmware.vmware_vm_inventory                                                                            
[WARNING]: Failed to parse inventory with 'auto' plugin: inventory source '/data/testing/vcenter_dynamic_test/ansible/playbooks/dynamic_inventory/vmware.yml' could not be verified by inventory plugin 'vmware.vmware.vms' 

So far, I haven’t determined what’s causing this, but hopefully this extra nugget can help someone get you closer to the answer.

Hey that was actually really helpful! It at least gave me new errors to fixate on

The doc you’re using is labeled as “unmaintained” - the latest and official docs are here

But I also hadn’t generated that default Ansible config - so I started with your bit and went from there. Playing “detective” - I decided to make sure that the same exact plugin was enabled in my cfg that’s at the top of my yaml vmware.vmware.vms
ansible.cfg:

[inventory]
enable_plugins = vmware.vmware.vms

And the the resulting text is exactly the same as my original output :man_facepalming:

  8489 1757508511.26089: Attempting to use plugin ansible_collections.vmware.vmware.plugins.inventory.vms (/home/bzaks1424/.ansible/collections/ansible_collections/vmware/vmware/plugins/inventory/vms.py)
ansible_collections.vmware.vmware.plugins.inventory.vms declined parsing /home/bzaks1424/workspace/myproject/ansible/playbooks/dynamic_inventory/vmware.yml as it did not pass its verify_file() method
[WARNING]: Unable to parse /home/bzaks1424/workspace/myproject/ansible/playbooks/dynamic_inventory/vmware.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available

This led me to ask "Is there no way to debug the verify_file method? And then I saw it:

8489 1757508511.26089: Attempting to use plugin ansible_collections.vmware.vmware.plugins.inventory.vms (/home/bzaks1424/.ansible/collections/ansible_collections/vmware/vmware/plugins/inventory/vms.py)

Naturally - I realized I could just look at the method.

vi ~/.ansible/collections/ansible_collections/vmware/vmware/plugins/inventory/vms.py

def verify_file(self, path):
    """
    Checks the plugin configuration file format and name, and returns True
    if everything is valid.
    Args:
        path: Path to the configuration YAML file
    Returns: 
        True if everything is correct, else False
    """
    if super(InventoryModule, self).verify_file(path):
        return path.endswith(
            (
                "vms.yml",
                "vms.yaml",
                "vmware_vms.yaml",
                "vmware_vms.yml"
            )
        )
    return False

I renamed my yml file to “vmware_vms.yml” and it magically works. I don’t know if I should cheer or cry.

1 Like

Good catch. I just did a quick google search and found it.

both!

Also, on reading the current doc you linked, I did see something that hints at this in the examples section

# Below are examples of inventory configuration files that can be used with this plugin.
# To test these and see the resulting inventory, save the snippet in a file named **hosts.vmware_vms.yml** and run:
# ansible-inventory -i **hosts.vmware_vms.yml** --list

(emphasis is mine)

Clearly I missed a line in the requirements:

Uses any file which ends with vms.yml, vms.yaml, vmware_vms.yml, or vmware_vms.yaml as a YAML configuration file.

So I can only blame that jerk in the mirror.

Thanks again for all of your help @Lyle_McKarns !!!