The best way to interact with your hosts is to use the VMware dynamic inventory plugin, which dynamically queries VMware APIs and tells Ansible what nodes can be managed.
To use the VMware dynamic inventory plugins, you must install pyVmomi on your control node (the host running Ansible).
To include tag-related information for the virtual machines in your dynamic inventory, you also need the vSphere Automation SDK, which supports REST API features like tagging and content libraries, on your control node.
You can install the
vSphere Automation SDK following these instructions.
$ pip install pyvmomi
To use this VMware dynamic inventory plugin, you need to enable it first by specifying the following in the
[inventory] enable_plugins = vmware_vm_inventory
Then, create a file that ends in
.vmware.yaml in your working directory.
vmware_vm_inventory script takes in the same authentication information as any VMware module.
Here’s an example of a valid inventory file:
ansible-inventory --list -i <filename>.vmware.yml will create a list of VMware instances that are ready to be configured using Ansible.
Since the inventory configuration file contains vCenter password in plain text, a security risk, you may want to encrypt your entire inventory configuration file.
You can encrypt a valid inventory configuration file as follows:
$ ansible-vault encrypt <filename>.vmware.yml New Vault password: Confirm New Vault password: Encryption successful
And you can use this vaulted inventory configuration file using:
$ ansible-inventory -i filename.vmware.yml --list --vault-password-file=/path/to/vault_password_file