community.vmware.vmware_guest_instant_clone – Instant Clone VM

Note

This plugin is part of the community.vmware collection (version 1.9.0).

To install it use: ansible-galaxy collection install community.vmware.

To use it in a playbook, specify: community.vmware.vmware_guest_instant_clone.

New in version 1.9.0: of community.vmware

Synopsis

Parameters

Parameter Choices/Defaults Comments
datacenter
string / required
Name of the datacenter, where VM to be deployed.
datastore
string / required
The name of the datastore or the datastore cluster.
If datastore cluster name is specified, module will find the Storage DRS recommended datastore in that cluster.
folder
string
Destination folder, absolute path to deploy the cloned vm.
This parameter is case sensitive.
Examples:
folder: ha-datacenter/vm
folder: /datacenter1/vm
host
string / required
Name of the ESX Host in datacenter in which to place cloned VM.
The host has to be a member of the cluster that contains the resource pool.
Required with resource_pool to find resource pool details. This will be used as additional information when there are resource pools with same name.

aliases: esxi_hostname
hostname
string
The hostname or IP address of the vSphere vCenter or ESXi server.
If the value is not specified in the task, the value of environment variable VMWARE_HOST will be used instead.
Environment variable support added in Ansible 2.6.
moid
string
Managed Object ID of the vm instance to manage if known, this is a unique identifier only within a single vCenter instance.
This is required if parent_vm or uuid is not supplied.
name
string / required
Name of the Cloned virtual machine.

aliases: vm_name
parent_vm
string
Name of the parent virtual machine.
This is a required parameter, if parameter uuid or moid is not supplied.
password
string
The password of the vSphere vCenter or ESXi server.
If the value is not specified in the task, the value of environment variable VMWARE_PASSWORD will be used instead.
Environment variable support added in Ansible 2.6.

aliases: pass, pwd
port
integer
Default:
443
The port number of the vSphere vCenter or ESXi server.
If the value is not specified in the task, the value of environment variable VMWARE_PORT will be used instead.
Environment variable support added in Ansible 2.6.
proxy_host
string
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.
This feature depends on a version of pyvmomi greater than v6.7.1.2018.12
proxy_port
integer
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
Name of the resource pool in datacenter in which to place deployed VM.
Required if cluster is not specified.
For default or non-unique resource pool names, specify host and cluster.
Resources is the default name of resource pool.
use_instance_uuid
boolean
    Choices:
  • no ←
  • yes
Whether to use the VMware instance UUID rather than the BIOS UUID.
username
string
The username of the vSphere vCenter or ESXi server.
If the value is not specified in the task, the value of environment variable VMWARE_USER will be used instead.
Environment variable support added in Ansible 2.6.

aliases: admin, user
uuid
string
UUID of the vm instance to clone from, this is VMware's unique identifier.
This is a required parameter, if parameter parent_vm or moid is not supplied.
validate_certs
boolean
    Choices:
  • no
  • yes ←
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.
Environment variable support added in Ansible 2.6.
If set to true, please make sure Python >= 2.7.9 is installed on the given machine.

Examples

- name: Instant Clone a VM
  community.vmware.vmware_guest_instant_clone:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    validate_certs: False
    folder: "{{ f0 }}"
    datastore: "{{ rw_datastore }}"
    datacenter: "{{ dc1 }}"
    host: "{{ esxi1 }}"
    name: "{{ Clone_vm }}"
    parent_vm: "{{ testvm_1 }}"
    resource_pool: "{{ test_resource_001 }}"
  register: vm_clone
  delegate_to: localhost

- name: set state to poweroff the Cloned VM
  community.vmware.vmware_guest_powerstate:
    validate_certs: false
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: "cloned_vm_from_vm_cluster"
    folder: "{{ f0 }}"
    state: powered-off
  register: poweroff_instant_clone_from_vm_when_cluster
  delegate_to: localhost

- name: Clean VM
  community.vmware.vmware_guest:
    validate_certs: false
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: "cloned_vm_from_vm_cluster"
    datacenter: "{{ dc1 }}"
    state: absent
  register: delete_instant_clone_from_vm_when_cluster
  ignore_errors: true
  delegate_to: localhost

- name: Instant Clone a VM when skipping optional params
  community.vmware.vmware_guest_instant_clone:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    validate_certs: False
    name: "{{ Clone_vm }}"
    parent_vm: "{{ testvm_1 }}"
    datacenter: "{{ dc1 }}"
    datastore: "{{ rw_datastore }}"
    host: "{{ esxi1 }}"
  register: VM_clone_optional_arguments
  delegate_to: localhost

- name: Instant clone in check mode
  community.vmware.vmware_guest_instant_clone:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    validate_certs: False
    folder: "{{ f0 }}"
    datastore: "{{ rw_datastore }}"
    datacenter: "{{ dc1 }}"
    host: "{{ esx1 }}"
    name: "{{ Clone_vm }}"
    parent_vm: "{{ testvm_2 }}"
    resource_pool: "{{ test_resource_001 }}"
  check_mode: true
  register: check_mode_clone
  delegate_to: localhost
- debug:
    var: check_mode_clone

Return Values

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

Key Returned Description
vm_info
dictionary
always
metadata about the virtual machine

Sample:
{'datastore': '', 'host': '', 'vcenter': '', 'vm_folder': '', 'vm_name': ''}


Authors

  • Anant Chopra (@Anant99-sys)