vmware.vmware_rest.vcenter_vm module – Creates a virtual machine.

Note

This module is part of the vmware.vmware_rest collection (version 4.4.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. You need further requirements to be able to use this module, see Requirements for details.

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

New in vmware.vmware_rest 0.1.0

Synopsis

  • Creates a virtual machine.

Requirements

The below requirements are needed on the host that executes this module.

  • vSphere 7.0.3 or greater

  • python >= 3.6

  • aiohttp

Parameters

Parameter

Comments

bios_uuid

string

128-bit SMBIOS UUID of a virtual machine represented as a hexadecimal string in “12345678-abcd-1234-cdef-123456789abc” format.

If unset, will be generated.

boot

dictionary

Boot configuration.

If unset, guest-specific default values will be used.

Valid attributes are:

  • type (str): This option defines the valid firmware types for a virtual machine. ([‘present’])

  • Accepted values:

  • BIOS

  • EFI

  • efi_legacy_boot (bool): Flag indicating whether to use EFI legacy boot mode.

If unset, defaults to value that is recommended for the guest OS and is supported for the virtual hardware version. ([‘present’])

  • network_protocol (str): This option defines the valid network boot protocols supported when booting a virtual machine with EFI firmware over the network. ([‘present’])

  • Accepted values:

  • IPV4

  • IPV6

  • delay (int): Delay in milliseconds before beginning the firmware boot process when the virtual machine is powered on. This delay may be used to provide a time window for users to connect to the virtual machine console and enter BIOS setup mode.

If unset, default value is 0. ([‘present’])

  • retry (bool): Flag indicating whether the virtual machine should automatically retry the boot process after a failure.

If unset, default value is false. ([‘present’])

  • retry_delay (int): Delay in milliseconds before retrying the boot process after a failure; applicable only when retry is true.

If unset, default value is 10000. ([‘present’])

  • enter_setup_mode (bool): Flag indicating whether the firmware boot process should automatically enter setup mode the next time the virtual machine boots. Note that this flag will automatically be reset to false once the virtual machine enters setup mode.

If unset, the value is unchanged. ([‘present’])

boot_devices

list / elements=dictionary

Boot device configuration.

If unset, a server-specific boot sequence will be used.

Valid attributes are:

  • type (str): This option defines the valid device types that may be used as bootable devices. ([‘present’])

This key is required with [‘present’].

  • Accepted values:

  • CDROM

  • DISK

  • ETHERNET

  • FLOPPY

cdroms

list / elements=dictionary

List of CD-ROMs.

If unset, no CD-ROM devices will be created.

Valid attributes are:

  • type (str): This option defines the valid types of host bus adapters that may be used for attaching a Cdrom to a virtual machine. ([‘present’])

  • Accepted values:

  • IDE

  • SATA

  • ide (dict): Address for attaching the device to a virtual IDE adapter.

If unset, the server will choose an available address; if none is available, the request will fail. ([‘present’])

  • Accepted keys:

  • primary (boolean): Flag specifying whether the device should be attached to the primary or secondary IDE adapter of the virtual machine.

If unset, the server will choose a adapter with an available connection. If no IDE connections are available, the request will be rejected.

  • master (boolean): Flag specifying whether the device should be the master or slave device on the IDE adapter.

If unset, the server will choose an available connection type. If no IDE connections are available, the request will be rejected.

  • sata (dict): Address for attaching the device to a virtual SATA adapter.

If unset, the server will choose an available address; if none is available, the request will fail. ([‘present’])

  • Accepted keys:

  • bus (integer): Bus number of the adapter to which the device should be attached.

  • unit (integer): Unit number of the device.

If unset, the server will choose an available unit number on the specified adapter. If there are no available connections on the adapter, the request will be rejected.

  • backing (dict): Physical resource backing for the virtual CD-ROM device.

If unset, defaults to automatic detection of a suitable host device. ([‘present’])

  • Accepted keys:

  • type (string): This option defines the valid backing types for a virtual CD-ROM device.

Accepted value for this field:

  • CLIENT_DEVICE

  • HOST_DEVICE

  • ISO_FILE

  • iso_file (string): Path of the image file that should be used as the virtual CD-ROM device backing.

This field is optional and it is only relevant when the value of type is ISO_FILE.

  • host_device (string): Name of the device that should be used as the virtual CD-ROM device backing.

If unset, the virtual CD-ROM device will be configured to automatically detect a suitable host device.

  • device_access_type (string): This option defines the valid device access types for a physical device packing of a virtual CD-ROM device.

Accepted value for this field:

  • EMULATION

  • PASSTHRU

  • PASSTHRU_EXCLUSIVE

  • start_connected (bool): Flag indicating whether the virtual device should be connected whenever the virtual machine is powered on.

Defaults to false if unset. ([‘present’])

  • allow_guest_control (bool): Flag indicating whether the guest can connect and disconnect the device.

Defaults to false if unset. ([‘present’])

cpu

dictionary

CPU configuration.

If unset, guest-specific default values will be used.

Valid attributes are:

  • count (int): New number of CPU cores. The number of CPU cores in the virtual machine must be a multiple of the number of cores per socket.

The supported range of CPU counts is constrained by the configured guest operating system and virtual hardware version of the virtual machine.

If the virtual machine is running, the number of CPU cores may only be increased if hot_add_enabled is true, and may only be decreased if hot_remove_enabled is true.

If unset, the value is unchanged. ([‘present’])

  • cores_per_socket (int): New number of CPU cores per socket. The number of CPU cores in the virtual machine must be a multiple of the number of cores per socket.

If unset, the value is unchanged. ([‘present’])

  • hot_add_enabled (bool): Flag indicating whether adding CPUs while the virtual machine is running is enabled.

This field may only be modified if the virtual machine is powered off.

If unset, the value is unchanged. ([‘present’])

  • hot_remove_enabled (bool): Flag indicating whether removing CPUs while the virtual machine is running is enabled.

This field may only be modified if the virtual machine is powered off.

If unset, the value is unchanged. ([‘present’])

datastore

string

Identifier of the datastore on which the virtual machine’s configuration state is stored.

If unset, path must also be unset and datastore_path must be set.

When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_datastore_info.

datastore_path

string

Datastore path for the virtual machine’s configuration file in the format “[datastore name] path”. For example “[storage1] Test-VM/Test-VM.vmx”.

If unset, both datastore and path must be set.

disconnect_all_nics

boolean

Indicates whether all NICs on the destination virtual machine should be disconnected from the newtwork

If unset, connection status of all NICs on the destination virtual machine will be the same as on the source virtual machine.

Choices:

  • false

  • true

disks

list / elements=dictionary

Individual disk relocation map.

If unset, all disks will migrate to the datastore specified in the datastore field of

When clients pass a value of this structure as a parameter, the key in the field map must be the id of a resource returned by vmware.vmware_rest.vcenter_vm_hardware_disk.

Valid attributes are:

  • type (str): This option defines the valid types of host bus adapters that may be used for attaching a virtual storage device to a virtual machine. ([‘present’])

  • Accepted values:

  • IDE

  • NVME

  • SATA

  • SCSI

  • ide (dict): Address for attaching the device to a virtual IDE adapter.

If unset, the server will choose an available address; if none is available, the request will fail. ([‘present’])

  • Accepted keys:

  • primary (boolean): Flag specifying whether the device should be attached to the primary or secondary IDE adapter of the virtual machine.

If unset, the server will choose a adapter with an available connection. If no IDE connections are available, the request will be rejected.

  • master (boolean): Flag specifying whether the device should be the master or slave device on the IDE adapter.

If unset, the server will choose an available connection type. If no IDE connections are available, the request will be rejected.

  • scsi (dict): Address for attaching the device to a virtual SCSI adapter.

If unset, the server will choose an available address; if none is available, the request will fail. ([‘present’])

  • Accepted keys:

  • bus (integer): Bus number of the adapter to which the device should be attached.

  • unit (integer): Unit number of the device.

If unset, the server will choose an available unit number on the specified adapter. If there are no available connections on the adapter, the request will be rejected.

  • sata (dict): Address for attaching the device to a virtual SATA adapter.

If unset, the server will choose an available address; if none is available, the request will fail. ([‘present’])

  • Accepted keys:

  • bus (integer): Bus number of the adapter to which the device should be attached.

  • unit (integer): Unit number of the device.

If unset, the server will choose an available unit number on the specified adapter. If there are no available connections on the adapter, the request will be rejected.

  • nvme (dict): Address for attaching the device to a virtual NVMe adapter.

If unset, the server will choose an available address; if none is available, the request will fail. ([‘present’])

  • Accepted keys:

  • bus (integer): Bus number of the adapter to which the device should be attached.

  • unit (integer): Unit number of the device.

If unset, the server will choose an available unit number on the specified adapter. If there are no available connections on the adapter, the request will be rejected.

  • backing (dict): Existing physical resource backing for the virtual disk. Exactly one of backing or new_vmdk must be specified.

If unset, the virtual disk will not be connected to an existing backing. ([‘present’])

  • Accepted keys:

  • type (string): This option defines the valid backing types for a virtual disk.

Accepted value for this field:

  • VMDK_FILE

  • vmdk_file (string): Path of the VMDK file backing the virtual disk.

This field is optional and it is only relevant when the value of type is VMDK_FILE.

  • new_vmdk (dict): Specification for creating a new VMDK backing for the virtual disk. Exactly one of backing or new_vmdk must be specified.

If unset, a new VMDK backing will not be created. ([‘present’])

  • Accepted keys:

  • name (string): Base name of the VMDK file. The name should not include the ‘.vmdk’ file extension.

If unset, a name (derived from the name of the virtual machine) will be chosen by the server.

  • capacity (integer): Capacity of the virtual disk backing in bytes.

If unset, defaults to a guest-specific capacity.

  • storage_policy (object): The storage_policy_spec structure contains information about the storage policy that is to be associated the with VMDK file.

If unset the default storage policy of the target datastore (if applicable) is applied. Currently a default storage policy is only supported by object based datastores : VVol & vSAN. For non- object datastores, if unset then no storage policy would be associated with the VMDK file.

disks_to_remove

list / elements=string

Set of Disks to Remove.

If unset, all disks will be copied. If the same identifier is in disks_to_update InvalidArgument fault will be returned.

When clients pass a value of this structure as a parameter, the field must contain the id of resources returned by vmware.vmware_rest.vcenter_vm_hardware_disk.

disks_to_update

dictionary

Map of Disks to Update.

If unset, all disks will copied to the datastore specified in the datastore field of If the same identifier is in disks_to_remove InvalidArgument fault will be thrown.

When clients pass a value of this structure as a parameter, the key in the field map must be the id of a resource returned by vmware.vmware_rest.vcenter_vm_hardware_disk.

floppies

list / elements=dictionary

List of floppy drives.

If unset, no floppy drives will be created.

Valid attributes are:

  • backing (dict): Physical resource backing for the virtual floppy drive.

If unset, defaults to automatic detection of a suitable host device. ([‘present’])

  • Accepted keys:

  • type (string): This option defines the valid backing types for a virtual floppy drive.

Accepted value for this field:

  • CLIENT_DEVICE

  • HOST_DEVICE

  • IMAGE_FILE

  • image_file (string): Path of the image file that should be used as the virtual floppy drive backing.

This field is optional and it is only relevant when the value of type is IMAGE_FILE.

  • host_device (string): Name of the device that should be used as the virtual floppy drive backing.

If unset, the virtual floppy drive will be configured to automatically detect a suitable host device.

  • start_connected (bool): Flag indicating whether the virtual device should be connected whenever the virtual machine is powered on.

Defaults to false if unset. ([‘present’])

  • allow_guest_control (bool): Flag indicating whether the guest can connect and disconnect the device.

Defaults to false if unset. ([‘present’])

guest_customization_spec

dictionary

Guest customization spec to apply to the virtual machine after the virtual machine is deployed.

If unset, the guest operating system is not customized after clone.

Valid attributes are:

  • name (str): Name of the customization specification.

If unset, no guest customization is performed. ([‘clone’])

guest_OS

string

The GuestOS enumerated type defines the valid guest operating system types used for configuring a virtual machine. Required with state=[‘present’]

Choices:

  • "ALMALINUX_64"

  • "AMAZONLINUX2_64"

  • "AMAZONLINUX3_64"

  • "ASIANUX_3"

  • "ASIANUX_3_64"

  • "ASIANUX_4"

  • "ASIANUX_4_64"

  • "ASIANUX_5_64"

  • "ASIANUX_7_64"

  • "ASIANUX_8_64"

  • "ASIANUX_9_64"

  • "CENTOS"

  • "CENTOS_6"

  • "CENTOS_64"

  • "CENTOS_6_64"

  • "CENTOS_7"

  • "CENTOS_7_64"

  • "CENTOS_8_64"

  • "CENTOS_9_64"

  • "COREOS_64"

  • "CRXPOD_1"

  • "DARWIN"

  • "DARWIN_10"

  • "DARWIN_10_64"

  • "DARWIN_11"

  • "DARWIN_11_64"

  • "DARWIN_12_64"

  • "DARWIN_13_64"

  • "DARWIN_14_64"

  • "DARWIN_15_64"

  • "DARWIN_16_64"

  • "DARWIN_17_64"

  • "DARWIN_18_64"

  • "DARWIN_19_64"

  • "DARWIN_20_64"

  • "DARWIN_21_64"

  • "DARWIN_22_64"

  • "DARWIN_23_64"

  • "DARWIN_64"

  • "DEBIAN_10"

  • "DEBIAN_10_64"

  • "DEBIAN_11"

  • "DEBIAN_11_64"

  • "DEBIAN_12"

  • "DEBIAN_12_64"

  • "DEBIAN_4"

  • "DEBIAN_4_64"

  • "DEBIAN_5"

  • "DEBIAN_5_64"

  • "DEBIAN_6"

  • "DEBIAN_6_64"

  • "DEBIAN_7"

  • "DEBIAN_7_64"

  • "DEBIAN_8"

  • "DEBIAN_8_64"

  • "DEBIAN_9"

  • "DEBIAN_9_64"

  • "DOS"

  • "ECOMSTATION"

  • "ECOMSTATION_2"

  • "FEDORA"

  • "FEDORA_64"

  • "FREEBSD"

  • "FREEBSD_11"

  • "FREEBSD_11_64"

  • "FREEBSD_12"

  • "FREEBSD_12_64"

  • "FREEBSD_13"

  • "FREEBSD_13_64"

  • "FREEBSD_14"

  • "FREEBSD_14_64"

  • "FREEBSD_64"

  • "GENERIC_LINUX"

  • "MANDRAKE"

  • "MANDRIVA"

  • "MANDRIVA_64"

  • "NETWARE_4"

  • "NETWARE_5"

  • "NETWARE_6"

  • "NLD_9"

  • "OES"

  • "OPENSERVER_5"

  • "OPENSERVER_6"

  • "OPENSUSE"

  • "OPENSUSE_64"

  • "ORACLE_LINUX"

  • "ORACLE_LINUX_6"

  • "ORACLE_LINUX_64"

  • "ORACLE_LINUX_6_64"

  • "ORACLE_LINUX_7"

  • "ORACLE_LINUX_7_64"

  • "ORACLE_LINUX_8_64"

  • "ORACLE_LINUX_9_64"

  • "OS2"

  • "OTHER"

  • "OTHER_24X_LINUX"

  • "OTHER_24X_LINUX_64"

  • "OTHER_26X_LINUX"

  • "OTHER_26X_LINUX_64"

  • "OTHER_3X_LINUX"

  • "OTHER_3X_LINUX_64"

  • "OTHER_4X_LINUX"

  • "OTHER_4X_LINUX_64"

  • "OTHER_5X_LINUX"

  • "OTHER_5X_LINUX_64"

  • "OTHER_64"

  • "OTHER_6X_LINUX"

  • "OTHER_6X_LINUX_64"

  • "OTHER_LINUX"

  • "OTHER_LINUX_64"

  • "REDHAT"

  • "RHEL_2"

  • "RHEL_3"

  • "RHEL_3_64"

  • "RHEL_4"

  • "RHEL_4_64"

  • "RHEL_5"

  • "RHEL_5_64"

  • "RHEL_6"

  • "RHEL_6_64"

  • "RHEL_7"

  • "RHEL_7_64"

  • "RHEL_8_64"

  • "RHEL_9_64"

  • "ROCKYLINUX_64"

  • "SJDS"

  • "SLES"

  • "SLES_10"

  • "SLES_10_64"

  • "SLES_11"

  • "SLES_11_64"

  • "SLES_12"

  • "SLES_12_64"

  • "SLES_15_64"

  • "SLES_16_64"

  • "SLES_64"

  • "SOLARIS_10"

  • "SOLARIS_10_64"

  • "SOLARIS_11_64"

  • "SOLARIS_6"

  • "SOLARIS_7"

  • "SOLARIS_8"

  • "SOLARIS_9"

  • "SUSE"

  • "SUSE_64"

  • "TURBO_LINUX"

  • "TURBO_LINUX_64"

  • "UBUNTU"

  • "UBUNTU_64"

  • "UNIXWARE_7"

  • "VMKERNEL"

  • "VMKERNEL_5"

  • "VMKERNEL_6"

  • "VMKERNEL_65"

  • "VMKERNEL_7"

  • "VMKERNEL_8"

  • "VMWARE_PHOTON_64"

  • "WINDOWS_11_64"

  • "WINDOWS_12_64"

  • "WINDOWS_7"

  • "WINDOWS_7_64"

  • "WINDOWS_7_SERVER_64"

  • "WINDOWS_8"

  • "WINDOWS_8_64"

  • "WINDOWS_8_SERVER_64"

  • "WINDOWS_9"

  • "WINDOWS_9_64"

  • "WINDOWS_9_SERVER_64"

  • "WINDOWS_HYPERV"

  • "WINDOWS_SERVER_2019"

  • "WINDOWS_SERVER_2021"

  • "WINDOWS_SERVER_2025"

  • "WIN_2000_ADV_SERV"

  • "WIN_2000_PRO"

  • "WIN_2000_SERV"

  • "WIN_31"

  • "WIN_95"

  • "WIN_98"

  • "WIN_LONGHORN"

  • "WIN_LONGHORN_64"

  • "WIN_ME"

  • "WIN_NET_BUSINESS"

  • "WIN_NET_DATACENTER"

  • "WIN_NET_DATACENTER_64"

  • "WIN_NET_ENTERPRISE"

  • "WIN_NET_ENTERPRISE_64"

  • "WIN_NET_STANDARD"

  • "WIN_NET_STANDARD_64"

  • "WIN_NET_WEB"

  • "WIN_NT"

  • "WIN_VISTA"

  • "WIN_VISTA_64"

  • "WIN_XP_HOME"

  • "WIN_XP_PRO"

  • "WIN_XP_PRO_64"

hardware_version

string

The version enumerated type defines the valid virtual hardware versions for a virtual machine. See https://kb.vmware.com/s/article/1003746 (Virtual machine hardware versions (1003746)).

Choices:

  • "VMX_03"

  • "VMX_04"

  • "VMX_06"

  • "VMX_07"

  • "VMX_08"

  • "VMX_09"

  • "VMX_10"

  • "VMX_11"

  • "VMX_12"

  • "VMX_13"

  • "VMX_14"

  • "VMX_15"

  • "VMX_16"

  • "VMX_17"

  • "VMX_18"

  • "VMX_19"

  • "VMX_20"

  • "VMX_21"

memory

dictionary

Memory configuration.

If unset, guest-specific default values will be used.

Valid attributes are:

  • size_MiB (int): New memory size in mebibytes.

The supported range of memory sizes is constrained by the configured guest operating system and virtual hardware version of the virtual machine.

If the virtual machine is running, this value may only be changed if hot_add_enabled is true, and the new memory size must satisfy the constraints specified by hot_add_increment_size_mib and

If unset, the value is unchanged. ([‘present’])

  • hot_add_enabled (bool): Flag indicating whether adding memory while the virtual machine is running should be enabled.

Some guest operating systems may consume more resources or perform less efficiently when they run on hardware that supports adding memory while the machine is running.

This field may only be modified if the virtual machine is not powered on.

If unset, the value is unchanged. ([‘present’])

name

string

Virtual machine name.

If unset, the display name from the virtual machine’s configuration file will be used.

nics

list / elements=dictionary

List of Ethernet adapters.

If unset, no Ethernet adapters will be created.

Valid attributes are:

  • type (str): This option defines the valid emulation types for a virtual Ethernet adapter. ([‘present’])

  • Accepted values:

  • E1000

  • E1000E

  • PCNET32

  • VMXNET

  • VMXNET2

  • VMXNET3

  • upt_compatibility_enabled (bool): Flag indicating whether Universal Pass-Through (UPT) compatibility is enabled on this virtual Ethernet adapter.

If unset, UPT will not be enabled on the newly-created virtual Ethernet adapter. ([‘present’])

  • mac_type (str): This option defines the valid MAC address origins for a virtual Ethernet adapter. ([‘present’])

  • Accepted values:

  • ASSIGNED

  • GENERATED

  • MANUAL

  • mac_address (str): MAC address.

Workaround for PR1459647 ([‘present’])

  • pci_slot_number (int): Address of the virtual Ethernet adapter on the PCI bus. If the PCI address is invalid, the server will change when it the VM is started or as the device is hot added.

If unset, the server will choose an available address when the virtual machine is powered on. ([‘present’])

  • wake_on_lan_enabled (bool): Flag indicating whether wake-on-LAN is enabled on this virtual Ethernet adapter.

Defaults to false if unset. ([‘present’])

  • backing (dict): Physical resource backing for the virtual Ethernet adapter.

If unset, the system may try to find an appropriate backing. If one is not found, the request will fail. ([‘present’])

  • Accepted keys:

  • type (string): This option defines the valid backing types for a virtual Ethernet adapter.

Accepted value for this field:

  • DISTRIBUTED_PORTGROUP

  • HOST_DEVICE

  • OPAQUE_NETWORK

  • STANDARD_PORTGROUP

  • network (string): Identifier of the network that backs the virtual Ethernet adapter.

This field is optional and it is only relevant when the value of type is one of STANDARD_PORTGROUP, DISTRIBUTED_PORTGROUP, or OPAQUE_NETWORK.

When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_network_info.

  • distributed_port (string): Key of the distributed virtual port that backs the virtual Ethernet adapter. Depending on the type of the Portgroup, the port may be specified using this field. If the portgroup type is early-binding (also known as static), a port is assigned when the Ethernet adapter is configured to use the port. The port may be either automatically or specifically assigned based on the value of this field. If the portgroup type is ephemeral, the port is created and assigned to a virtual machine when it is powered on and the Ethernet adapter is connected. This field cannot be specified as no free ports exist before use.

May be used to specify a port when the network specified on the network field is a static or early binding distributed portgroup. If unset, the port will be automatically assigned to the Ethernet adapter based on the policy embodied by the portgroup type.

  • start_connected (bool): Flag indicating whether the virtual device should be connected whenever the virtual machine is powered on.

Defaults to false if unset. ([‘present’])

  • allow_guest_control (bool): Flag indicating whether the guest can connect and disconnect the device.

Defaults to false if unset. ([‘present’])

nics_to_update

dictionary

Map of NICs to update.

If unset, no NICs will be updated.

When clients pass a value of this structure as a parameter, the key in the field map must be the id of a resource returned by vmware.vmware_rest.vcenter_vm_hardware_ethernet.

nvme_adapters

list / elements=dictionary

List of NVMe adapters.

If unset, any adapters necessary to connect the virtual machine’s storage devices will be created; this includes any devices that explicitly specify a NVMe host bus adapter, as well as any devices that do not specify a host bus adapter if the guest’s preferred adapter type is NVMe.

Valid attributes are:

  • bus (int): NVMe bus number.

If unset, the server will choose an available bus number; if none is available, the request will fail. ([‘present’])

  • pci_slot_number (int): Address of the NVMe adapter on the PCI bus.

If unset, the server will choose an available address when the virtual machine is powered on. ([‘present’])

parallel_ports

list / elements=dictionary

List of parallel ports.

If unset, no parallel ports will be created.

Valid attributes are:

  • backing (dict): Physical resource backing for the virtual parallel port.

If unset, defaults to automatic detection of a suitable host device. ([‘present’])

  • Accepted keys:

  • type (string): This option defines the valid backing types for a virtual parallel port.

Accepted value for this field:

  • FILE

  • HOST_DEVICE

  • file (string): Path of the file that should be used as the virtual parallel port backing.

This field is optional and it is only relevant when the value of type is FILE.

  • host_device (string): Name of the device that should be used as the virtual parallel port backing.

If unset, the virtual parallel port will be configured to automatically detect a suitable host device.

  • start_connected (bool): Flag indicating whether the virtual device should be connected whenever the virtual machine is powered on.

Defaults to false if unset. ([‘present’])

  • allow_guest_control (bool): Flag indicating whether the guest can connect and disconnect the device.

Defaults to false if unset. ([‘present’])

parallel_ports_to_update

dictionary

Map of parallel ports to Update.

If unset, no parallel ports will be updated.

When clients pass a value of this structure as a parameter, the key in the field map must be the id of a resource returned by vmware.vmware_rest.vcenter_vm_hardware_parallel.

path

string

Path to the virtual machine’s configuration file on the datastore corresponding to {@link #datastore).

If unset, datastore must also be unset and datastore_path must be set.

placement

dictionary

Virtual machine placement information.

If this field is unset, the system will use the values from the source virtual machine. If specified, each field will be used for placement. If the fields result in disjoint placement the operation will fail. If the fields along with the other existing placement of the virtual machine result in disjoint placement the operation will fail.

Valid attributes are:

  • folder (str): Virtual machine folder into which the virtual machine should be placed.

If this field is unset, the virtual machine will stay in the current folder.

When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_folder_info. ([‘clone’, ‘instant_clone’, ‘present’, ‘register’, ‘relocate’])

  • resource_pool (str): Resource pool into which the virtual machine should be placed.

If this field is unset, the virtual machine will stay in the current resource pool.

When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_resourcepool_info. ([‘clone’, ‘instant_clone’, ‘present’, ‘register’, ‘relocate’])

  • host (str): Host onto which the virtual machine should be placed.

If host and resource_pool are both specified, resource_pool must belong to host.

If host and cluster are both specified, host must be a member of cluster.

If this field is unset, if resource_pool is unset, the virtual machine will remain on the current host. if resource_pool is set, and the target is a standalone host, the host is used. if resource_pool is set, and the target is a DRS cluster, a host will be picked by DRS. if resource_pool is set, and the target is a cluster without DRS, InvalidArgument will be thrown.

When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_host_info. ([‘clone’, ‘present’, ‘register’, ‘relocate’])

  • cluster (str): Cluster into which the virtual machine should be placed.

If cluster and resource_pool are both specified, resource_pool must belong to cluster.

If cluster and host are both specified, host must be a member of cluster.

If resource_pool or host is specified, it is recommended that this field be unset.

When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_cluster_info. ([‘clone’, ‘present’, ‘register’, ‘relocate’])

  • datastore (str): Datastore on which the virtual machine’s configuration state should be stored. This datastore will also be used for any virtual disks that are associated with the virtual machine, unless individually overridden.

If this field is unset, the virtual machine will remain on the current datastore.

When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_datastore_info. ([‘clone’, ‘instant_clone’, ‘present’, ‘relocate’])

power_on

boolean

Attempt to perform a power_on after clone.

If unset, the virtual machine will not be powered on.

Choices:

  • false

  • true

sata_adapters

list / elements=dictionary

List of SATA adapters.

If unset, any adapters necessary to connect the virtual machine’s storage devices will be created; this includes any devices that explicitly specify a SATA host bus adapter, as well as any devices that do not specify a host bus adapter if the guest’s preferred adapter type is SATA.

Valid attributes are:

  • type (str): This option defines the valid emulation types for a virtual SATA adapter. ([‘present’])

  • Accepted values:

  • AHCI

  • bus (int): SATA bus number.

If unset, the server will choose an available bus number; if none is available, the request will fail. ([‘present’])

  • pci_slot_number (int): Address of the SATA adapter on the PCI bus.

If unset, the server will choose an available address when the virtual machine is powered on. ([‘present’])

scsi_adapters

list / elements=dictionary

List of SCSI adapters.

If unset, any adapters necessary to connect the virtual machine’s storage devices will be created; this includes any devices that explicitly specify a SCSI host bus adapter, as well as any devices that do not specify a host bus adapter if the guest’s preferred adapter type is SCSI. The type of the SCSI adapter will be a guest-specific default type.

Valid attributes are:

  • type (str): This option defines the valid emulation types for a virtual SCSI adapter. ([‘present’])

  • Accepted values:

  • BUSLOGIC

  • LSILOGIC

  • LSILOGICSAS

  • PVSCSI

  • bus (int): SCSI bus number.

If unset, the server will choose an available bus number; if none is available, the request will fail. ([‘present’])

  • pci_slot_number (int): Address of the SCSI adapter on the PCI bus. If the PCI address is invalid, the server will change it when the VM is started or as the device is hot added.

If unset, the server will choose an available address when the virtual machine is powered on. ([‘present’])

  • sharing (str): This option defines the valid bus sharing modes for a virtual SCSI adapter. ([‘present’])

  • Accepted values:

  • NONE

  • PHYSICAL

  • VIRTUAL

serial_ports

list / elements=dictionary

List of serial ports.

If unset, no serial ports will be created.

Valid attributes are:

  • yield_on_poll (bool): CPU yield behavior. If set to true, the virtual machine will periodically relinquish the processor if its sole task is polling the virtual serial port. The amount of time it takes to regain the processor will depend on the degree of other virtual machine activity on the host.

If unset, defaults to false. ([‘present’])

  • backing (dict): Physical resource backing for the virtual serial port.

If unset, defaults to automatic detection of a suitable host device. ([‘present’])

  • Accepted keys:

  • type (string): This option defines the valid backing types for a virtual serial port.

Accepted value for this field:

  • FILE

  • HOST_DEVICE

  • NETWORK_CLIENT

  • NETWORK_SERVER

  • PIPE_CLIENT

  • PIPE_SERVER

  • file (string): Path of the file backing the virtual serial port.

This field is optional and it is only relevant when the value of type is FILE.

  • host_device (string): Name of the device backing the virtual serial port.

If unset, the virtual serial port will be configured to automatically detect a suitable host device.

  • pipe (string): Name of the pipe backing the virtual serial port.

This field is optional and it is only relevant when the value of type is one of PIPE_SERVER or PIPE_CLIENT.

  • no_rx_loss (boolean): Flag that enables optimized data transfer over the pipe. When the value is true, the host buffers data to prevent data overrun. This allows the virtual machine to read all of the data transferred over the pipe with no data loss.

If unset, defaults to false.

  • network_location (string): URI specifying the location of the network service backing the virtual serial port.

  • If type is NETWORK_SERVER, this field is the location used by clients to connect to this server. The hostname part of the URI should either be empty or should specify the address of the host on which the virtual machine is running.

  • If type is NETWORK_CLIENT, this field is the location used by the virtual machine to connect to the remote server.

This field is optional and it is only relevant when the value of type is one of NETWORK_SERVER or NETWORK_CLIENT.

  • proxy (string): Proxy service that provides network access to the network backing. If set, the virtual machine initiates a connection with the proxy service and forwards the traffic to the proxy.

If unset, no proxy service should be used.

  • start_connected (bool): Flag indicating whether the virtual device should be connected whenever the virtual machine is powered on.

Defaults to false if unset. ([‘present’])

  • allow_guest_control (bool): Flag indicating whether the guest can connect and disconnect the device.

Defaults to false if unset. ([‘present’])

serial_ports_to_update

dictionary

Map of serial ports to Update.

If unset, no serial ports will be updated.

When clients pass a value of this structure as a parameter, the key in the field map must be the id of a resource returned by vmware.vmware_rest.vcenter_vm_hardware_serial.

session_timeout

float

added in vmware.vmware_rest 2.1.0

Timeout settings for client session.

The maximal number of seconds for the whole operation including connection establishment, request sending and response.

The default value is 300s.

source

string

Virtual machine to InstantClone from.

When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_vm_info. Required with state=[‘clone’, ‘instant_clone’]

state

string

Choices:

  • "absent"

  • "clone"

  • "instant_clone"

  • "present" ← (default)

  • "register"

  • "relocate"

  • "unregister"

storage_policy

dictionary

The storage_policy_spec structure contains information about the storage policy that is to be associated with the virtual machine home (which contains the configuration and log files).

If unset the datastore default storage policy (if applicable) is applied. Currently a default storage policy is only supported by object datastores : VVol and vSAN. For non-object datastores, if unset then no storage policy would be associated with the virtual machine home. Required with state=[‘present’]

Valid attributes are:

  • policy (str): Identifier of the storage policy which should be associated with the virtual machine.

When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_storage_policies_info. ([‘present’])

This key is required with [‘present’].

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_rest_log_file

string

You can use this optional parameter to set the location of a log file.

This file will be used to record the HTTP REST interaction.

The file will be stored on the host that runs the module.

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 be unregistered.

The parameter must be the id of a resource returned by vmware.vmware_rest.vcenter_vm_info. Required with state=[‘absent’, ‘relocate’, ‘unregister’]

Notes

Note

  • Tested on vSphere 7.0.3

Examples

- name: Create a VM
  vmware.vmware_rest.vcenter_vm:
    placement:
      cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/my_dc/host/my_cluster') }}"
      datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/rw_datastore') }}"
      folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}"
      resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}"
    name: test_vm1
    guest_OS: RHEL_7_64
    hardware_version: VMX_11
    memory:
      hot_add_enabled: true
      size_MiB: 1024
  register: my_vm

