Is there a dynamic inventory for VMware in Ansible?

The documentation for Dynamic Inventory makes mention of so many dynamic inventories, but none for VMware.

I really liked the feature of tagging servers in Amazon EC2 and was hoping to re-create a similar system in our VMware environment.

Fetch all servers in vSphere with tags "environment=testing" and "application=helloworld" and run this Ansible playbook on them.


Solution 1:

Is there a dynamic inventory for VMware in Ansible?

There are two in the official Ansible repository:

  • vmware.py - an old one based on pysphere
  • vmware_inventory.py - a new one based on pyvmomi

Refer to the code and the configuration files (vmware.ini, vmware_inventory.ini) for usage details.


Alternatively you can fetch the VMs facts with vmware_vm_facts module and create your own in-memory inventory with add_host.