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