vmware.vmware_rest.vcenter_vmtemplate_libraryitems module – Creates a library item in content library from a virtual machine
Note
This module is part of the vmware.vmware_rest collection (version 3.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
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: vmware.vmware_rest.vcenter_vmtemplate_libraryitems
.
New in vmware.vmware_rest 2.2.0
Synopsis
Creates a library item in content library from a virtual machine. This {@term operation} creates a library item in content library whose content is a virtual machine template created from the source virtual machine, using the supplied create specification. The virtual machine template is stored in a newly created library item.
Requirements
The below requirements are needed on the host that executes this module.
vSphere 7.0.3 or greater
python >= 3.6
aiohttp
Parameters
Parameter |
Comments |
---|---|
Description of the deployed virtual machine. |
|
Storage specification for the virtual machine template’s disks. Valid attributes are:
Accepted value for this field:
|
|
Storage specification for individual disks in the deployed virtual machine. This is specified as a mapping between disk identifiers in the source virtual machine template contained in the library item and their storage specifications. |
|
Guest customization spec to apply to the deployed virtual machine. Valid attributes are:
|
|
Hardware customization spec which specifies updates to the deployed virtual machine. Valid attributes are:
|
|
Identifier of the library in which the new library item should be created. Required with state=[‘present’] |
|
Name of the deployed virtual machine. This parameter is mandatory. |
|
Information used to place the virtual machine template. Valid attributes are:
|
|
Specifies whether the deployed virtual machine should be powered on after deployment. Choices:
|
|
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. |
|
Identifier of the source virtual machine to create the library item from. Required with state=[‘present’] |
|
Choices:
|
|
identifier of the content library item containing the source virtual machine template to be deployed. Required with state=[‘deploy’] |
|
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:
|
|
Storage location for the virtual machine template’s configuration and log files. Valid attributes are:
Accepted value for this field:
|
Notes
Note
Tested on vSphere 7.0.3
Examples
- 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 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: nfs_lib
- name: Create a VM template on the library
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
name: golden-template
library: '{{ nfs_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: Get the list of items of the NFS library
vmware.vmware_rest.content_library_item_info:
library_id: '{{ nfs_lib.id }}'
register: lib_items
- name: Use the name to identify the item
set_fact:
my_template_item: "{{ lib_items.value | selectattr('name', 'equalto', 'golden-template')|first }}"
- name: Deploy a new VM based on the template
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
name: vm-from-template
library: '{{ nfs_lib.id }}'
template_library_item: '{{ my_template_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
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
moid of the resource Returned: On success Sample: |
|
Create a VM template on the library Returned: On success Sample: |