Skip to content

Commit

Permalink
update vcenter_ovf_libraryitem docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemorency committed Dec 2, 2024
1 parent c93fe26 commit d762a73
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- vcenter_ovf_libraryitem - Update documentation to mention the metadata cannot be updated via conventional means. Added example showing workaround (https://github.com/ansible-collections/vmware.vmware_rest/issues/385)
2 changes: 2 additions & 0 deletions config/modules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
- vcenter_info:
- vcenter_network_info:
- vcenter_ovf_libraryitem:
documentation:
description: This operation creates a library item in content library whose content is an OVF package derived from a source virtual machine or virtual appliance, using the supplied create specification. For an existing library item whose content is updated by this operation, the original content is overwritten. Meta data such as name and description is not updated for the existing library item. PLease see the examples for a workaround if you need to update the description.
- vcenter_resourcepool_info:
- vcenter_resourcepool:
- vcenter_storage_policies_info:
Expand Down
134 changes: 65 additions & 69 deletions plugins/modules/vcenter_ovf_libraryitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
module: vcenter_ovf_libraryitem
short_description: Creates a library item in content library from a virtual machine
or virtual appliance
description: 'Creates a library item in content library from a virtual machine or
virtual appliance. '
description: This operation creates a library item in content library whose content
is an OVF package derived from a source virtual machine or virtual appliance,
using the supplied create specification. For an existing library item whose
content is updated by this operation, the original content is overwritten. Meta
data such as name and description is not updated for the existing library item.
PLease see the examples for a workaround if you need to update the description.
options:
client_token:
description:
Expand Down Expand Up @@ -261,93 +265,85 @@
"""

EXAMPLES = r"""
- 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 }}'
id: "{{ lookup('vmware.vmware_rest.vm_moid', 'My VM') }}"
target:
library_id: '{{ nfs_lib.id }}'
library_id: 1111111-1111111-1111111-111111
create_spec:
name: golden_image
description: an OVF example
name: Golden Image
description: A golden image for templating
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
# Due to an issue with the generated module code and the REST API limitations,
# updating existing template descriptions must be done by removing the create_spec.name
# attribute.
#
# Note that omitting the create_spec.name attribute will force the OVF template to be replaced.
# Thus, the second task will always report as changed
- name: Export the VM as an OVF on the library
vmware.vmware_rest.vcenter_ovf_libraryitem:
ovf_library_item_id: '{{ (lib_items.value|selectattr("name", "equalto", "golden_image")|first).id }}'
state: deploy
session_timeout: 2900
source:
type: VirtualMachine
id: "{{ lookup('vmware.vmware_rest.vm_moid', 'My VM') }}"
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
library_id: 1111111-1111111-1111111-111111
create_spec:
name: Golden Image
description: Some unhelpful description
flags: []
state: present
register: _ovf_item

- name: Create a new VM from the OVF and specify the host and folder
- name: Update The Template Description
vmware.vmware_rest.vcenter_ovf_libraryitem:
ovf_library_item_id: '{{ (lib_items.value|selectattr("name", "equalto", "golden_image")|first).id }}'
state: deploy
session_timeout: 2900
source:
type: VirtualMachine
id: "{{ lookup('vmware.vmware_rest.vm_moid', vm_name) }}"
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
library_id: "{{ library_id }}"
library_item_id: "{{ _ovf_item.id }}"
create_spec:
description: A much better description for this template
flags: []
"""

RETURN = r"""
# content generated by the update_return_section callback# task: Create a new VM from the OVF and specify the host and folder
id:
description: The ID of the OVF template
returned: When the template is created
type: str
sample:
id: "3994f858-2d45-4dac-b407-0643a29308bd"

# Sample shows values if OVF is created
value:
description: Create a new VM from the OVF and specify the host and folder
description: Details about the OVF if it was created, or an ID if the OVF was updated
returned: On success
sample:
error:
errors: []
information: []
warnings: []
resource_id:
id: vm-1078
type: VirtualMachine
succeeded: 1
type: dict
sample:
cached: true
certificate_verification_info:
status: "INTERNAL"
content_version: "3"
creation_time: "2024-11-26T20:08:07.108Z"
description: "an OVF example"
id: "3994f858-2d45-4dac-b407-0643a29308bd"
last_modified_time: "2024-12-02T15:43:24.882Z"
library_id: "fbcc0f38-b7d9-4243-95f6-fb28f1ab35a6"
metadata_version: "1"
name: "golden"
security_compliance: true
size: 875576749
type: "ovf"
version: "1"
"""


Expand Down

0 comments on commit d762a73

Please sign in to comment.