vmware.vmware_rest.vcenter_ovf_libraryitem module – Creates a library item in content library from a virtual machine or virtual appliance

Note

This module is part of the vmware.vmware_rest collection (version 4.1.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_ovf_libraryitem.

New in vmware.vmware_rest 2.0.0

Synopsis

  • Creates a library item in content library from a virtual machine or virtual appliance.

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

client_token

string

Client-generated token used to retry a request if the client fails to get a response from the server. If the original request succeeded, the result of that request will be returned, otherwise the operation will be retried.

If unset, the server will create a token.

create_spec

dictionary

Information used to create the OVF package from the source virtual machine or virtual appliance. Required with state=[‘present’]

Valid attributes are:

  • name (str): Name to use in the OVF descriptor stored in the library item.

If unset, the server will use source’s current name. ([‘present’])

  • description (str): Description to use in the OVF descriptor stored in the library item.

If unset, the server will use source’s current annotation. ([‘present’])

  • flags (list): Flags to use for OVF package creation. The supported flags can be obtained using ExportFlag.list.

If unset, no flags will be used. ([‘present’])

deployment_spec

dictionary

Specification of how the OVF package should be deployed to the target. Required with state=[‘deploy’]

Valid attributes are:

  • name (str): Name assigned to the deployed target virtual machine or virtual appliance.

If unset, the server will use the name from the OVF package. ([‘deploy’])

  • annotation (str): Annotation assigned to the deployed target virtual machine or virtual appliance.

If unset, the server will use the annotation from the OVF package. ([‘deploy’])

  • accept_all_EULA (bool): Whether to accept all End User License Agreements. See ([‘deploy’])

This key is required with [‘deploy’].

  • network_mappings (dict): Specification of the target network to use for sections of type ovf:NetworkSection in the OVF descriptor. The key in the map is the section identifier of the ovf:NetworkSection section in the OVF descriptor and the value is the target network to be used for deployment.

If unset, the server will choose a network mapping.

When clients pass a value of this structure as a parameter, the value in the field map must be the id of a resource returned by vmware.vmware_rest.vcenter_network_info. ([‘deploy’])

  • storage_mappings (dict): Specification of the target storage to use for sections of type vmw:StorageGroupSection in the OVF descriptor. The key in the map is the section identifier of the ovf:StorageGroupSection section in the OVF descriptor and the value is the target storage specification to be used for deployment. See

If unset, the server will choose a storage mapping. ([‘deploy’])

  • storage_provisioning (str): This option defines the virtual disk provisioning types that can be set for a disk on the target platform. ([‘deploy’])

  • Accepted values:

  • eagerZeroedThick

  • thick

  • thin

  • storage_profile_id (str): Default storage profile to use for all sections of type vmw:StorageSection in the OVF descriptor.

If unset, the server will choose the default profile.

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. ([‘deploy’])

  • locale (str): The locale to use for parsing the OVF descriptor.

If unset, the server locale will be used. ([‘deploy’])

  • flags (list): Flags to be use for deployment. The supported flag values can be obtained using ImportFlag.list.

If unset, no flags will be used. ([‘deploy’])

  • additional_parameters (list): Additional OVF parameters that may be needed for the deployment. Additional OVF parameters may be required by the OVF descriptor of the OVF package in the library item. Examples of OVF parameters that can be specified through this field include, but are not limited to:

  • DeploymentOptionParams

  • ExtraConfigParams

  • IpAllocationParams

  • PropertyParams

  • ScaleOutParams

  • VcenterExtensionParams

If unset, the server will choose default settings for all parameters necessary for the LibraryItem.deploy operation. See LibraryItem.deploy.

When clients pass a value of this structure as a parameter, the field must contain all the attributes defined in OvfParams. ([‘deploy’])

  • default_datastore_id (str): Default datastore to use for all sections of type vmw:StorageSection in the OVF descriptor.

If unset, the server will choose the default datastore.

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’])

  • vm_config_spec (dict): The resource_pool_deployment_spec.vm-config-spec is used for virtual machine configuration settings including hardware specifications to use in place of the OVF descriptor. If set, the OVF descriptor acts as a disk descriptor. Fields in the resource_pool_deployment_spec parameters such as resource_pool_deployment_spec.name that overlap with settings in the resource_pool_deployment_spec.vm-config-spec are not overridden and will continue to be used. Similarly, storage settings in the resource_pool_deployment_spec that affect the disks on the virtual machine namely resource_pool_deployment_spec.storage-mappings, resource_pool_deployment_spec.storage-profile-id, resource_pool_deployment_spec.storage-provisioning and resource_pool_deployment_spec.default-datastore-id will also be honored.

If unset, the relevant virtual machine specifications in the OVF descriptor of the OVF template will be used. ([‘deploy’])

  • Accepted keys:

  • provider (string): The vm_config_spec_provider is used to provide the optional vm_config_spec used when deploying an OVF template.

