vmware.vmware_rest.vcenter_vm module – Creates a virtual machine.
Note
This module is part of the vmware.vmware_rest collection (version 2.2.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
.
New in version 0.1.0: of vmware.vmware_rest
Requirements
The below requirements are needed on the host that executes this module.
vSphere 7.0.2 or greater
python >= 3.6
aiohttp
Parameters
Parameter |
Comments |
---|---|
128-bit SMBIOS UUID of a virtual machine represented as a hexadecimal string in “12345678-abcd-1234-cdef-123456789abc” format. |
|
Boot configuration. Valid attributes are:
|
|
Boot device configuration. Valid attributes are:
|
|
List of CD-ROMs. Valid attributes are:
Accepted value for this field:
Accepted value for this field:
|
|
CPU configuration. Valid attributes are:
|
|
Identifier of the datastore on which the virtual machine’s configuration state is stored. |
|
Datastore path for the virtual machine’s configuration file in the format “[datastore name] path”. For example “[storage1] Test-VM/Test-VM.vmx”. |
|
Indicates whether all NICs on the destination virtual machine should be disconnected from the newtwork Choices:
|
|
Individual disk relocation map. Valid attributes are:
Accepted value for this field:
|
|
Set of Disks to Remove. |
|
Map of Disks to Update. |
|
List of floppy drives. Valid attributes are:
Accepted value for this field:
|
|
Guest customization spec to apply to the virtual machine after the virtual machine is deployed. Valid attributes are:
|
|
The Choices:
|
|
The Choices:
|
|
Memory configuration. Valid attributes are:
|
|
Name of the new virtual machine. |
|
List of Ethernet adapters. Valid attributes are:
Accepted value for this field:
|
|
Map of NICs to update. |
|
List of parallel ports. Valid attributes are:
Accepted value for this field:
|
|
Map of parallel ports to Update. |
|
Path to the virtual machine’s configuration file on the datastore corresponding to {@link #datastore). |
|
Virtual machine placement information. Valid attributes are:
|
|
List of SATA adapters. Valid attributes are:
|
|
List of SCSI adapters. Valid attributes are:
|
|
List of serial ports. Valid attributes are:
Accepted value for this field:
|
|
Map of serial ports to Update. |
|
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. |
|
Virtual machine to InstantClone from. Required with state=[‘clone’, ‘instant_clone’] |
|
Choices:
|
|
The Valid attributes are:
|
|
The hostname or IP address of the vSphere vCenter If the value is not specified in the task, the value of environment variable |
|
The vSphere vCenter password If the value is not specified in the task, the value of environment variable |
|
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 run the module. If the value is not specified in the task, the value of environment variable |
|
The vSphere vCenter username If the value is not specified in the task, the value of environment variable |
|
Allows connection when SSL certificates are not valid. Set to If the value is not specified in the task, the value of environment variable Choices:
|
|
Identifier of the virtual machine to be unregistered. Required with state=[‘absent’, ‘relocate’, ‘unregister’] |
Examples
- 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: 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
- name: Collect the list of the existing VM
vmware.vmware_rest.vcenter_vm_info:
register: existing_vms
until: existing_vms is not failed
- name: Delete some VM
vmware.vmware_rest.vcenter_vm:
state: absent
vm: '{{ item.vm }}'
with_items: '{{ existing_vms.value }}'
when:
- not item.name.startswith("vCLS")
- 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 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: DEBIAN_8_64
hardware_version: VMX_11
memory:
hot_add_enabled: true
size_MiB: 1024
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: ds_lib
- name: Create a VM template on the library
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
name: foobar2001
library: '{{ ds_lib.id }}'
source_vm: '{{ my_vm.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')\
\ }}"
register: mylib_item
- name: Deploy a new VM based on the template
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
name: foobar2002
library: '{{ ds_lib.id }}'
template_library_item: '{{ mylib_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
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
Delete some VM Returned: On success Sample: “All items completed” |
|
Delete some VM Returned: On success Sample: [{“_ansible_item_label”: {“cpu_count”: 1, “memory_size_MiB”: 128, “name”: “vCLS-a3e9f505-69fc-43d0-beed-c1a43d06184e”, “power_state”: “POWERED_OFF”, “vm”: “vm-1130”}, “_ansible_no_log”: 0, “ansible_loop_var”: “item”, “changed”: 0, “item”: {“cpu_count”: 1, “memory_size_MiB”: 128, “name”: “vCLS-a3e9f505-69fc-43d0-beed-c1a43d06184e”, “power_state”: “POWERED_OFF”, “vm”: “vm-1130”}, “skip_reason”: “Conditional result was False”, “skipped”: 1}, {“_ansible_item_label”: {“cpu_count”: 1, “memory_size_MiB”: 1024, “name”: “test_vm1”, “power_state”: “POWERED_OFF”, “vm”: “vm-1131”}, “_ansible_no_log”: null, “ansible_loop_var”: “item”, “changed”: 1, “failed”: 0, “invocation”: {“module_args”: {“bios_uuid”: null, “boot”: null, “boot_devices”: null, “cdroms”: null, “cpu”: null, “datastore”: null, “datastore_path”: null, “disconnect_all_nics”: null, “disks”: null, “disks_to_remove”: null, “disks_to_update”: null, “floppies”: null, “guest_OS”: null, “guest_customization_spec”: null, “hardware_version”: null, “memory”: null, “name”: null, “nics”: null, “nics_to_update”: null, “parallel_ports”: null, “parallel_ports_to_update”: null, “path”: null, “placement”: null, “power_on”: null, “sata_adapters”: null, “scsi_adapters”: null, “serial_ports”: null, “serial_ports_to_update”: null, “session_timeout”: null, “source”: null, “state”: “absent”, “storage_policy”: null, “vcenter_hostname”: “vcenter.test”, “vcenter_password”: “VALUE_SPECIFIED_IN_NO_LOG_PARAMETER”, “vcenter_rest_log_file”: null, “vcenter_username”: “administrator@vsphere.local”, “vcenter_validate_certs”: 0, “vm”: “vm-1131”}}, “item”: {“cpu_count”: 1, “memory_size_MiB”: 1024, “name”: “test_vm1”, “power_state”: “POWERED_OFF”, “vm”: “vm-1131”}, “value”: {}}, {“_ansible_item_label”: {“cpu_count”: 1, “memory_size_MiB”: 1024, “name”: “foobar2002”, “power_state”: “POWERED_OFF”, “vm”: “vm-1134”}, “_ansible_no_log”: null, “ansible_loop_var”: “item”, “changed”: 1, “failed”: 0, “invocation”: {“module_args”: {“bios_uuid”: null, “boot”: null, “boot_devices”: null, “cdroms”: null, “cpu”: null, “datastore”: null, “datastore_path”: null, “disconnect_all_nics”: null, “disks”: null, “disks_to_remove”: null, “disks_to_update”: null, “floppies”: null, “guest_OS”: null, “guest_customization_spec”: null, “hardware_version”: null, “memory”: null, “name”: null, “nics”: null, “nics_to_update”: null, “parallel_ports”: null, “parallel_ports_to_update”: null, “path”: null, “placement”: null, “power_on”: null, “sata_adapters”: null, “scsi_adapters”: null, “serial_ports”: null, “serial_ports_to_update”: null, “session_timeout”: null, “source”: null, “state”: “absent”, “storage_policy”: null, “vcenter_hostname”: “vcenter.test”, “vcenter_password”: “VALUE_SPECIFIED_IN_NO_LOG_PARAMETER”, “vcenter_rest_log_file”: null, “vcenter_username”: “administrator@vsphere.local”, “vcenter_validate_certs”: 0, “vm”: “vm-1134”}}, “item”: {“cpu_count”: 1, “memory_size_MiB”: 1024, “name”: “foobar2002”, “power_state”: “POWERED_OFF”, “vm”: “vm-1134”}, “value”: {}}] |
Authors
Ansible Cloud Team (@ansible-collections)