community / community.vmware / 4.2.0 / module / vmware_vm_info Return basic info pertaining to a VMware machine guest Authors: Joseph Callen (@jcpowermac), Abhijeet Kasurde (@Akasurde), Fedor Vompe (@sumkincpp)community.vmware.vmware_vm_info (4.2.0) — module
Install with ansible-galaxy collection install community.vmware:==4.2.0
collections: - name: community.vmware version: 4.2.0
Return basic information pertaining to a vSphere or ESXi virtual machine guest.
- name: Gather all registered virtual machines community.vmware.vmware_vm_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' delegate_to: localhost register: vminfo
- debug: var: vminfo.virtual_machines
- name: Gather one specific VM community.vmware.vmware_vm_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' vm_name: 'vm_name_as_per_vcenter' delegate_to: localhost register: vm_info
- debug: var: vminfo.virtual_machines
- name: Gather only registered virtual machine templates community.vmware.vmware_vm_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' vm_type: template delegate_to: localhost register: template_info
- debug: var: template_info.virtual_machines
- name: Gather only registered virtual machines community.vmware.vmware_vm_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' vm_type: vm delegate_to: localhost register: vm_info
- debug: var: vm_info.virtual_machines
- name: Get UUID from given VM Name block: - name: Get virtual machine info community.vmware.vmware_vm_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' folder: "/datacenter/vm/folder" delegate_to: localhost register: vm_info - debug: msg: "{{ item.uuid }}" with_items: - "{{ vm_info.virtual_machines | community.general.json_query(query) }}" vars: query: "[?guest_name=='DC0_H0_VM0']"
- name: Get Tags from given VM Name block: - name: Get virtual machine info community.vmware.vmware_vm_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' folder: "/datacenter/vm/folder" delegate_to: localhost register: vm_info - debug: msg: "{{ item.tags }}" with_items: - "{{ vm_info.virtual_machines | community.general.json_query(query) }}" vars: query: "[?guest_name=='DC0_H0_VM0']"
- name: Gather all VMs from a specific folder community.vmware.vmware_vm_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' folder: "/Asia-Datacenter1/vm/prod" delegate_to: localhost register: vm_info
- name: Get datastore_url from given VM name block: - name: Get virtual machine info community.vmware.vmware_vm_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' delegate_to: localhost register: vm_info - debug: msg: "{{ item.datastore_url }}" with_items: - "{{ vm_info.virtual_machines | community.general.json_query(query) }}" vars: query: "[?guest_name=='DC0_H0_VM0']"
port: default: 443 description: - The port number of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable E(VMWARE_PORT) will be used instead. type: int folder: description: - Specify a folder location of VMs to gather information from. - 'Examples:' - ' folder: /ha-datacenter/vm' - ' folder: ha-datacenter/vm' - ' folder: /datacenter1/vm' - ' folder: datacenter1/vm' - ' folder: /datacenter1/vm/folder1' - ' folder: datacenter1/vm/folder1' - ' folder: /folder1/datacenter1/vm' - ' folder: folder1/datacenter1/vm' - ' folder: /folder1/datacenter1/vm/folder2' type: str vm_name: description: - Name of the virtual machine to get related configurations information from. type: str vm_type: choices: - all - vm - template default: all description: - If set to V(vm), then information are gathered for virtual machines only. - If set to V(template), then information are gathered for virtual machine templates only. - If set to V(all), then information are gathered for all virtual machines and virtual machine templates. required: false type: str hostname: description: - The hostname or IP address of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable E(VMWARE_HOST) will be used instead. type: str password: aliases: - pass - pwd description: - The password of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable E(VMWARE_PASSWORD) will be used instead. type: str show_net: default: true description: - Tags virtual machine's network is shown if set to V(true). type: bool version_added: 3.5.0 version_added_collection: community.vmware show_tag: default: false description: - Tags related to virtual machine are shown if set to V(true). type: bool username: aliases: - admin - user description: - The username of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable E(VMWARE_USER) will be used instead. type: str proxy_host: description: - Address of a proxy that will receive all HTTPS requests and relay them. - The format is a hostname or a IP. - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_HOST) will be used instead. required: false type: str proxy_port: description: - Port of the HTTP proxy that will receive all HTTPS requests and relay them. - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_PORT) will be used instead. required: false type: int show_folder: default: true description: - Show folders type: bool version_added: 3.7.0 version_added_collection: community.vmware show_cluster: default: true description: - Tags virtual machine's cluster is shown if set to V(true). type: bool version_added: 3.5.0 version_added_collection: community.vmware show_allocated: default: false description: - Allocated storage in byte and memory in MB are shown if it set to True. type: bool show_attribute: default: false description: - Attributes related to VM guest shown in information only when this is set V(true). type: bool show_datastore: default: true description: - Tags virtual machine's datastore is shown if set to V(true). type: bool version_added: 3.5.0 version_added_collection: community.vmware validate_certs: default: true description: - Allows connection when SSL certificates are not valid. Set to V(false) when certificates are not trusted. - If the value is not specified in the task, the value of environment variable E(VMWARE_VALIDATE_CERTS) will be used instead. type: bool show_datacenter: default: true description: - Tags virtual machine's datacenter is shown if set to V(true). type: bool version_added: 3.5.0 version_added_collection: community.vmware show_mac_address: default: true description: - Tags virtual machine's mac address is shown if set to V(true). type: bool version_added: 3.5.0 version_added_collection: community.vmware show_esxi_hostname: default: true description: - Tags virtual machine's ESXi host is shown if set to V(true). type: bool version_added: 3.5.0 version_added_collection: community.vmware show_resource_pool: default: true description: - Tags virtual machine's resource pool is shown if set to V(true). type: bool version_added: 3.5.0 version_added_collection: community.vmware
virtual_machines: description: list of dictionary of virtual machines and their information returned: success sample: - allocated: cpu: 2 memory: 16 storage: 500000000 attributes: job: backup-prepare cluster: null datacenter: Datacenter-1 datastore_url: - name: t880-o2g url: /vmfs/volumes/e074264a-e5c82a58 esxi_hostname: 10.76.33.226 folder: /Datacenter-1/vm guest_fullname: Ubuntu Linux (64-bit) guest_name: ubuntu_t ip_address: '' mac_address: - 00:50:56:87:a5:9a moid: vm-24 power_state: poweredOff tags: - category_id: urn:vmomi:InventoryServiceCategory:b316cc45-f1a9-4277-811d-56c7e7975203:GLOBAL category_name: cat_0001 description: '' id: urn:vmomi:InventoryServiceTag:43737ec0-b832-4abf-abb1-fd2448ce3b26:GLOBAL name: tag_0001 uuid: 4207072c-edd8-3bd5-64dc-903fd3a0db04 vm_network: 00:50:56:87:a5:9a: ipv4: - 10.76.33.228/24 ipv6: [] type: list