Specifying a folder to filter Ansible Dynamic inventory for VMware

ansiblevmware-vsphere

I want to use the vmware_inventory.py dynamic inventory script with Ansible to generate an inventory based on my VMware guests.

However, my Vsphere cluster has many hosts running on it which I do not with to have included in the inventory, or manage with Ansible. In the vmware_inventory.ini configuration I see the following line:

#host_filters={{ guest.gueststate == "running" }}

Which looks like it would be useful for filtering only the guests I wish to manage. However, I can't see where the possible values for this field are documented. Ideally, I'd use this in conjunction with the groupby_patterns configuration to get an inventory which has groups corresponding to their folder in Vsphere.

How can I specify that I only want to load hosts into my inventory that are in a specific folder, or have a prefix in their name, or have some other property assigned to them?

EDIT: this could also be a tag

Best Answer

I discovered that I needed to first modify the skip_keys parameter as such

skip_keys = declaredalarmstate,disabledmethod,dynamicproperty,dynamictype,environmentbrowser,managedby,childtype,resourceconfig

(removing parent, so that key is no longer skipped)

Now, I can specify a filter like this:

host_filters={{ parent.name == "MyFolderName"}}

And it will return all machines under the folder MyFolderName in VSphere