vmware.vmware.vm module – Create, update, or delete a virtual machine.

Note

This module is part of the vmware.vmware collection (version 2.5.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.

To use it in a playbook, specify: vmware.vmware.vm.

Synopsis

  • This module is used to create, update, or delete virtual machines.

  • Although this module will attempt to validate your configuration, it is not feasible to validate all possible combinations of parameters. You may encounter errors when starting VMs with invalid configurations.

  • Error messages may not always be very helpful. Checking the vCenter task logs or VM edit settings page may have additional messages.

Parameters

Parameter

Comments

allow_power_cycling

boolean

Whether to allow the VM to be powered off and on when required by the changes detected by the module.

For example, if the module detects CPU changes and hot add is not enabled, you can enable this parameter to allow the VM to be powered off, updated, and then powered on automatically.

If this is set to false, a failure will occur if the VM needs to be powered off before changes can be applied.

A “hard” power off is performed when the VM is powered off. If you do not want this, you could use this module in check mode, vmware.vmware.vm_powerstate module to power off the VM if needed, and then this module again to apply the changes.

Choices:

  • false ← (default)

  • true

cdroms

list / elements=dictionary

CD-ROMs to manage on the VM.

The order of this list does matter, since you cannot specify the CDROM index number in vSphere. In other words, the first CDROM in this list will always manage the first CDROM on the VM.

client_device_mode

string

The mode of the CD-ROM when acting as a client device.

One of cdroms[].iso_media_path or cdroms[].client_device_mode must be set.

If this is not set and the CD-ROM is being created, passthrough will be used.

passthrough is similar to the ‘client’ mode in the community.vmware.vmware_guest module.

Choices:

  • "passthrough"

  • "emulated"

connect_at_power_on

boolean

Whether to connect the CD-ROM to the VM at power on.

This parameter is ignored if client_device_mode is set.

If this is set to true, the CD-ROM will be connected to the VM at power on.

If this is set to false, the CD-ROM will remain disconnected from the VM at power on.

Choices:

  • false

  • true

device_node

string / required

Specifies the controller, bus, and unit number of the CD-ROM. Only SATA and IDE controllers are supported.

The format of this value should be like ‘SATA(0:0)’ or ‘IDE(0:1)’.

CD-ROM controllers referenced in this attribute must be configured in the corresponding controller section. The exception to this are the two IDE controllers, which are automatically added to the VM.

The device node should be unique across all other devices (CD-ROMs, disks, etc.) on the VM.

iso_media_path

string

The ISO media path to use for the CD-ROM. This must be a valid datastore path that is accessible to the host of the VM.

One of cdroms[].iso_media_path or cdroms[].client_device_mode must be set.

A datastore path should be like ‘[my-datastore-name] some/folder/path/My.iso’.

A content library item can be referenced by its full datastore path only.

cdroms_remove_unmanaged

boolean

Whether to remove CD-ROMs that are not specified in the cdroms parameter.

If this is set to true, any CD-ROMs that are not specified in the cdroms parameter will be removed.

If this is set to false, the module will ignore CD-ROMs that are not specified in the cdroms parameter.

Choices:

  • false

  • true ← (default)

cluster

aliases: cluster_name

string

The cluster in which to place the VM.

This is required when creating a new VM.

You cannot use this module to modify the placement of a VM once it has been created. This parameter is ignored if the VM already exists.

cpu

dictionary

Options related to CPU resource allocation.

This is required when creating a new VM.

cores

integer

The number of CPU cores to add to the VM.

This is required when creating a new VM.

cores_per_socket

integer

The number of cores per socket to use for the VM.

If this is defined, cpu.cores must be a multiple of cpu.cores_per_socket.

enable_hot_add

boolean

Whether to enable CPU hot add. This allows you to add CPUs to the VM while it is powered on.

Encryption (vm_options.enable_encryption) cannot be enabled if CPU hot-add is enabled. You must disable CPU hot-add in a separate module call before you can attempt to enable encryption.

Choices:

  • false

  • true

enable_hot_remove

boolean

Whether to enable CPU hot remove. This allows you to remove CPUs from the VM while it is powered on.

Encryption (vm_options.enable_encryption) cannot be enabled if CPU hot-remove is enabled. You must disable CPU hot-remove in a separate module call before you can attempt to enable encryption.

Choices:

  • false

  • true

enable_performance_counters

boolean

Whether to enable Virtual CPU Performance Monitoring Counters (VPMC).

Choices:

  • false

  • true

limit

integer

The maximum amount of CPU resources (Mhz) the VM can use.

reservation

integer

The amount of CPU resource (Mhz) that is guaranteed available to the virtual machine.

shares

integer

The custom number of shares of CPU allocated to this virtual machine.

You can set cpu.shares_level and omit this parameter to use a pre-defined value.

If this is defined, cpu.shares_level will be ignored.

shares_level

string

The allocation level of CPU resources for the virtual machine.

If cpu.shares is defined, cpu.shares_level will automatically be set to ‘custom’ and this parameter will be ignored.

Choices:

  • "low"

  • "normal"

  • "high"

datacenter

aliases: datacenter_name

string

The datacenter in which to place the VM.

This is required when creating a new VM.

You cannot use this module to modify the placement of a VM once it has been created. This parameter is ignored if the VM already exists.

datastore

string

The datastore on which to place the VM.

This is required when creating a new VM, or when creating new disks.

You cannot use this module to modify the placement of a VM once it has been created. This parameter is ignored if the VM or disk already exists.

datastore_cluster

string

The datastore cluster on which to place the VM.

This is required when creating a new VM.

This is required when creating a new VM, or when creating new disks.

You cannot use this module to modify the placement of a VM once it has been created. This parameter is ignored if the VM or disk already exists.

delete_from_inventory

boolean

Whether to delete the VM from the datastore when removing it, or just remove the VM from the vSphere inventory.

If this is set to true, the VM will be deleted from the datastore when it is removed.

If this is set to false, the VM will remain on the datastore when it is removed.

This parameter is only used when state is set to absent.

Choices:

  • false ← (default)

  • true

disks

list / elements=dictionary

Disks to manage on the VM.

Reducing disk size is not supported.

At least one disk is required when creating a new VM.

Controllers (except IDE) referenced by the disks[].device_node parameter must be configured in the corresponding controller section.

datastore

string

The datastore or datastore cluster where this disk should be stored. The host that the VM is running on must have access to this datastore.

This can be a name or a MOID. If using a name, the first datastore (or cluster) that matches the name will be used.

If this is not specified, the disk will be created on the same datastore as the VM.

This is only used when creating a new disk. If it is specified for an existing disk, it is ignored.

Only one of disks[].datastore or disks[].filename can be set.

device_node

string / required

Specifies the controller, bus, and unit number of the disk.

The format of this value should be like ‘SCSI(0:0)’ or ‘IDE(0:1)’.

Disk controllers referenced in this attribute must be configured in the corresponding controller section. The exception to this are the two IDE controllers, which are automatically added to the VM.

enable_sharing

boolean

If true, disk sharing will be enabled. This enabled multi-writer mode, allowing multiple VMs to write to the same disk.

If false, disk sharing will be disabled. This will cause the disk to be exclusive to the VM.

If this is not specified, new disks will be created with sharing disabled.

Sharing depends on the storage backing type. If your storage does not support sharing, enabling sharing will cause the module to fail with an incompatible device backing error.

Choices:

  • false

  • true

filename

string

The filename of an existing disk to attach to the VM. This file must already exist on the datastore.

This is only used when creating a new disk. If it is specified for an existing disk, it is ignored.

An example filename is ‘[my-datastore-name] some/folder/path/My.vmdk’.

Only one of disks[].datastore or disks[].filename can be set.

mode

string

The mode of the disk. Supported values are dependent on the disk storage location.

persistent is supported by all disk backing types. In the UI, this is called “dependent”.

persistent means changes are immediately and permanently written to the virtual disk.

independent_persistent means the same as persistent, but not affected by snapshots.

independent_nonpersistent means the same as nonpersistent, but not affected by snapshots.

append means changes are not written to the virtual disk.

nonpersistent means changes to virtual disk are made to a redo log and discarded at power off.

undoable means changes are made to a redo log, but you are given the option to commit or undo.

If this is not specified, new disks will be created with persistent mode.

If you chose a mode that is not supported by the disk storage type, the module will fail with an incompatible device backing error.

Choices:

  • "persistent"

  • "independent_persistent"

  • "independent_nonpersistent"

  • "append"

  • "nonpersistent"

  • "undoable"

provisioning

string

The provisioning type for the disk.

This is only used when creating a new disk. If it is specified for an existing disk, it is ignored.

Choices:

  • "thin"

  • "thick"

  • "eagerzeroedthick"

size

string / required

The size of the disk.

The format of this value should be like ‘100gb’ or ‘100mb’.

Supported units are ‘kb’, ‘mb’, ‘gb’, ‘tb’.

Note that disk size cannot be decreased at any time.

disks_detach_only

boolean

Whether to detach disks that are to be removed, or delete them entirely.

If this is set to true, any disks that are removed will be detached from the VM but remain on the datastore.

If this is set to false, any disks that are removed will be deleted from the datastore.

This parameter only applies to individual disk removal. If the entire VM is being removed, this parameter is ignored and delete_from_inventory is used instead.

Choices:

  • false ← (default)

  • true

disks_remove_unmanaged

boolean

Whether to remove disks that are not specified in the disks parameter.

If this is set to true, any disks that are not specified in the disks parameter will be removed.

If this is set to false, the module will ignore disks that are not specified in the disks parameter.

Choices:

  • false

  • true ← (default)

esxi_host

string

The ESXi host on which to place the VM.

This is required when creating a new VM.

You cannot use this module to modify the placement of a VM once it has been created. This parameter is ignored if the VM already exists.

folder

aliases: vm_folder

string

Destination folder, absolute or relative path to find an existing guest.

Should be the full folder path, with or without the ‘datacenter/vm/’ prefix

For example ‘datacenter_name/vm/path/to/folder’ or ‘path/to/folder’.

You cannot use this module to modify the placement of a VM once it has been created.

guest_id

string

The guest ID of the VM.

Guest IDs are pre-defined by VMware. For example see https://developer.broadcom.com/xapis/vsphere-web-services-api/latest/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html

This is required when creating a new VM.

hardware_version

integer

Specify the hardware version for the new VM. This value should be an integer, where the actual version is ‘vmx-<value>’.

This parameter is ignored if the VM already exists. Upgrading hardware version is not supported in this module.

If this is not specified, the highest available hardware version will be used.

Your environment must support the hardware version you specify. Specifying an unsupported hardware version will cause a vSphere error when deploying the VM.

hostname

string

The hostname or IP address of the vSphere vCenter server.

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

memory

dictionary

Options related to memory resource allocation.

This is required when creating a new VM.

enable_hot_add

boolean

Whether to enable memory hot add. This allows you to add memory to the VM while it is powered on.

Encryption (vm_options.enable_encryption) cannot be enabled if memory hot-add is enable. You must disable memory hot-add in a separate module call before you can attempt to enable encryption.

Choices:

  • false

  • true

limit

integer

The maximum amount of memory the VM can use.

reservation

integer

The amount of memory resource that is guaranteed available to the VM.

Only one of memory.reservation or memory.reserve_all_memory can be set.

This value must be less than or equal to the VMs total memory in MB.

reserve_all_memory

boolean

Whether to reserve (lock) all memory allocated for the VM.

Only one of memory.reservation or memory.reserve_all_memory can be set.

This will cause VMware to reserve all memory allocated for the VM, meaning that the memory will not be available to other VMs even if this VM is not actively using it.

Choices:

  • false

  • true

shares

integer

The custom number of shares of memory allocated to this virtual machine.

You can set memory.shares_level and omit this parameter to use a pre-defined value.

If this is defined, memory.shares_level will be ignored.

shares_level

string

The allocation level of memory resources for the virtual machine.

If memory.shares is defined, memory.shares_level will automatically be set to ‘custom’ and this parameter will be ignored.

Choices:

  • "low"

  • "normal"

  • "high"

size_mb

integer

The amount of memory in mb to add to the VM.

Memory cannot be changed while the VM is powered on, unless memory hot add is already enabled.

This parameter is required when creating a new VM.

moid

string

Managed Object ID of the instance to manage if known, this is a unique identifier only within a single vCenter instance.

This is required if name or uuid is not supplied.

name

string

Name of the virtual machine to manage.

Virtual machine names in vCenter are not necessarily unique, which may be problematic, see name_match.

This is required when the VM does not exist, or if moid or uuid is not supplied.

name_match

string

If multiple virtual machines matching the name, use the first or last found.

Choices:

  • "first" ← (default)

  • "last"

network_adapters

list / elements=dictionary

A list of network adapters to manage on the VM.

Due to limitations in the VMware API, you cannot change the type of a network adapter once it has been created using this module.

The order of this list does matter, since you cannot specify the network adapter index number in vSphere. In other words, the first network adapter in this list will always manage the network adapter assigned to index 0.

The network adapter types defined in this parameter must match the types of any existing adapters on the VM, in the same order that they are specified. For example, the first adapter in this list must have the same type as the first adapter attached to the VM (if one exists).

Any adapters in this list that do not exist on the VM will be created.

Portgroups must already exist; this module does not create them.

adapter_type

string

The type of the adapter.

This is required when creating a new adapter.

Note that this cannot be changed once the adapter has been created.

Choices:

  • "e1000"

  • "e1000e"

  • "pcnet32"

  • "vmxnet2"

  • "vmxnet3"

  • "sriov"

connect_at_power_on

boolean

Specifies whether or not to connect the network adapter when the virtual machine starts.

Choices:

  • false

  • true

connected

boolean

Indicates whether the NIC is currently connected.

Choices:

  • false

  • true

limit

integer

The maximum amount of network resources the network adapter can use.

The unit is Mbps.

mac_address

string

The MAC address of the network adapter.

If you want to use a generated or automatic mac address, set this to ‘automatic’.

If not specified and this is a new adapter, a random MAC address will be assigned.

If not specified and this is an existing adapter, the MAC address will not be changed.

network

string / required

The name or MOID of the standard or distributed virtual portgroup for this interface.

The portgroup must already exist.

reservation

integer

The amount of network resources reserved for the network adapter.

The unit is Mbps.

shares

integer

The percentage of network resources allocated to the network adapter.

If setting this, it should be between 0 and 100.

Only one of network_adapters[].shares or network_adapters[].shares_level can be set.

shares_level

string

The pre-defined allocation level of network resources for the network adapter.

Only one of network_adapters[].shares or network_adapters[].shares_level can be set.

Choices:

  • "low"

  • "normal"

  • "high"

network_adapters_remove_unmanaged

boolean

Whether to remove network adapters that are not specified in the network_adapters parameter.

If this is set to true, any network adapters that are not specified in the network_adapters parameter will be removed.

If this is set to false, the module will ignore network adapters beyond those listed in the network_adapters parameter.

If you do not specify network_adapters at all, no devices will be removed regardless of the value of this parameter.

Choices:

  • false

  • true ← (default)

nvdimms

list / elements=dictionary

A list of non-volatile DIMMs to manage on the VM.

Any NVDIMMs in this list that do not exist on the VM will be created.

If any NVDIMMs are specified, the module will automatically add and manage a NVDIMM controller on the VM. If you remove all NVDIMMs, the NVDIMM controller will be removed as well.

You must have a PMem datastore selected for the host that the VM is running on before adding NVDIMMs to the VM.

size_mb

integer / required

The amount of memory to add to the VM.

Memory cannot be changed while the VM is powered on, unless memory hot add is already enabled.

This parameter is required when creating a new VM.

nvdimms_remove_unmanaged

boolean

Whether to remove NVDIMMs that are not specified in the nvdimms parameter.

If this is set to true, any NVDIMMs that are not specified in the nvdimms parameter will be removed.

If this is set to false, the module will ignore NVDIMMs beyond those listed in the nvdimms parameter.

Choices:

  • false

  • true ← (default)

nvme_controllers

list / elements=dictionary

NVMe device controllers to manage on the VM.

If a controller is not specified, it will be removed from the VM.

You may only specify four NVMe controllers per VM.

The order of this list does not matter, i.e. you may specify bus numbers out of order and do not need to specify all bus numbers (See nvme_controllers_remove_unmanaged).

Valid unit numbers for NVMe controllers are 0-63.

bus_number

integer / required

The bus number of the NVMe controller. This is used to identify the controller and is required.

Valid bus numbers are 0 to 3, inclusive.

bus_sharing

string

The bus sharing mode of the controller.

If this is not set, noSharing will be used for new controllers.

Choices:

  • "noSharing"

  • "physicalSharing"

nvme_controllers_remove_unmanaged

boolean

Whether to remove NVMe controllers that are not specified in the nvme_controllers parameter.

If this is set to true, any NVMe controllers that are not specified in the nvme_controllers parameter will be removed.

If this is set to false, the module will ignore NVMe controllers that are not specified in the nvme_controllers parameter.

Choices:

  • false

  • true ← (default)

password

aliases: pass, pwd

string

The password of the vSphere vCenter server.

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

port

integer

The port number of the vSphere vCenter server.

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

Default: 443

proxy_host

string

The 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 VMWARE_PROXY_HOST will be used instead.

proxy_port

integer

The 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 VMWARE_PROXY_PORT will be used instead.

resource_pool

string

The resource pool in which to place the VM.

This is required when creating a new VM.

You cannot use this module to modify the placement of a VM once it has been created. This parameter is ignored if the VM already exists.

sata_controllers

list / elements=dictionary

SATA controllers to manage on the VM.

You may only specify four SATA controllers per VM.

Valid unit numbers for SATA controllers are 0-29.

The order of this list does not matter, i.e. you may specify bus numbers out of order and do not need to specify all bus numbers (See sata_controllers_remove_unmanaged).

bus_number

integer / required

The bus number of the SATA controller. This is used to identify the controller and is required.

Valid bus numbers are 0 to 3, inclusive.

sata_controllers_remove_unmanaged

boolean

Whether to remove SATA controllers that are not specified in the sata_controllers parameter.

If this is set to true, any SATA controllers that are not specified in the sata_controllers parameter will be removed.

If this is set to false, the module will ignore SATA controllers that are not specified in the sata_controllers parameter.

Choices:

  • false

  • true ← (default)

scsi_controllers

list / elements=dictionary

SCSI device controllers to manage on the VM.

If a controller is not specified, it will be removed from the VM.

You may only specify four SCSI controllers per VM.

The order of this list does not matter, i.e. you may specify bus numbers out of order and do not need to specify all bus numbers (See scsi_controllers_remove_unmanaged).

Valid unit numbers for SCSI controllers are 0-15, except for the reserved unit 7.

bus_number

integer / required

The bus number of the SCSI controller. This is used to identify the controller and is required.

Valid bus numbers are 0 to 3, inclusive.

bus_sharing

string

The bus sharing mode of the controller.

If this is not set, noSharing will be used for new controllers.

Choices:

  • "noSharing"

  • "virtualSharing"

  • "physicalSharing"

controller_type

string / required

The sub-type of the SCSI controller.

Changing the type essentially removes the old controller and adds a new one in its place. Your VM should be powered off and dependent devices should support this kind of change.

Choices:

  • "lsilogic"

  • "paravirtual"

  • "buslogic"

  • "lsilogicsas"

scsi_controllers_remove_unmanaged

boolean

Whether to remove SCSI controllers that are not specified in the scsi_controllers parameter.

If this is set to true, any SCSI controllers that are not specified in the scsi_controllers parameter will be removed.

If this is set to false, the module will ignore SCSI controllers that are not specified in the scsi_controllers parameter.

Choices:

  • false

  • true ← (default)

state

string

Whether to ensure the VM is present or absent.

Choices:

  • "present" ← (default)

  • "absent"

timeout

integer

The timeout in seconds for the module to wait for the VM to be created or updated.

Default: 600

usb_controllers

list / elements=dictionary

USB device controllers to manage on the VM.

You may only specify two USB controllers per VM, and only one of each type.

The order of this list does matter, since you cannot specify the controller/bus number in vSphere. In other words, the first controller in this list will always manage the controller assigned to bus 0.

The ESXi host that the VM is running on must have the required hardware and firmware to support the USB controller type.

controller_type

string / required

The type of the USB controller.

Choices:

  • "usb2"

  • "usb3"

usb_controllers_remove_unmanaged

boolean

Whether to remove USB controllers that are not specified in the usb_controllers parameter.

If this is set to true, any USB controllers that are not specified in the usb_controllers parameter will be removed.

If this is set to false, the module will ignore USB controllers beyond those listed in the usb_controllers parameter.

Choices:

  • false

  • true ← (default)

use_instance_uuid

boolean

Whether to use the VMware instance UUID rather than the BIOS UUID.

Choices:

  • false ← (default)

  • true

username

aliases: admin, user

string

The username of the vSphere vCenter server.

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

uuid

string

UUID of the instance to manage if known, this is VMware’s unique identifier.

This is required if name or moid is not supplied.

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_options

dictionary

Advanced and miscellaneous options for the VM, including things like BIOS settings, remote console settings, and encryption settings.

boot_firmware

string

The boot firmware to use for the VM.

Encryption (vm_options.enable_encryption) can only be enabled when boot firmware is EFI.

Choices:

  • "bios"

  • "efi"

enable_encryption

boolean

Whether to enable encryption for the VM.

If this is set to false, you can still modify vm_options.encrypted_vmotion and vm_options.encrypted_fault_tolerance, but those settings will have no effect on the VM.

Secure boot (vm_options.enable_secure_boot) is not compatible with encryption.

Encryption requires EFI boot firmware (vm_options.boot_firmware).

Memory hot-add (memory.enable_hot_add) and CPU hot-add/hot-remove (cpu.enable_hot_add or cpu.enable_hot_remove) must be disabled before you can enable encryption.

Choices:

  • false

  • true

enable_hardware_assisted_virtualization

boolean

Whether to enable hardware assisted virtualization.

If true, the VM will be able to use hardware assisted, or nested, virtualization.

Choices:

  • false

  • true

enable_io_mmu

boolean

Whether to enable IO Memory Management Unit (IO MMU).

Choices:

  • false

  • true

enable_secure_boot

boolean

Whether to enable secure boot for the VM.

Only (U)EFI boot firmware is supported.

Secure boot cannot be enabled if encryption (vm_options.enable_encryption) is also enabled.

Choices:

  • false

  • true

enable_virtual_based_security

boolean

Whether to enable the Virtualization Based Security feature for Windows on at least ESXi 6.7, hardware version 14.

Supported Guest OS are Windows 10 64 bit, Windows Server 2016, Windows Server 2019 and later.

The firmware of virtual machine must be EFI and secure boot must be enabled.

Virtualization Based Security depends on nested virtualization and Intel Virtualization Technology for Directed I/O.

Choices:

  • false

  • true

encrypted_fault_tolerance

string

Modify how the VM’s Fault Tolerance (FT) replication is encrypted, if encryption is enabled.

disabled means do not turn on encrypted Fault Tolerance (FT) replication logging.

opportunistic means turn on encryption only if both sides are capable. The VM is allowed to move to an older host that does not support encrypted FT logging.

required means run on primary/secondary FT hosts such that both hosts support encrypted FT logging.

Choices:

  • "disabled"

  • "opportunistic"

  • "required"

encrypted_vmotion

string

Modify how the VM can be migrated using vMotion, if encryption is enabled.

disabled means do not use encrypted vMotion, even if available.

opportunistic means use encrypted vMotion if source and destination hosts support it, fall back to unencrypted vMotion otherwise.

required means allow only encrypted vMotion. If the source or destination host does not support vMotion encryption, do not allow the vMotion to occur.

Choices:

  • "disabled"

  • "opportunistic"

  • "required"

maximum_remote_console_sessions

integer

The maximum number of remote console sessions that can be established to the VM.

Must be a value between 0 and 40

Notes

Note

  • All modules require API write access and hence are not supported on a free ESXi license.

  • All variables and VMware object names are case sensitive.

  • Modules may rely on the ‘requests’ python library, which does not use the system certificate store by default. You can specify the certificate store by setting the REQUESTS_CA_BUNDLE environment variable. Note having this variable set may cause a ‘false’ value for the ‘validate_certs’ option to be ignored in some cases. Example: ‘export REQUESTS_CA_BUNDLE=/path/to/your/ca_bundle.pem’

Examples

- name: Create a VM
  vmware.vmware.vm:
    name: my-new-vm
    datacenter: DC01
    cluster: Cluster01
    datastore: Datastore01
    guest_id: amazonlinux3_64Guest
    cpu:
      cores: 4
      cores_per_socket: 2
      enable_hot_add: true
      enable_hot_remove: true
    memory:
      size_mb: 8096
      enable_hot_add: true
      reserve_all_memory: true
    disks:
      - size: 80gb
        provisioning: thin
        device_node: SCSI(0:0)
      - size: 10gb
        provisioning: thick
        device_node: SCSI(0:1)
      - size: 1tb
        provisioning: thin
        device_node: SCSI(1:0)
        datastore: ArchiveDatastore
    scsi_controllers:
      - controller_type: paravirtual
        bus_number: 0
      - controller_type: paravirtual
        bus_number: 1
        bus_sharing: virtualSharing
    sata_controllers:
      - bus_number: 0
    cdroms:
      - connect_at_power_on: true
        iso_media_path: '[ISODS01] OS/Linux/RHEL-9.iso'
        device_node: SATA(0:0)
      - client_device_mode: passthrough
        device_node: IDE(0:0)
    network_adapters:
      - network: VM Network
        adapter_type: vmxnet3
        connected: true
        connect_at_power_on: true
      - network: Management
        adapter_type: vmxnet3
        connected: true
        connect_at_power_on: true
        mac_address: 11:11:11:11:11:11
    vm_options:
      maximum_remote_console_sessions: 10
      enable_io_mmu: true
      boot_firmware: efi
      enable_hardware_assisted_virtualization: true
  register: _new_vm

- name: Power on VM
  vmware.vmware.vm_powerstate:
    moid: "{{ _new_vm.vm.moid }}"
    datacenter: DC01
    state: powered-on


- name: Add additional network adapter to VM
  vmware.vmware.vm:
    moid: "{{ _new_vm.vm.moid }}"
    network_adapters:
      - network: VM Network
        adapter_type: vmxnet3
      - network: Management
        adapter_type: vmxnet3
      - network: Legacy
        adapter_type: e1000e

- name: Change second adapter shares without removing the new adapter
  vmware.vmware.vm:
    moid: "{{ _new_vm.vm.moid }}"
    network_adapter_remove_unmanaged: false
    network_adapters:
      - network: VM Network
        adapter_type: vmxnet3
      - network: Management
        adapter_type: vmxnet3
        shares: 50


- name: Update resources with a reboot, if needed
  vmware.vmware.vm:
    moid: "{{ _new_vm.vm.moid }}"
    allow_power_cycling: true
    cpu:
      cores: 16
    memory:
      size_mb: 16384


- name: Delete VM
  vmware.vmware.vm:
    moid: "{{ _new_vm.vm.moid }}"
    state: absent

Return Values

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

Key

Description

changes

dictionary

A dictionary showing any changes in settings or devices on the VM

If there are no changes, this is an empty dictionary

Returned: On success

Sample: {"changed_parameters": {"cpu.cores": {"new_value": 2, "old_value": 1}, "memory.size_mb": {"new_value": 1024, "old_value": 2048}, "name": {"new_value": "my-new-vm", "old_value": "foo"}}, "objects_to_add": [{"bus_number": 0, "device_class": "<class 'pyVmomi.VmomiSupport.vim.vm.device.VirtualIDEController'>", "device_type": "ide", "object_type": "controller", "used_unit_numbers": []}, {"bus_number": 1, "device_class": "<class 'pyVmomi.VmomiSupport.vim.vm.device.VirtualIDEController'>", "device_type": "ide", "object_type": "controller", "used_unit_numbers": []}], "objects_to_remove": [], "objects_to_update": [{"controller": "BUSLOGIC(0:)", "datastore": "N/A", "mode": "persistent", "object_type": "virtual disk", "provisioning": "thin", "size": 10485760, "unit_number": 0}, {"bus_number": 0, "device_class": "<class 'pyVmomi.VmomiSupport.vim.vm.device.VirtualBusLogicController'>", "device_type": "buslogic", "object_type": "controller", "used_unit_numbers": [0]}]}

power_cycled_for_update

boolean

Whether the VM was powered cycled to apply the update.

This is always returned, but always false for create and delete operations.

Returned: On success

Sample: true

vm

dictionary

Information about the target VM

Returned: On success

Sample: {"moid": "vm-79828,", "name": "test-d9c1-vm"}

Authors

  • Ansible Cloud Team (@ansible-collections)