diff --git a/lib/ansible/plugins/inventory/vmware_vm_inventory.py b/lib/ansible/plugins/inventory/vmware_vm_inventory.py index 9b44028874b..0ba36d83331 100644 --- a/lib/ansible/plugins/inventory/vmware_vm_inventory.py +++ b/lib/ansible/plugins/inventory/vmware_vm_inventory.py @@ -60,6 +60,19 @@ DOCUMENTATION = ''' - 'https://code.vmware.com/web/sdk/65/vsphere-automation-python' default: False type: boolean + properties: + description: + - Specify the list of VMware schema properties associated with the VM. + - These properties will be populated in hostvars of the given VM. + - Each value in the list specifies the path to a specific property in VM object. + type: list + default: [ 'name', 'config.cpuHotAddEnabled', 'config.cpuHotRemoveEnabled', + 'config.instanceUuid', 'config.hardware.numCPU', 'config.template', + 'config.name', 'guest.hostName', 'guest.ipAddress', + 'guest.guestId', 'guest.guestState', 'runtime.maxMemoryUsage', + 'customValue' + ] + version_added: "2.9" ''' EXAMPLES = ''' @@ -71,6 +84,18 @@ EXAMPLES = ''' password: Esxi@123$% validate_certs: False with_tags: True + +# Gather minimum set of properties for VMware guest + plugin: vmware_vm_inventory + strict: False + hostname: 10.65.223.31 + username: administrator@vsphere.local + password: Esxi@123$% + validate_certs: False + with_tags: False + properties: + - 'name' + - 'guest.ipAddress' ''' import ssl @@ -432,24 +457,9 @@ class InventoryModule(BaseInventoryPlugin, Cacheable): def _populate_host_properties(self, vm_obj, current_host): # Load VM properties in host_vars - vm_properties = [ - 'name', - 'config.cpuHotAddEnabled', - 'config.cpuHotRemoveEnabled', - 'config.instanceUuid', - 'config.hardware.numCPU', - 'config.template', - 'config.name', - 'guest.hostName', - 'guest.ipAddress', - 'guest.guestId', - 'guest.guestState', - 'runtime.maxMemoryUsage', - 'customValue', - ] - field_mgr = [] - if self.pyv.content.customFieldsManager: - field_mgr = self.pyv.content.customFieldsManager.field + vm_properties = self.get_option('properties') or [] + + field_mgr = self.pyv.content.customFieldsManager.field for vm_prop in vm_properties: if vm_prop == 'customValue':