How to let Ansible pick a datastore and ESX host in VMware

ansibleinfrastructurevmware-vsphere

I need 50gb space, 64gb of ram and 2 cpu's for new virtual machines.

We want to use Ansible for infrastructure as code, but what would best practices in letting Ansible picking the right datastore and esx host?

  • Write a python command based on the pyvmomi package? As Ansible doesn't seem to have any modules that can check for free disk space in data stores or for free memory in hosts.
  • Some sort of VMware dynamic inventory?

Best Answer

I use raw module for some tasks on esx host that are not available via native Ansible modules.

You can do raw: "df | grep datastore1 | awk '{print $4}'" to get free space, for example.

Note, that you need ssh access enabled for this to work.