- name: Create a VM
  vmware.vmware_rest.vcenter_vm:
    placement:
      cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/my_dc/host/my_cluster') }}"
      datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/local') }}"
      folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}"
      resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}"
    name: test_vm1
    guest_OS: RHEL_7_64
    hardware_version: VMX_11
    memory:
      hot_add_enabled: true
      size_MiB: 1024
    disks:
    - type: SATA
      backing:
        type: VMDK_FILE
        vmdk_file: '[local] test_vm1/{{ disk_name }}.vmdk'
    - type: SATA
      new_vmdk:
        name: second_disk
        capacity: 32000000000
    cdroms:
    - type: SATA
      sata:
        bus: 0
        unit: 2
    nics:
    - backing:
        type: STANDARD_PORTGROUP
        network: "{{ lookup('vmware.vmware_rest.network_moid', '/my_dc/network/VM Network') }}"
  register: my_vm

- name: Create a content library based on a DataStore
  vmware.vmware_rest.content_locallibrary:
    name: my_library_on_datastore
    description: automated
    publish_info:
      published: true
      authentication_method: NONE
    storage_backings:
    - datastore_id: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/local') }}"
      type: DATASTORE
    state: present
  register: nfs_lib

- name: Get the list of items of the NFS library
  vmware.vmware.content_library_item_info:
    library_id: '{{ nfs_lib.id }}'
  register: lib_items

