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 4.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 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. If unset, the deployed virtual machine has the same description as the source library item. |
|
Storage specification for the deployed virtual machine’s disks. If both disk_storage_overrides and disk_storage are unset, the deployed virtual machine’s disks are created with the same storage spec as the corresponding disks in the source virtual machine template contained in the library item. If disk_storage_overrides is unset and disk_storage is specified, all of the deployed virtual machine’s disks are created with the storage spec specified by disk_storage. If disk_storage_overrides is specified and disk_storage is unset, disks with identifiers that are not in disk_storage_overrides are created with the same storage spec as the corresponding disks in the source virtual machine template contained in the library item. If both disk_storage_overrides and disk_storage are specified, disks with identifiers that are not in disk_storage_overrides are created with the storage spec specified by disk_storage. Valid attributes are:
This field is currently required. If storage_policy is also specified and is incompatible with the datastore, then the disk will be flagged as being out of compliance with the specified storage policy. When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_datastore_info. ([‘deploy’, ‘present’])
If unset, datastore must be specified and the deployed virtual machine’s disk is created with the default storage policy associated with the datastore. ([‘deploy’, ‘present’])
Accepted value for this field:
This field is optional and it is only relevant when the value of type is USE_SPECIFIED_POLICY. When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_storage_policies_info. |
|
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. If both disk_storage_overrides and disk_storage are unset, the deployed virtual machine’s disks are created with the same storage spec as the corresponding disks in the source virtual machine template contained in the library item. If disk_storage_overrides is unset and disk_storage is specified, all of the deployed virtual machine’s disks are created with the storage spec specified by disk_storage. If disk_storage_overrides is specified and disk_storage is unset, disks with identifiers that are not in disk_storage_overrides are created with the same storage spec as the corresponding disks in the source virtual machine template contained in the library item. If both disk_storage_overrides and disk_storage are specified, disks with identifiers that are not in disk_storage_overrides are created with the storage spec specified by disk_storage. When clients pass a value of this structure as a parameter, the key in the field map must be the id of a resource returned by vmware.vmware_rest.vcenter_vm_hardware_disk. |
|
Guest customization spec to apply to the deployed virtual machine. If unset, the guest operating system is not customized after deployment. Valid attributes are:
If unset, no guest customization is performed. ([‘deploy’]) |
|
Hardware customization spec which specifies updates to the deployed virtual machine. If unset, the deployed virtual machine has the same hardware configuration as the source virtual machine template contained in the library item. Valid attributes are:
If unset, all Ethernet adapters will remain connected to the same network as they were in the source virtual machine template. An Ethernet adapter with a MacAddressType of MANUAL will not change. An Ethernet adapter with a MacAddressType of GENERATED or ASSIGNED will receive a new address. When clients pass a value of this structure as a parameter, the key in the field map must be the id of a resource returned by vmware.vmware_rest.vcenter_vm_hardware_ethernet. ([‘deploy’])
If unset, all disks will be copied. When clients pass a value of this structure as a parameter, the field must contain the id of resources returned by vmware.vmware_rest.vcenter_vm_hardware_disk. ([‘deploy’])
If unset, disks in the deployed virtual machine will have the same settings as the corresponding disks in the source virtual machine template contained in the library item. When clients pass a value of this structure as a parameter, the key in the field map must be the id of a resource returned by vmware.vmware_rest.vcenter_vm_hardware_disk. ([‘deploy’])
If {@term.unset}, the deployed virtual machine has the same CPU settings as the source virtual machine template contained in the library item. ([‘deploy’])
If {@term.unset}, the deployed virtual machine has the same CPU count as the source virtual machine template contained in the library item.
If {@term.unset}, the deployed virtual machine has the same number of cores per socket as the source virtual machine template contained in the library item.
If {@term.unset}, the deployed virtual machine has the same memory settings as the source virtual machine template contained in the library item. ([‘deploy’])
If {@term.unset}, the deployed virtual machine has the same memory size as the source virtual machine template. |
|
Identifier of the library in which the new library item should be created. When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.content_library_info. Required with state=[‘present’] |
|
Name of the deployed virtual machine. This parameter is mandatory. |
|
Information used to place the deployed virtual machine. This field is currently required. In the future, if this field is unset, the system will use the values from the source virtual machine template contained in the library item. If specified, each field will be used for placement. If the fields result in disjoint placement, the operation will fail. If the fields along with the placement values of the source virtual machine template result in disjoint placement, the operation will fail. Valid attributes are:
This field is currently required. If unset, the system will attempt to choose a suitable folder for the virtual machine; if a folder cannot be chosen, the virtual machine deployment operation will fail. When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_folder_info. ([‘deploy’, ‘present’])
If unset, the system will attempt to choose a suitable resource pool for the virtual machine; if a resource pool cannot be chosen, the virtual machine deployment operation will fail. When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_resourcepool_info. ([‘deploy’, ‘present’])
This field may be unset if resource_pool or cluster is specified. If unset, the system will attempt to choose a suitable host for the virtual machine; if a host cannot be chosen, the virtual machine deployment operation will fail. When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_host_info. ([‘deploy’, ‘present’])
If resource_pool or host is specified, it is recommended that this field be unset. When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_cluster_info. ([‘deploy’, ‘present’]) |
|
Specifies whether the deployed virtual machine should be powered on after deployment. If unset, the virtual machine will not 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. When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_vm_info. Required with state=[‘present’] |
|
Choices:
|
|
identifier of the content library item containing the source virtual machine template to be deployed. The parameter must be the id of a resource returned by vmware.vmware_rest.content_library_item_info. 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 runs 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. If unset, the virtual machine template’s configuration and log files are placed on the default storage backing associated with the library specified by Valid attributes are:
This field is currently required. When storage_policy is also specified and is incompatible with the datastore, then the deployed virtual machine will be flagged as being out of compliance with the specified storage policy. When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_datastore_info. ([‘deploy’, ‘present’])
If unset, datastore must be specified and the deployed virtual machine’s configuration and log files are created with the default storage policy associated with the datastore. ([‘deploy’, ‘present’])
Accepted value for this field:
This field is optional and it is only relevant when the value of type is USE_SPECIFIED_POLICY. When clients pass a value of this structure as a parameter, the field must be the id of a resource returned by vmware.vmware_rest.vcenter_storage_policies_info. |
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: |