vmware.vmware_rest.vcenter_vm_info module – Gather information about virtual machines in vCenter.

Note

This module is part of the vmware.vmware_rest collection (version 5.0.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install vmware.vmware_rest.

To use it in a playbook, specify: vmware.vmware_rest.vcenter_vm_info.

New in vmware.vmware_rest 5.0.0

DEPRECATED

Removed in:

version 6.0.0

Why:

This functionality has been moved to vmware.vmware.vm_info.

Alternative:

Use vmware.vmware.vm_info instead.

Synopsis

  • Retrieve information about one or more virtual machines managed by vCenter.

  • When a virtual machine identifier is supplied, return the full configuration details for that single virtual machine, including its hardware, boot options, CPU, memory, disks, and network adapters.

  • When no identifier is supplied, return a summary list of virtual machines, optionally narrowed using the available filters such as names, folders, datacenters, hosts, clusters, resource pools, and power states.

Parameters

Parameter

Comments

clusters

list / elements=string

Limit the results to virtual machines contained in these clusters.

Each value must be the MOID of a ClusterComputeResource resource.

If omitted or empty, virtual machines in any cluster match the filter.

datacenters

aliases: filter_datacenters

list / elements=string

Limit the results to virtual machines contained in these datacenters.

Each value must be the MOID of a Datacenter resource.

If omitted or empty, virtual machines in any datacenter match the filter.

folders

aliases: filter_folders

list / elements=string

Limit the results to virtual machines contained in these folders.

Each value must be the MOID of a Folder resource.

If omitted or empty, virtual machines in any folder match the filter.

hosts

list / elements=string

Limit the results to virtual machines running on these hosts.

Each value must be the MOID of a HostSystem resource.

If omitted or empty, virtual machines on any host match the filter.

names

aliases: filter_names

list / elements=string

Limit the results to virtual machines with these display names.

If omitted or empty, virtual machines with any name match the filter.

power_states

list / elements=string

Limit the results to virtual machines that are in one of these power states.

POWERED_OFF - The virtual machine is powered off.

POWERED_ON - The virtual machine is powered on.

SUSPENDED - The virtual machine is suspended.

If omitted or empty, virtual machines in any power state match the filter.

resource_pools

list / elements=string

Limit the results to virtual machines contained in these resource pools.

Each value must be the MOID of a ResourcePool resource.

If omitted or empty, virtual machines in any resource pool match the filter.

session_timeout

float

Timeout in seconds for the whole operation including connection establishment, request sending, and response.

Default: 300.0

vcenter_hostname

string / required

The hostname or IP address of the vSphere vCenter.

If the value is not specified in the task, the value of environment variable VMWARE_HOST will be used instead.

vcenter_password

string / required

The vSphere vCenter password.

If the value is not specified in the task, the value of environment variable VMWARE_PASSWORD will be used instead.

vcenter_port

integer

The port number of the vSphere vCenter.

If the value is not specified in the task, the value of environment variable VMWARE_PORT will be used instead.

vcenter_rest_log_file

string

Optional path to a log file for HTTP REST interaction.

If the value is not specified in the task, the value of environment variable VMWARE_REST_LOG_FILE will be used instead.

vcenter_username

string / required

The vSphere vCenter username.

If the value is not specified in the task, the value of environment variable VMWARE_USER will be used instead.

vcenter_validate_certs

boolean

Allows connection when SSL certificates are not valid.

Set to false when certificates are not trusted.

If the value is not specified in the task, the value of environment variable VMWARE_VALIDATE_CERTS will be used instead.

Choices:

  • false

  • true ← (default)

vm

string

Identifier of the virtual machine to retrieve full configuration details for.

Must be the MOID (managed object identifier) of a Vm resource.

When set, the module returns detailed information about this single virtual machine instead of a summary list.

vms

list / elements=string

Limit the results to virtual machines with these identifiers (MOIDs).

Each value must be the MOID of a Vm resource.

If omitted or empty, virtual machines with any identifier match the filter.

Notes

Note

  • Generated from vSphere API spec 9.1.0.

  • Compatible with vSphere API 7.0.3.

  • Compatible with vSphere API 8.0.2.

Examples

- name: List all virtual machines
  vmware.vmware_rest.vcenter_vm_info:
  register: all_vms

- name: Get full details about a specific virtual machine
  vmware.vmware_rest.vcenter_vm_info:
    vm: vm-1013
  register: my_vm

- name: Filter virtual machines by name
  vmware.vmware_rest.vcenter_vm_info:
    names:
      - my_test_vm
  register: filtered_vms

- name: Find powered-on virtual machines in specific clusters
  vmware.vmware_rest.vcenter_vm_info:
    clusters:
      - domain-c1007
    power_states:
      - POWERED_ON
  register: running_vms

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

id

string

MOID of the queried virtual machine.

This is not returned when a single VM is looked up directly by its MOID (using the vm parameter), since it would be redundant with the value the caller already supplied.

Returned: When only one resource, with a MOID, was queried.

Sample: "vm-1013"

info

list / elements=string

A list of virtual machines matching the query.

Returned: On success.

Sample: [{"cpu_count": 2, "memory_size_mib": 4096, "name": "my_test_vm", "power_state": "POWERED_ON", "vm": "vm-1013"}]

value

any

Raw output from the API response.

This output is maintained for consistency with version 4.x and earlier of this collection. It is recommended to switch to the info return key for a more consistent and documented output.

Returned: On success.

Sample: {"cpu": {"cores_per_socket": 1, "count": 2, "hot_add_enabled": false, "hot_remove_enabled": false}, "disks": {"2000": {"capacity": 17179869184, "label": "Hard disk 1", "type": "SCSI"}}, "guest_os": "RHEL_9_64", "memory": {"hot_add_enabled": false, "size_mib": 4096}, "name": "my_test_vm", "nics": {"4000": {"label": "Network adapter 1", "mac_address": "00:50:56:aa:bb:cc", "state": "CONNECTED", "type": "VMXNET3"}}, "power_state": "POWERED_ON"}

Status

  • This module will be removed in version 6.0.0. [deprecated]

  • For more information see DEPRECATED.

Authors

  • Ansible Eco Content Team (@eco-ansible-content)