community.vmware.vmware_vm_info – Return basic info pertaining to a VMware machine guest¶
Note
This plugin is part of the community.vmware collection (version 1.7.0).
To install it use: ansible-galaxy collection install community.vmware
.
To use it in a playbook, specify: community.vmware.vmware_vm_info
.
Synopsis¶
Return basic information pertaining to a vSphere or ESXi virtual machine guest.
Cluster name as fact is added in version 2.7.
This module was called
vmware_vm_facts
before Ansible 2.9. The usage did not change.
Requirements¶
The below requirements are needed on the host that executes this module.
python >= 2.6
PyVmomi
Parameters¶
Notes¶
Note
Tested on ESXi 6.7, vSphere 5.5 and vSphere 6.5
From 2.8 and onwards, information are returned as list of dict instead of dict.
Fact about
moid
added in VMware collection 1.4.0.
Examples¶
- 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 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 | 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 | 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
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Authors¶
Joseph Callen (@jcpowermac)
Abhijeet Kasurde (@Akasurde)
Fedor Vompe (@sumkincpp)