- name: Use the name to identify the item
  set_fact:
    my_template_item: "{{ lib_items.value | selectattr('name', 'equalto', 'golden-template')|first }}"

- name: Deploy a new VM based on the template
  vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
    name: vm-from-template
    library: '{{ nfs_lib.id }}'
    template_library_item: '{{ my_template_item.id }}'
    placement:
      cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/my_dc/host/my_cluster') }}"
      folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}"
      resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}"
    state: deploy
  register: my_new_vm

- name: Retrieve all the details about the new VM
  vmware.vmware_rest.vcenter_vm:
    vm: '{{ my_new_vm.value }}'
  register: my_new_vm_info

- name: Create an instant clone of a VM
  vmware.vmware_rest.vcenter_vm:
    placement:
      datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/local') }}"
      folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}"
      resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}"
    source: '{{ my_vm.id }}'
    name: test_vm2
    state: instant_clone
  register: my_instant_clone

- name: Create a clone of a VM
  vmware.vmware_rest.vcenter_vm:
    placement:
      datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/local') }}"
      folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}"
      resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}"
    source: '{{ my_vm.id }}'
    name: test_vm3
    state: clone
  register: my_clone_vm

- name: Build a list of all the clusters
  vmware.vmware_rest.vcenter_cluster_info:
  register: all_the_clusters

