1.. _vmware_ansible_inventory:
2
3*************************************
4Using VMware dynamic inventory plugin
5*************************************
6
7.. contents:: Topics
8
9VMware Dynamic Inventory Plugin
10===============================
11
12
13The best way to interact with your hosts is to use the VMware dynamic inventory plugin, which dynamically queries VMware APIs and
14tells Ansible what nodes can be managed.
15
16Requirements
17------------
18
19To use the VMware dynamic inventory plugins, you must install `pyVmomi <https://github.com/vmware/pyvmomi>`_
20on your control node (the host running Ansible).
21
22To include tag-related information for the virtual machines in your dynamic inventory, you also need the `vSphere Automation SDK <https://code.vmware.com/web/sdk/65/vsphere-automation-python>`_, which supports REST API features like tagging and content libraries, on your control node.
23You can install the ``vSphere Automation SDK`` following `these instructions <https://github.com/vmware/vsphere-automation-sdk-python#installing-required-python-packages>`_.
24
25.. code-block:: bash
26
27    $ pip install pyvmomi
28
29To use this VMware dynamic inventory plugin, you need to enable it first by specifying the following in the ``ansible.cfg`` file:
30
31.. code-block:: ini
32
33  [inventory]
34  enable_plugins = vmware_vm_inventory
35
36Then, create a file that ends in ``.vmware.yml`` or ``.vmware.yaml`` in your working directory.
37
38The ``vmware_vm_inventory`` script takes in the same authentication information as any VMware module.
39
40Here's an example of a valid inventory file:
41
42.. code-block:: yaml
43
44    plugin: vmware_vm_inventory
45    strict: False
46    hostname: 10.65.223.31
47    username: administrator@vsphere.local
48    password: Esxi@123$%
49    validate_certs: False
50    with_tags: True
51
52
53Executing ``ansible-inventory --list -i <filename>.vmware.yml`` will create a list of VMware instances that are ready to be configured using Ansible.
54
55Using vaulted configuration files
56=================================
57
58Since the inventory configuration file contains vCenter password in plain text, a security risk, you may want to
59encrypt your entire inventory configuration file.
60
61You can encrypt a valid inventory configuration file as follows:
62
63.. code-block:: bash
64
65    $ ansible-vault encrypt <filename>.vmware.yml
66      New Vault password:
67      Confirm New Vault password:
68      Encryption successful
69
70And you can use this vaulted inventory configuration file using:
71
72.. code-block:: bash
73
74    $ ansible-inventory -i filename.vmware.yml --list --vault-password-file=/path/to/vault_password_file
75
76
77.. seealso::
78
79    `pyVmomi <https://github.com/vmware/pyvmomi>`_
80        The GitHub Page of pyVmomi
81    `pyVmomi Issue Tracker <https://github.com/vmware/pyvmomi/issues>`_
82        The issue tracker for the pyVmomi project
83    `vSphere Automation SDK GitHub Page <https://github.com/vmware/vsphere-automation-sdk-python>`_
84        The GitHub Page of vSphere Automation SDK for Python
85    `vSphere Automation SDK Issue Tracker <https://github.com/vmware/vsphere-automation-sdk-python/issues>`_
86        The issue tracker for vSphere Automation SDK for Python
87    :ref:`working_with_playbooks`
88        An introduction to playbooks
89    :ref:`playbooks_vault`
90        Using Vault in playbooks
91