community / community.vmware / 2.10.4 / module / vmware_guest_instant_clone Instant Clone VM | "added in version" 1.9.0 of community.vmware" Authors: Anant Chopra (@Anant99-sys)community.vmware.vmware_guest_instant_clone (2.10.4) — module
Install with ansible-galaxy collection install community.vmware:==2.10.4
collections: - name: community.vmware version: 2.10.4
This module can be used for Creating a powered-on Instant Clone of a virtual machine.
All variables and VMware object names are case sensitive.
M(community.vmware.vmware_guest) module is needed for creating a VM with poweredon state which would be used as a parent VM.
M(community.vmware.vmware_guest_powerstate) module is also needed to poweroff the instant cloned module.
The powered off VM would in turn be deleted by again using M(community.vmware.vmware_guest) module.
Thus M(community.vmware.vmware_guest) module is necessary for removing Instant Cloned VM when VMs being created in testing environment.
Also GuestOS Customization has now been added with guestinfo_vars parameter.
The Parent VM must have The Guest customization Engine for instant Clone to customize Guest OS.
Only Linux Os in Parent VM enable support for native vSphere Guest Customization for Instant Clone in vSphere 7.
- 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 with guest_customization community.vmware.vmware_guest_instant_clone: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" vm_username: "root" vm_password: "SuperSecret" validate_certs: False folder: "{{ f0 }}" datastore: "{{ rw_datastore }}" datacenter: "{{ dc1 }}" host: "{{ esxi1 }}" guestinfo_vars: - hostname: "{{ guestinfo.ic.hostname }}" ipaddress: "{{ guestinfo.ic.ipaddress }}" netmask: "{{ guestinfo.ic.netmask }}" gateway: "{{ guestinfo.ic.gateway }}" dns: "{{ guestinfo.ic.dns }}" domain: "{{ guestinfo.ic.domain }}" name: "Instant_clone_guest_customize" parent_vm: "test_vm1" resource_pool: DC0_C0_RP1 register: Instant_cloned_guest_customize 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
host: aliases: - esxi_hostname description: - 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 I(resource_pool) to find resource pool details. This will be used as additional information when there are resource pools with same name. required: true type: str moid: description: - 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 C(parent_vm) or C(uuid) is not supplied. type: str name: aliases: - vm_name description: - Name of the Cloned virtual machine. required: true type: str port: default: 443 description: - The port number of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable C(VMWARE_PORT) will be used instead. - Environment variable support added in Ansible 2.6. type: int uuid: description: - UUID of the vm instance to clone from, this is VMware's unique identifier. - This is a required parameter, if parameter C(parent_vm) or C(moid) is not supplied. type: str folder: description: - Destination folder, absolute path to deploy the cloned vm. - This parameter is case sensitive. - 'Examples:' - 'folder: ha-datacenter/vm' - 'folder: /datacenter1/vm' type: str hostname: description: - 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 C(VMWARE_HOST) will be used instead. - Environment variable support added in Ansible 2.6. type: str password: aliases: - pass - pwd description: - The password of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable C(VMWARE_PASSWORD) will be used instead. - Environment variable support added in Ansible 2.6. type: str username: aliases: - admin - user description: - The username of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable C(VMWARE_USER) will be used instead. - Environment variable support added in Ansible 2.6. type: str datastore: description: - 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. required: true type: str parent_vm: description: - Name of the parent virtual machine. - This is a required parameter, if parameter C(uuid) or C(moid) is not supplied. type: str datacenter: description: - Name of the datacenter, where VM to be deployed. required: true type: str proxy_host: description: - 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 C(VMWARE_PROXY_HOST) will be used instead. - This feature depends on a version of pyvmomi greater than v6.7.1.2018.12 required: false type: str proxy_port: description: - 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 C(VMWARE_PROXY_PORT) will be used instead. required: false type: int vm_password: description: - The password used to login-in to the virtual machine. - Only required when using guest customization feature. required: false type: str vm_username: description: - The user to login-in to the virtual machine. - Only required when using guest customization feature. required: false type: str resource_pool: description: - Name of the resource pool in datacenter in which to place deployed VM. - Required if I(cluster) is not specified. - For default or non-unique resource pool names, specify I(host) and I(cluster). - C(Resources) is the default name of resource pool. required: false type: str wait_vm_tools: default: true description: - Whether waiting until vm tools start after rebooting an instant clone vm. type: bool version_added: 1.12.0 version_added_collection: community.vmware guestinfo_vars: description: - Provides GuestOS Customization functionality in instant cloned VM. - A list of key value pairs that will be passed to the destination VM. - These pairs should be used to provide user-defined customization to differentiate the destination VM from the source VM. elements: dict suboptions: dns: description: - dns is used to set the dns in Instant Cloned Guest Operating System.. type: str domain: description: - domain is used to set A fully qualified domain name (FQDN) or complete domain name for Instant Cloned Guest operating System. type: str gateway: description: - netmask is used to set the netmask in Instant Cloned Guest Operating System. type: str hostname: description: - hostname is used to obtain the DNS(Domain Name System) name and set the Guest system's hostname. type: str ipaddress: description: - ipaddress is used to set the ipaddress in Instant Cloned Guest Operating System. type: str netmask: description: - netmask is used to set the netmask in Instant Cloned Guest Operating System. type: str type: list version_added: 1.11.0 version_added_collection: community.vmware validate_certs: default: true description: - Allows connection when SSL certificates are not valid. Set to C(false) when certificates are not trusted. - If the value is not specified in the task, the value of environment variable C(VMWARE_VALIDATE_CERTS) will be used instead. - Environment variable support added in Ansible 2.6. - If set to C(true), please make sure Python >= 2.7.9 is installed on the given machine. type: bool use_instance_uuid: default: false description: - Whether to use the VMware instance UUID rather than the BIOS UUID. type: bool wait_vm_tools_timeout: default: 300 description: - Define a timeout (in seconds) for I(the wait_vm_tools) parameter. type: int version_added: 1.12.0 version_added_collection: community.vmware
vm_info: description: - metadata about the virtual machine - added instance_uuid from version 1.12.0 returned: always sample: datastore: '' host: '' instance_uuid: '' vcenter: '' vm_folder: '' vm_name: '' type: dict