vmware.vmware.folder_template_from_vm module – Create a template in a local VCenter folder from an existing VM

Note

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

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

Synopsis

  • This module creates a template in a local VCenter folder from an existing VM. The folder must already exist. The VM must be powered off, and is otherwise unchanged. If the template already exists and the desired state is ‘present’, nothing is done.

Requirements

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

  • pyvmomi

Parameters

Parameter

Comments

cluster

aliases: cluster_name

string

The cluster to use when connecting to a vCenter.

datacenter

aliases: datacenter_name

string / required

The name of datacenter in which to operate

datastore

string

The name of datastore to use as storage for the template.

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.

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

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

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 to place the template in.

state

string

If the template should be present or absent

Choices:

  • "present" ← (default)

  • "absent"

template_folder

string / required

The name of the folder that the new template should be placed in

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’

template_name

string / required

The name to give to the new template.

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.

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_moid

string

The MOID of the vm to be used to create the template

One of vm_name, vm_moid, vm_uuid is required

This parameter is ignored when state is ‘absent’

vm_name

string

The name of the vm to be used to create the template

One of vm_name, vm_moid, vm_uuid is required

This parameter is ignored when state is ‘absent’

vm_name_match

string

If using vm_name and multiple VMs have the same name, specify which VM should be selected

Choices:

  • "first"

  • "last"

vm_use_instance_uuid

boolean

If true, search by instance UUID instead of BIOS UUID.

BIOS UUID may not be unique and may cause errors.

Choices:

  • false

  • true ← (default)

vm_uuid

string

The UUID of the vm to be used to create the template

One of vm_name, vm_moid, vm_uuid is required

This parameter is ignored when state is ‘absent’

wait_for_template

boolean

If true, the module will wait until the template is created to exit.

Choices:

  • false

  • true ← (default)

Attributes

Attribute

Support

Description

check_mode

Support: full

The check_mode support.

Notes

Note

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

Examples

- name: Create A New Template Using VM UUID
  vmware.vmware.folder_template:
    hostname: "https://vcenter"
    username: "username"
    password: "password"
    datacenter: "my-datacenter"
    vm_uuid: "11111111-11111111-11111111"
    template_folder: "my-datacenter/vm/netsted/folder/path/templates"
    template_name: "my_template"

- name: Create A New Template Using VM Name
  vmware.vmware.folder_template_from_vm:
    hostname: "https://vcenter"
    username: "username"
    password: "password"
    datacenter: "my-datacenter"
    vm_name: "my_vm"
    vm_name_match: "first"
    template_name: "my_template"
    template_folder: "nested/folder/path/templates"

- name: Destroy A Template In A Folder
  vmware.vmware.folder_template_from_vm:
    hostname: "https://vcenter"
    username: "username"
    password: "password"
    datacenter: "my-datacenter"
    vm_name: "foo"
    state: "absent"
    template_name: "my_template"
    template_folder: "nested/folder/path/templates"

Authors

  • Ansible Cloud Team (@ansible-collections)