Accepted value for this field:

  • XML

  • xml (string): The xml is a conditional configuration made available upon selecting the XML. It is used to pass in a vim.vm.ConfigSpec for a virtual machine that has been serialized to XML and base64 encoded.

This field is optional and it is only relevant when the value of provider is XML.

ovf_library_item_id

string

Identifier of the content library item containing the OVF package 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’, ‘filter’]

session_timeout

float

added in vmware.vmware_rest 2.1.0

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.

source

dictionary

Identifier of the virtual machine or virtual appliance to use as the source. Required with state=[‘present’]

Valid attributes are:

  • type (str): Type of the deployable resource.

When clients pass a value of this structure as a parameter, the field must be one of VirtualMachine or VirtualApp. ([‘present’])

This key is required with [‘present’].

  • id (str): Identifier of the deployable resource.

When clients pass a value of this structure as a parameter, the field must be an identifier for one of these resource types: VirtualMachine or VirtualApp. ([‘present’])

This key is required with [‘present’].

state

string

Choices:

  • "deploy"

  • "filter"

  • "present" ← (default)

target

dictionary / required

Specification of the target content library and library item. This parameter is mandatory.

Valid attributes are:

  • library_id (str): Identifier of the library in which a new library item should be created. This field is not used if the library_item_id field is specified.

This field is currently required.

In the future, if unset, the library_item_id field must be specified.

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. ([‘present’])

  • library_item_id (str): Identifier of the library item that should be should be updated.

If unset, a new library item will be created. The library_id field must be specified if this field is set.

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_item_info. ([‘present’])

  • resource_pool_id (str): Identifier of the resource pool to which the virtual machine or virtual appliance should be attached.

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’, ‘filter’])

This key is required with [‘deploy’, ‘filter’].

  • host_id (str): Identifier of the target host on which the virtual machine or virtual appliance will run. The target host must be a member of the cluster that contains the resource pool identified by

If unset, the server will automatically select a target host from the resource pool if resource_pool_id is a stand-alone host or a cluster with Distributed Resource Scheduling (DRS) enabled.

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’, ‘filter’])

  • folder_id (str): Identifier of the vCenter folder that should contain the virtual machine or virtual appliance. The folder must be virtual machine folder.

If unset, the server will choose the deployment folder.

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’, ‘filter’])

vcenter_hostname

string / required

The hostname or IP address of the vSphere vCenter

If the value is not specified in the task, the value of environment variable VMWARE_HOST will be used instead.

vcenter_password

string / required

The vSphere vCenter password

If the value is not specified in the task, the value of environment variable VMWARE_PASSWORD will be used instead.

vcenter_rest_log_file

string

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 VMWARE_REST_LOG_FILE will be used instead.

vcenter_username

string / required

The vSphere vCenter username

If the value is not specified in the task, the value of environment variable VMWARE_USER will be used instead.

vcenter_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)

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/rw_datastore') }}"
      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
  register: my_vm

- name: Create a content library pointing on a NFS share
  vmware.vmware_rest.content_locallibrary:
    name: my_library_on_nfs
    description: automated
    publish_info:
      published: true
      authentication_method: NONE
    storage_backings:
    - storage_uri: nfs://datastore.test/srv/share/content-library
      type: OTHER
    state: present
  register: nfs_lib

- name: Export the VM as an OVF on the library
  vmware.vmware_rest.vcenter_ovf_libraryitem:
    session_timeout: 2900
    source:
      type: VirtualMachine
      id: '{{ my_vm.id }}'
    target:
      library_id: '{{ nfs_lib.id }}'
    create_spec:
      name: golden_image
      description: an OVF example
      flags: []
    state: present
  register: ovf_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: Create a new VM from the OVF
  vmware.vmware_rest.vcenter_ovf_libraryitem:
    ovf_library_item_id: '{{ (lib_items.value|selectattr("name", "equalto", "golden_image")|first).id }}'
    state: deploy
    target:
      resource_pool_id: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}"
    deployment_spec:
      name: my_vm_from_ovf
      accept_all_EULA: true
      storage_provisioning: thin

- name: Create a new VM from the OVF and specify the host and folder
  vmware.vmware_rest.vcenter_ovf_libraryitem:
    ovf_library_item_id: '{{ (lib_items.value|selectattr("name", "equalto", "golden_image")|first).id }}'
    state: deploy
    target:
      resource_pool_id: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}"
      folder_id: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}"
      host_id: "{{ lookup('vmware.vmware_rest.host_moid', '/my_dc/host/my_cluster/esxi1.test/test_vm1') }}"
    deployment_spec:
      name: my_vm_from_ovf_on_a_host
      accept_all_EULA: true
      storage_provisioning: thin

Return Values

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

Key

Description

value

dictionary

Create a new VM from the OVF and specify the host and folder

Returned: On success

Sample: {"error": {"errors": [], "information": [], "warnings": []}, "resource_id": {"id": "vm-1078", "type": "VirtualMachine"}, "succeeded": 1}

Authors

  • Ansible Cloud Team (@ansible-collections)