- name: Retrieve details about the first cluster
  vmware.vmware_rest.vcenter_cluster_info:
    cluster: '{{ all_the_clusters.value[0].cluster }}'
  register: my_cluster_info

- name: Build a list of all the folders with the type VIRTUAL_MACHINE and called vm
  vmware.vmware_rest.vcenter_folder_info:
    filter_type: VIRTUAL_MACHINE
    filter_names:
    - vm
  register: my_folders

- name: Set my_virtual_machine_folder
  ansible.builtin.set_fact:
    my_virtual_machine_folder: '{{ my_folders.value|first }}'

- name: Create a VM
  vmware.vmware_rest.vcenter_vm:
    placement:
      cluster: '{{ my_cluster_info.id }}'
      datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/local') }}"
      folder: '{{ my_virtual_machine_folder.folder }}'
      resource_pool: '{{ my_cluster_info.value.resource_pool }}'
    name: test_vm1
    guest_OS: DEBIAN_7_64
    hardware_version: VMX_10
    memory:
      hot_add_enabled: true
      size_MiB: 1024
  register: my_vm

Return Values

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

Key

Description

id

string

moid of the resource

Returned: On success

Sample: "vm-1104"

value

dictionary

Create an instant clone of a VM

Returned: On success

Sample: {"boot": {"delay": 0, "enter_setup_mode": 0, "retry": 0, "retry_delay": 10000, "type": "BIOS"}, "boot_devices": [], "cdroms": {"16002": {"allow_guest_control": 0, "backing": {"auto_detect": 1, "device_access_type": "EMULATION", "type": "HOST_DEVICE"}, "label": "CD/DVD drive 1", "sata": {"bus": 0, "unit": 2}, "start_connected": 0, "state": "NOT_CONNECTED", "type": "SATA"}}, "cpu": {"cores_per_socket": 1, "count": 1, "hot_add_enabled": 0, "hot_remove_enabled": 0}, "disks": {"16000": {"backing": {"type": "VMDK_FILE", "vmdk_file": "[local] test_vm2/test_vm2_2.vmdk"}, "capacity": 16106127360, "label": "Hard disk 1", "sata": {"bus": 0, "unit": 0}, "type": "SATA"}, "16001": {"backing": {"type": "VMDK_FILE", "vmdk_file": "[local] test_vm2/test_vm2_1.vmdk"}, "capacity": 32000000000, "label": "Hard disk 2", "sata": {"bus": 0, "unit": 1}, "type": "SATA"}}, "floppies": {}, "guest_OS": "RHEL_7_64", "hardware": {"upgrade_policy": "NEVER", "upgrade_status": "NONE", "version": "VMX_11"}, "identity": {"bios_uuid": "4231bf8b-3cb4-3a3f-1bfb-18c857ce95b6", "instance_uuid": "5031b322-6030-a020-8e73-1a9ad0fd03ce", "name": "test_vm2"}, "instant_clone_frozen": 0, "memory": {"hot_add_enabled": 1, "hot_add_increment_size_MiB": 128, "hot_add_limit_MiB": 3072, "size_MiB": 1024}, "name": "test_vm2", "nics": {"4000": {"allow_guest_control": 0, "backing": {"network": "network-1095", "network_name": "VM Network", "type": "STANDARD_PORTGROUP"}, "label": "Network adapter 1", "mac_address": "00:50:56:b1:26:0c", "mac_type": "ASSIGNED", "pci_slot_number": 160, "start_connected": 0, "state": "NOT_CONNECTED", "type": "VMXNET3", "upt_compatibility_enabled": 0, "wake_on_lan_enabled": 0}}, "nvme_adapters": {}, "parallel_ports": {}, "power_state": "POWERED_ON", "sata_adapters": {"15000": {"bus": 0, "label": "SATA controller 0", "pci_slot_number": 32, "type": "AHCI"}}, "scsi_adapters": {}, "serial_ports": {}}

Authors

  • Ansible Cloud Team (@ansible-collections)