We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Allow Users to Choose Content Library for OVF Deployments 
<!--- Verify first that your feature was not already discussed on GitHub -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY

Unlike the Module "community.vmware.vmware_content_deploy_template"  Where you have the ability to pick which Subscription you wish to deploy from. The module  Deploying OVF from Content Library doesn't have this feature, which it appears to pick at random a  subscription to deploy from. In doing so, to double the time needed for a deployment workflow.

##### ISSUE TYPE
- Add the Feature content_library 

##### COMPONENT NAME
community.vmware.vmware_content_deploy_ovf_template

##### ADDITIONAL INFORMATION
<!--- Describe how the feature would be used, why it is needed and what it would solve -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml

---
    - name:
      hosts: localhost
      gather_facts: false
      connection: local
      tasks:
      - community.vmware.vmware_content_deploy_ovf_template:
          host: "{{ esxi_hostname }}"
          hostname: "{{ vcenter_hostname }}"
          username: "{{ user }}"
          password: "{{ pass }}"
          datacenter: "{{ datacenter }}"
          cluster: "{{ cluster }}"
           content_library: "{{ library_name }}" 
          datastore: "{{ datastore }}"
          resource_pool: "{{ vmname }}-resource"
          validate_certs: False
          folder: vm
          ovf_template: "{{ TemplateName }}"
          name: "{{ vmname }}"
        delegate_to: localhost

```

<!--- HINT: You can also paste gist.github.com links for larger files -->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `plugins/modules/vmware_content_deploy_ovf_template.py`
Content:
```
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright: (c) 2020, Lev Goncharov <lev@goncharov.xyz>
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5 
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8 
9 
10 DOCUMENTATION = r'''
11 ---
12 module: vmware_content_deploy_ovf_template
13 short_description: Deploy Virtual Machine from ovf template stored in content library.
14 description:
15 - Module to deploy virtual machine from ovf template in content library.
16 - All variables and VMware object names are case sensitive.
17 author:
18 - Lev Goncharv (@ultral)
19 notes:
20 - Tested on vSphere 6.7
21 requirements:
22 - python >= 2.6
23 - PyVmomi
24 - vSphere Automation SDK
25 options:
26     ovf_template:
27       description:
28       - The name of OVF template from which VM to be deployed.
29       type: str
30       required: True
31       aliases: ['ovf', 'template_src']
32     name:
33       description:
34       - The name of the VM to be deployed.
35       type: str
36       required: True
37       aliases: ['vm_name']
38     datacenter:
39       description:
40       - Name of the datacenter, where VM to be deployed.
41       type: str
42       required: True
43     datastore:
44       description:
45       - Name of the datastore to store deployed VM and disk.
46       type: str
47       required: True
48     folder:
49       description:
50       - Name of the folder in datacenter in which to place deployed VM.
51       type: str
52       required: True
53     host:
54       description:
55       - Name of the ESX Host in datacenter in which to place deployed VM. The host has to be a member of the cluster that contains the resource pool.
56       type: str
57       required: True
58     resource_pool:
59       description:
60       - Name of the resourcepool in datacenter in which to place deployed VM.
61       type: str
62       required: True
63     cluster:
64       description:
65       - Name of the cluster in datacenter in which to place deployed VM.
66       type: str
67       required: False
68     storage_provisioning:
69       description:
70       - Default storage provisioning type to use for all sections of type vmw:StorageSection in the OVF descriptor.
71       type: str
72       choices: [ thin, thick, eagerZeroedThick ]
73 extends_documentation_fragment: community.vmware.vmware_rest_client.documentation
74 '''
75 
76 EXAMPLES = r'''
77 - name: Deploy Virtual Machine from OVF template in content library
78   community.vmware.vmware_content_deploy_ovf_template:
79     hostname: '{{ vcenter_hostname }}'
80     username: '{{ vcenter_username }}'
81     password: '{{ vcenter_password }}'
82     ovf_template: rhel_test_template
83     datastore: Shared_NFS_Volume
84     folder: vm
85     datacenter: Sample_DC_1
86     name: Sample_VM
87     resource_pool: test_rp
88   delegate_to: localhost
89 
90 - name: Deploy Virtual Machine from OVF template in content library with eagerZeroedThick storage
91   vmware_content_deploy_ovf_template:
92     hostname: '{{ vcenter_hostname }}'
93     username: '{{ vcenter_username }}'
94     password: '{{ vcenter_password }}'
95     ovf_template: rhel_test_template
96     datastore: Shared_NFS_Volume
97     folder: vm
98     datacenter: Sample_DC_1
99     name: Sample_VM
100     resource_pool: test_rp
101     storage_provisioning: eagerZeroedThick
102   delegate_to: localhost
103 '''
104 
105 RETURN = r'''
106 vm_deploy_info:
107   description: Virtual machine deployment message and vm_id
108   returned: on success
109   type: dict
110   sample: {
111         "msg": "Deployed Virtual Machine 'Sample_VM'.",
112         "vm_id": "vm-1009"
113     }
114 '''
115 
116 from ansible.module_utils.basic import AnsibleModule
117 from ansible.module_utils._text import to_native
118 from ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient
119 from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi
120 
121 HAS_VAUTOMATION_PYTHON_SDK = False
122 try:
123     from com.vmware.vcenter.ovf_client import LibraryItem
124     from com.vmware.vapi.std.errors_client import Error
125     HAS_VAUTOMATION_PYTHON_SDK = True
126 except ImportError:
127     pass
128 
129 
130 class VmwareContentDeployOvfTemplate(VmwareRestClient):
131     def __init__(self, module):
132         """Constructor."""
133         super(VmwareContentDeployOvfTemplate, self).__init__(module)
134         self.ovf_template_name = self.params.get('ovf_template')
135         self.vm_name = self.params.get('name')
136         self.datacenter = self.params.get('datacenter')
137         self.datastore = self.params.get('datastore')
138         self.folder = self.params.get('folder')
139         self.resourcepool = self.params.get('resource_pool')
140         self.cluster = self.params.get('cluster')
141         self.host = self.params.get('host')
142         self.storage_provisioning = self.params.get('storage_provisioning')
143 
144     def deploy_vm_from_ovf_template(self):
145         # Find the datacenter by the given datacenter name
146         self.datacenter_id = self.get_datacenter_by_name(datacenter_name=self.datacenter)
147         if not self.datacenter_id:
148             self.module.fail_json(msg="Failed to find the datacenter %s" % self.datacenter)
149         # Find the datastore by the given datastore name
150         self.datastore_id = self.get_datastore_by_name(self.datacenter, self.datastore)
151         if not self.datastore_id:
152             self.module.fail_json(msg="Failed to find the datastore %s" % self.datastore)
153         # Find the LibraryItem (Template) by the given LibraryItem name
154         self.library_item_id = self.get_library_item_by_name(self.ovf_template_name)
155         if not self.library_item_id:
156             self.module.fail_json(msg="Failed to find the library Item %s" % self.ovf_template_name)
157         # Find the folder by the given folder name
158         self.folder_id = self.get_folder_by_name(self.datacenter, self.folder)
159         if not self.folder_id:
160             self.module.fail_json(msg="Failed to find the folder %s" % self.folder)
161         # Find the Host by given HostName
162         self.host_id = self.get_host_by_name(self.datacenter, self.host)
163         if not self.host_id:
164             self.module.fail_json(msg="Failed to find the Host %s" % self.host)
165         # Find the resourcepool by the given resourcepool name
166         self.resourcepool_id = self.get_resource_pool_by_name(self.datacenter, self.resourcepool, self.cluster, self.host)
167         if not self.resourcepool_id:
168             self.module.fail_json(msg="Failed to find the resource_pool %s" % self.resourcepool)
169         # Find the Cluster by the given Cluster name
170         self.cluster_id = None
171         if self.cluster:
172             self.cluster_id = self.get_cluster_by_name(self.datacenter, self.cluster)
173             if not self.cluster_id:
174                 self.module.fail_json(msg="Failed to find the Cluster %s" % self.cluster)
175 
176         deployment_target = LibraryItem.DeploymentTarget(
177             resource_pool_id=self.resourcepool_id,
178             folder_id=self.folder_id
179         )
180 
181         self.ovf_summary = self.api_client.vcenter.ovf.LibraryItem.filter(
182             ovf_library_item_id=self.library_item_id,
183             target=deployment_target)
184 
185         self.deploy_spec = LibraryItem.ResourcePoolDeploymentSpec(
186             name=self.vm_name,
187             annotation=self.ovf_summary.annotation,
188             accept_all_eula=True,
189             network_mappings=None,
190             storage_mappings=None,
191             storage_provisioning=self.storage_provisioning,
192             storage_profile_id=None,
193             locale=None,
194             flags=None,
195             additional_parameters=None,
196             default_datastore_id=self.datastore_id)
197 
198         result = {
199             'succeeded': False
200         }
201         try:
202             result = self.api_client.vcenter.ovf.LibraryItem.deploy(self.library_item_id, deployment_target, self.deploy_spec)
203         except Error as error:
204             self.module.fail_json(msg="%s" % self.get_error_message(error))
205         except Exception as err:
206             self.module.fail_json(msg="%s" % to_native(err))
207 
208         if result.succeeded:
209             self.module.exit_json(
210                 changed=True,
211                 vm_deploy_info=dict(
212                     msg="Deployed Virtual Machine '%s'." % self.vm_name,
213                     vm_id=result.resource_id.id,
214                 )
215             )
216         self.module.exit_json(changed=False,
217                               vm_deploy_info=dict(msg="Virtual Machine deployment failed", vm_id=''))
218 
219 
220 def main():
221     argument_spec = VmwareRestClient.vmware_client_argument_spec()
222     argument_spec.update(
223         ovf_template=dict(type='str', aliases=['template_src', 'ovf'], required=True),
224         name=dict(type='str', required=True, aliases=['vm_name']),
225         datacenter=dict(type='str', required=True),
226         datastore=dict(type='str', required=True),
227         folder=dict(type='str', required=True),
228         host=dict(type='str', required=True),
229         resource_pool=dict(type='str', required=True),
230         cluster=dict(type='str', required=False),
231         storage_provisioning=dict(type='str',
232                                   required=False,
233                                   choices=['thin', 'thick', 'eagerZeroedThick'],
234                                   default=None),
235     )
236     module = AnsibleModule(argument_spec=argument_spec,
237                            supports_check_mode=True)
238     result = {'failed': False, 'changed': False}
239     pyv = PyVmomi(module=module)
240     vm = pyv.get_vm()
241     if vm:
242         module.exit_json(
243             changed=False,
244             vm_deploy_info=dict(
245                 msg="Virtual Machine '%s' already Exists." % module.params['name'],
246                 vm_id=vm._moId,
247             )
248         )
249     vmware_contentlib_create = VmwareContentDeployOvfTemplate(module)
250     if module.check_mode:
251         result.update(
252             vm_name=module.params['name'],
253             changed=True,
254             desired_operation='Create VM with PowerOff State',
255         )
256         module.exit_json(**result)
257     vmware_contentlib_create.deploy_vm_from_ovf_template()
258 
259 
260 if __name__ == '__main__':
261     main()
262
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/plugins/modules/vmware_content_deploy_ovf_template.py b/plugins/modules/vmware_content_deploy_ovf_template.py
--- a/plugins/modules/vmware_content_deploy_ovf_template.py
+++ b/plugins/modules/vmware_content_deploy_ovf_template.py
@@ -29,6 +29,12 @@
       type: str
       required: True
       aliases: ['ovf', 'template_src']
+    content_library:
+      description:
+      - The name of the content library from where the template resides.
+      type: str
+      required: False
+      version_added: '1.5.0'
     name:
       description:
       - The name of the VM to be deployed.
@@ -132,6 +138,7 @@
         """Constructor."""
         super(VmwareContentDeployOvfTemplate, self).__init__(module)
         self.ovf_template_name = self.params.get('ovf_template')
+        self.content_library_name = self.params.get('content_library')
         self.vm_name = self.params.get('name')
         self.datacenter = self.params.get('datacenter')
         self.datastore = self.params.get('datastore')
@@ -151,9 +158,15 @@
         if not self.datastore_id:
             self.module.fail_json(msg="Failed to find the datastore %s" % self.datastore)
         # Find the LibraryItem (Template) by the given LibraryItem name
-        self.library_item_id = self.get_library_item_by_name(self.ovf_template_name)
-        if not self.library_item_id:
-            self.module.fail_json(msg="Failed to find the library Item %s" % self.ovf_template_name)
+        if self.content_library_name:
+            self.library_item_id = self.get_library_item_from_content_library_name(
+                self.ovf_template_name, self.content_library_name)
+            if not self.library_item_id:
+                self.module.fail_json(msg="Failed to find the library Item %s in content library %s" % (self.ovf_template_name, self.content_library_name))
+        else:
+            self.library_item_id = self.get_library_item_by_name(self.ovf_template_name)
+            if not self.library_item_id:
+                self.module.fail_json(msg="Failed to find the library Item %s" % self.ovf_template_name)
         # Find the folder by the given folder name
         self.folder_id = self.get_folder_by_name(self.datacenter, self.folder)
         if not self.folder_id:
@@ -221,6 +234,7 @@
     argument_spec = VmwareRestClient.vmware_client_argument_spec()
     argument_spec.update(
         ovf_template=dict(type='str', aliases=['template_src', 'ovf'], required=True),
+        content_library=dict(type='str', required=False),
         name=dict(type='str', required=True, aliases=['vm_name']),
         datacenter=dict(type='str', required=True),
         datastore=dict(type='str', required=True),

{"golden_diff": "diff --git a/plugins/modules/vmware_content_deploy_ovf_template.py b/plugins/modules/vmware_content_deploy_ovf_template.py\n--- a/plugins/modules/vmware_content_deploy_ovf_template.py\n+++ b/plugins/modules/vmware_content_deploy_ovf_template.py\n@@ -29,6 +29,12 @@\n       type: str\n       required: True\n       aliases: ['ovf', 'template_src']\n+    content_library:\n+      description:\n+      - The name of the content library from where the template resides.\n+      type: str\n+      required: False\n+      version_added: '1.5.0'\n     name:\n       description:\n       - The name of the VM to be deployed.\n@@ -132,6 +138,7 @@\n         \"\"\"Constructor.\"\"\"\n         super(VmwareContentDeployOvfTemplate, self).__init__(module)\n         self.ovf_template_name = self.params.get('ovf_template')\n+        self.content_library_name = self.params.get('content_library')\n         self.vm_name = self.params.get('name')\n         self.datacenter = self.params.get('datacenter')\n         self.datastore = self.params.get('datastore')\n@@ -151,9 +158,15 @@\n         if not self.datastore_id:\n             self.module.fail_json(msg=\"Failed to find the datastore %s\" % self.datastore)\n         # Find the LibraryItem (Template) by the given LibraryItem name\n-        self.library_item_id = self.get_library_item_by_name(self.ovf_template_name)\n-        if not self.library_item_id:\n-            self.module.fail_json(msg=\"Failed to find the library Item %s\" % self.ovf_template_name)\n+        if self.content_library_name:\n+            self.library_item_id = self.get_library_item_from_content_library_name(\n+                self.ovf_template_name, self.content_library_name)\n+            if not self.library_item_id:\n+                self.module.fail_json(msg=\"Failed to find the library Item %s in content library %s\" % (self.ovf_template_name, self.content_library_name))\n+        else:\n+            self.library_item_id = self.get_library_item_by_name(self.ovf_template_name)\n+            if not self.library_item_id:\n+                self.module.fail_json(msg=\"Failed to find the library Item %s\" % self.ovf_template_name)\n         # Find the folder by the given folder name\n         self.folder_id = self.get_folder_by_name(self.datacenter, self.folder)\n         if not self.folder_id:\n@@ -221,6 +234,7 @@\n     argument_spec = VmwareRestClient.vmware_client_argument_spec()\n     argument_spec.update(\n         ovf_template=dict(type='str', aliases=['template_src', 'ovf'], required=True),\n+        content_library=dict(type='str', required=False),\n         name=dict(type='str', required=True, aliases=['vm_name']),\n         datacenter=dict(type='str', required=True),\n         datastore=dict(type='str', required=True),\n", "issue": "Allow Users to Choose Content Library for OVF Deployments \n<!--- Verify first that your feature was not already discussed on GitHub -->\r\n<!--- Complete *all* sections as described, this form is processed automatically -->\r\n\r\n##### SUMMARY\r\n\r\nUnlike the Module \"community.vmware.vmware_content_deploy_template\"  Where you have the ability to pick which Subscription you wish to deploy from. The module  Deploying OVF from Content Library doesn't have this feature, which it appears to pick at random a  subscription to deploy from. In doing so, to double the time needed for a deployment workflow.\r\n\r\n##### ISSUE TYPE\r\n- Add the Feature content_library \r\n\r\n##### COMPONENT NAME\r\ncommunity.vmware.vmware_content_deploy_ovf_template\r\n\r\n##### ADDITIONAL INFORMATION\r\n<!--- Describe how the feature would be used, why it is needed and what it would solve -->\r\n\r\n<!--- Paste example playbooks or commands between quotes below -->\r\n```yaml\r\n\r\n---\r\n    - name:\r\n      hosts: localhost\r\n      gather_facts: false\r\n      connection: local\r\n      tasks:\r\n      - community.vmware.vmware_content_deploy_ovf_template:\r\n          host: \"{{ esxi_hostname }}\"\r\n          hostname: \"{{ vcenter_hostname }}\"\r\n          username: \"{{ user }}\"\r\n          password: \"{{ pass }}\"\r\n          datacenter: \"{{ datacenter }}\"\r\n          cluster: \"{{ cluster }}\"\r\n           content_library: \"{{ library_name }}\" \r\n          datastore: \"{{ datastore }}\"\r\n          resource_pool: \"{{ vmname }}-resource\"\r\n          validate_certs: False\r\n          folder: vm\r\n          ovf_template: \"{{ TemplateName }}\"\r\n          name: \"{{ vmname }}\"\r\n        delegate_to: localhost\r\n\r\n```\r\n\r\n<!--- HINT: You can also paste gist.github.com links for larger files -->\r\n\n", "before_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n# Copyright: (c) 2020, Lev Goncharov <lev@goncharov.xyz>\n# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\n\nDOCUMENTATION = r'''\n---\nmodule: vmware_content_deploy_ovf_template\nshort_description: Deploy Virtual Machine from ovf template stored in content library.\ndescription:\n- Module to deploy virtual machine from ovf template in content library.\n- All variables and VMware object names are case sensitive.\nauthor:\n- Lev Goncharv (@ultral)\nnotes:\n- Tested on vSphere 6.7\nrequirements:\n- python >= 2.6\n- PyVmomi\n- vSphere Automation SDK\noptions:\n    ovf_template:\n      description:\n      - The name of OVF template from which VM to be deployed.\n      type: str\n      required: True\n      aliases: ['ovf', 'template_src']\n    name:\n      description:\n      - The name of the VM to be deployed.\n      type: str\n      required: True\n      aliases: ['vm_name']\n    datacenter:\n      description:\n      - Name of the datacenter, where VM to be deployed.\n      type: str\n      required: True\n    datastore:\n      description:\n      - Name of the datastore to store deployed VM and disk.\n      type: str\n      required: True\n    folder:\n      description:\n      - Name of the folder in datacenter in which to place deployed VM.\n      type: str\n      required: True\n    host:\n      description:\n      - Name of the ESX Host in datacenter in which to place deployed VM. The host has to be a member of the cluster that contains the resource pool.\n      type: str\n      required: True\n    resource_pool:\n      description:\n      - Name of the resourcepool in datacenter in which to place deployed VM.\n      type: str\n      required: True\n    cluster:\n      description:\n      - Name of the cluster in datacenter in which to place deployed VM.\n      type: str\n      required: False\n    storage_provisioning:\n      description:\n      - Default storage provisioning type to use for all sections of type vmw:StorageSection in the OVF descriptor.\n      type: str\n      choices: [ thin, thick, eagerZeroedThick ]\nextends_documentation_fragment: community.vmware.vmware_rest_client.documentation\n'''\n\nEXAMPLES = r'''\n- name: Deploy Virtual Machine from OVF template in content library\n  community.vmware.vmware_content_deploy_ovf_template:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    ovf_template: rhel_test_template\n    datastore: Shared_NFS_Volume\n    folder: vm\n    datacenter: Sample_DC_1\n    name: Sample_VM\n    resource_pool: test_rp\n  delegate_to: localhost\n\n- name: Deploy Virtual Machine from OVF template in content library with eagerZeroedThick storage\n  vmware_content_deploy_ovf_template:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    ovf_template: rhel_test_template\n    datastore: Shared_NFS_Volume\n    folder: vm\n    datacenter: Sample_DC_1\n    name: Sample_VM\n    resource_pool: test_rp\n    storage_provisioning: eagerZeroedThick\n  delegate_to: localhost\n'''\n\nRETURN = r'''\nvm_deploy_info:\n  description: Virtual machine deployment message and vm_id\n  returned: on success\n  type: dict\n  sample: {\n        \"msg\": \"Deployed Virtual Machine 'Sample_VM'.\",\n        \"vm_id\": \"vm-1009\"\n    }\n'''\n\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible.module_utils._text import to_native\nfrom ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient\nfrom ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi\n\nHAS_VAUTOMATION_PYTHON_SDK = False\ntry:\n    from com.vmware.vcenter.ovf_client import LibraryItem\n    from com.vmware.vapi.std.errors_client import Error\n    HAS_VAUTOMATION_PYTHON_SDK = True\nexcept ImportError:\n    pass\n\n\nclass VmwareContentDeployOvfTemplate(VmwareRestClient):\n    def __init__(self, module):\n        \"\"\"Constructor.\"\"\"\n        super(VmwareContentDeployOvfTemplate, self).__init__(module)\n        self.ovf_template_name = self.params.get('ovf_template')\n        self.vm_name = self.params.get('name')\n        self.datacenter = self.params.get('datacenter')\n        self.datastore = self.params.get('datastore')\n        self.folder = self.params.get('folder')\n        self.resourcepool = self.params.get('resource_pool')\n        self.cluster = self.params.get('cluster')\n        self.host = self.params.get('host')\n        self.storage_provisioning = self.params.get('storage_provisioning')\n\n    def deploy_vm_from_ovf_template(self):\n        # Find the datacenter by the given datacenter name\n        self.datacenter_id = self.get_datacenter_by_name(datacenter_name=self.datacenter)\n        if not self.datacenter_id:\n            self.module.fail_json(msg=\"Failed to find the datacenter %s\" % self.datacenter)\n        # Find the datastore by the given datastore name\n        self.datastore_id = self.get_datastore_by_name(self.datacenter, self.datastore)\n        if not self.datastore_id:\n            self.module.fail_json(msg=\"Failed to find the datastore %s\" % self.datastore)\n        # Find the LibraryItem (Template) by the given LibraryItem name\n        self.library_item_id = self.get_library_item_by_name(self.ovf_template_name)\n        if not self.library_item_id:\n            self.module.fail_json(msg=\"Failed to find the library Item %s\" % self.ovf_template_name)\n        # Find the folder by the given folder name\n        self.folder_id = self.get_folder_by_name(self.datacenter, self.folder)\n        if not self.folder_id:\n            self.module.fail_json(msg=\"Failed to find the folder %s\" % self.folder)\n        # Find the Host by given HostName\n        self.host_id = self.get_host_by_name(self.datacenter, self.host)\n        if not self.host_id:\n            self.module.fail_json(msg=\"Failed to find the Host %s\" % self.host)\n        # Find the resourcepool by the given resourcepool name\n        self.resourcepool_id = self.get_resource_pool_by_name(self.datacenter, self.resourcepool, self.cluster, self.host)\n        if not self.resourcepool_id:\n            self.module.fail_json(msg=\"Failed to find the resource_pool %s\" % self.resourcepool)\n        # Find the Cluster by the given Cluster name\n        self.cluster_id = None\n        if self.cluster:\n            self.cluster_id = self.get_cluster_by_name(self.datacenter, self.cluster)\n            if not self.cluster_id:\n                self.module.fail_json(msg=\"Failed to find the Cluster %s\" % self.cluster)\n\n        deployment_target = LibraryItem.DeploymentTarget(\n            resource_pool_id=self.resourcepool_id,\n            folder_id=self.folder_id\n        )\n\n        self.ovf_summary = self.api_client.vcenter.ovf.LibraryItem.filter(\n            ovf_library_item_id=self.library_item_id,\n            target=deployment_target)\n\n        self.deploy_spec = LibraryItem.ResourcePoolDeploymentSpec(\n            name=self.vm_name,\n            annotation=self.ovf_summary.annotation,\n            accept_all_eula=True,\n            network_mappings=None,\n            storage_mappings=None,\n            storage_provisioning=self.storage_provisioning,\n            storage_profile_id=None,\n            locale=None,\n            flags=None,\n            additional_parameters=None,\n            default_datastore_id=self.datastore_id)\n\n        result = {\n            'succeeded': False\n        }\n        try:\n            result = self.api_client.vcenter.ovf.LibraryItem.deploy(self.library_item_id, deployment_target, self.deploy_spec)\n        except Error as error:\n            self.module.fail_json(msg=\"%s\" % self.get_error_message(error))\n        except Exception as err:\n            self.module.fail_json(msg=\"%s\" % to_native(err))\n\n        if result.succeeded:\n            self.module.exit_json(\n                changed=True,\n                vm_deploy_info=dict(\n                    msg=\"Deployed Virtual Machine '%s'.\" % self.vm_name,\n                    vm_id=result.resource_id.id,\n                )\n            )\n        self.module.exit_json(changed=False,\n                              vm_deploy_info=dict(msg=\"Virtual Machine deployment failed\", vm_id=''))\n\n\ndef main():\n    argument_spec = VmwareRestClient.vmware_client_argument_spec()\n    argument_spec.update(\n        ovf_template=dict(type='str', aliases=['template_src', 'ovf'], required=True),\n        name=dict(type='str', required=True, aliases=['vm_name']),\n        datacenter=dict(type='str', required=True),\n        datastore=dict(type='str', required=True),\n        folder=dict(type='str', required=True),\n        host=dict(type='str', required=True),\n        resource_pool=dict(type='str', required=True),\n        cluster=dict(type='str', required=False),\n        storage_provisioning=dict(type='str',\n                                  required=False,\n                                  choices=['thin', 'thick', 'eagerZeroedThick'],\n                                  default=None),\n    )\n    module = AnsibleModule(argument_spec=argument_spec,\n                           supports_check_mode=True)\n    result = {'failed': False, 'changed': False}\n    pyv = PyVmomi(module=module)\n    vm = pyv.get_vm()\n    if vm:\n        module.exit_json(\n            changed=False,\n            vm_deploy_info=dict(\n                msg=\"Virtual Machine '%s' already Exists.\" % module.params['name'],\n                vm_id=vm._moId,\n            )\n        )\n    vmware_contentlib_create = VmwareContentDeployOvfTemplate(module)\n    if module.check_mode:\n        result.update(\n            vm_name=module.params['name'],\n            changed=True,\n            desired_operation='Create VM with PowerOff State',\n        )\n        module.exit_json(**result)\n    vmware_contentlib_create.deploy_vm_from_ovf_template()\n\n\nif __name__ == '__main__':\n    main()\n", "path": "plugins/modules/vmware_content_deploy_ovf_template.py"}], "after_files": [{"content": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n# Copyright: (c) 2020, Lev Goncharov <lev@goncharov.xyz>\n# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)\n\nfrom __future__ import absolute_import, division, print_function\n__metaclass__ = type\n\n\nDOCUMENTATION = r'''\n---\nmodule: vmware_content_deploy_ovf_template\nshort_description: Deploy Virtual Machine from ovf template stored in content library.\ndescription:\n- Module to deploy virtual machine from ovf template in content library.\n- All variables and VMware object names are case sensitive.\nauthor:\n- Lev Goncharv (@ultral)\nnotes:\n- Tested on vSphere 6.7\nrequirements:\n- python >= 2.6\n- PyVmomi\n- vSphere Automation SDK\noptions:\n    ovf_template:\n      description:\n      - The name of OVF template from which VM to be deployed.\n      type: str\n      required: True\n      aliases: ['ovf', 'template_src']\n    content_library:\n      description:\n      - The name of the content library from where the template resides.\n      type: str\n      required: False\n      version_added: '1.5.0'\n    name:\n      description:\n      - The name of the VM to be deployed.\n      type: str\n      required: True\n      aliases: ['vm_name']\n    datacenter:\n      description:\n      - Name of the datacenter, where VM to be deployed.\n      type: str\n      required: True\n    datastore:\n      description:\n      - Name of the datastore to store deployed VM and disk.\n      type: str\n      required: True\n    folder:\n      description:\n      - Name of the folder in datacenter in which to place deployed VM.\n      type: str\n      required: True\n    host:\n      description:\n      - Name of the ESX Host in datacenter in which to place deployed VM. The host has to be a member of the cluster that contains the resource pool.\n      type: str\n      required: True\n    resource_pool:\n      description:\n      - Name of the resourcepool in datacenter in which to place deployed VM.\n      type: str\n      required: True\n    cluster:\n      description:\n      - Name of the cluster in datacenter in which to place deployed VM.\n      type: str\n      required: False\n    storage_provisioning:\n      description:\n      - Default storage provisioning type to use for all sections of type vmw:StorageSection in the OVF descriptor.\n      type: str\n      choices: [ thin, thick, eagerZeroedThick ]\nextends_documentation_fragment: community.vmware.vmware_rest_client.documentation\n'''\n\nEXAMPLES = r'''\n- name: Deploy Virtual Machine from OVF template in content library\n  community.vmware.vmware_content_deploy_ovf_template:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    ovf_template: rhel_test_template\n    datastore: Shared_NFS_Volume\n    folder: vm\n    datacenter: Sample_DC_1\n    name: Sample_VM\n    resource_pool: test_rp\n  delegate_to: localhost\n\n- name: Deploy Virtual Machine from OVF template in content library with eagerZeroedThick storage\n  vmware_content_deploy_ovf_template:\n    hostname: '{{ vcenter_hostname }}'\n    username: '{{ vcenter_username }}'\n    password: '{{ vcenter_password }}'\n    ovf_template: rhel_test_template\n    datastore: Shared_NFS_Volume\n    folder: vm\n    datacenter: Sample_DC_1\n    name: Sample_VM\n    resource_pool: test_rp\n    storage_provisioning: eagerZeroedThick\n  delegate_to: localhost\n'''\n\nRETURN = r'''\nvm_deploy_info:\n  description: Virtual machine deployment message and vm_id\n  returned: on success\n  type: dict\n  sample: {\n        \"msg\": \"Deployed Virtual Machine 'Sample_VM'.\",\n        \"vm_id\": \"vm-1009\"\n    }\n'''\n\nfrom ansible.module_utils.basic import AnsibleModule\nfrom ansible.module_utils._text import to_native\nfrom ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient\nfrom ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi\n\nHAS_VAUTOMATION_PYTHON_SDK = False\ntry:\n    from com.vmware.vcenter.ovf_client import LibraryItem\n    from com.vmware.vapi.std.errors_client import Error\n    HAS_VAUTOMATION_PYTHON_SDK = True\nexcept ImportError:\n    pass\n\n\nclass VmwareContentDeployOvfTemplate(VmwareRestClient):\n    def __init__(self, module):\n        \"\"\"Constructor.\"\"\"\n        super(VmwareContentDeployOvfTemplate, self).__init__(module)\n        self.ovf_template_name = self.params.get('ovf_template')\n        self.content_library_name = self.params.get('content_library')\n        self.vm_name = self.params.get('name')\n        self.datacenter = self.params.get('datacenter')\n        self.datastore = self.params.get('datastore')\n        self.folder = self.params.get('folder')\n        self.resourcepool = self.params.get('resource_pool')\n        self.cluster = self.params.get('cluster')\n        self.host = self.params.get('host')\n        self.storage_provisioning = self.params.get('storage_provisioning')\n\n    def deploy_vm_from_ovf_template(self):\n        # Find the datacenter by the given datacenter name\n        self.datacenter_id = self.get_datacenter_by_name(datacenter_name=self.datacenter)\n        if not self.datacenter_id:\n            self.module.fail_json(msg=\"Failed to find the datacenter %s\" % self.datacenter)\n        # Find the datastore by the given datastore name\n        self.datastore_id = self.get_datastore_by_name(self.datacenter, self.datastore)\n        if not self.datastore_id:\n            self.module.fail_json(msg=\"Failed to find the datastore %s\" % self.datastore)\n        # Find the LibraryItem (Template) by the given LibraryItem name\n        if self.content_library_name:\n            self.library_item_id = self.get_library_item_from_content_library_name(\n                self.ovf_template_name, self.content_library_name)\n            if not self.library_item_id:\n                self.module.fail_json(msg=\"Failed to find the library Item %s in content library %s\" % (self.ovf_template_name, self.content_library_name))\n        else:\n            self.library_item_id = self.get_library_item_by_name(self.ovf_template_name)\n            if not self.library_item_id:\n                self.module.fail_json(msg=\"Failed to find the library Item %s\" % self.ovf_template_name)\n        # Find the folder by the given folder name\n        self.folder_id = self.get_folder_by_name(self.datacenter, self.folder)\n        if not self.folder_id:\n            self.module.fail_json(msg=\"Failed to find the folder %s\" % self.folder)\n        # Find the Host by given HostName\n        self.host_id = self.get_host_by_name(self.datacenter, self.host)\n        if not self.host_id:\n            self.module.fail_json(msg=\"Failed to find the Host %s\" % self.host)\n        # Find the resourcepool by the given resourcepool name\n        self.resourcepool_id = self.get_resource_pool_by_name(self.datacenter, self.resourcepool, self.cluster, self.host)\n        if not self.resourcepool_id:\n            self.module.fail_json(msg=\"Failed to find the resource_pool %s\" % self.resourcepool)\n        # Find the Cluster by the given Cluster name\n        self.cluster_id = None\n        if self.cluster:\n            self.cluster_id = self.get_cluster_by_name(self.datacenter, self.cluster)\n            if not self.cluster_id:\n                self.module.fail_json(msg=\"Failed to find the Cluster %s\" % self.cluster)\n\n        deployment_target = LibraryItem.DeploymentTarget(\n            resource_pool_id=self.resourcepool_id,\n            folder_id=self.folder_id\n        )\n\n        self.ovf_summary = self.api_client.vcenter.ovf.LibraryItem.filter(\n            ovf_library_item_id=self.library_item_id,\n            target=deployment_target)\n\n        self.deploy_spec = LibraryItem.ResourcePoolDeploymentSpec(\n            name=self.vm_name,\n            annotation=self.ovf_summary.annotation,\n            accept_all_eula=True,\n            network_mappings=None,\n            storage_mappings=None,\n            storage_provisioning=self.storage_provisioning,\n            storage_profile_id=None,\n            locale=None,\n            flags=None,\n            additional_parameters=None,\n            default_datastore_id=self.datastore_id)\n\n        result = {\n            'succeeded': False\n        }\n        try:\n            result = self.api_client.vcenter.ovf.LibraryItem.deploy(self.library_item_id, deployment_target, self.deploy_spec)\n        except Error as error:\n            self.module.fail_json(msg=\"%s\" % self.get_error_message(error))\n        except Exception as err:\n            self.module.fail_json(msg=\"%s\" % to_native(err))\n\n        if result.succeeded:\n            self.module.exit_json(\n                changed=True,\n                vm_deploy_info=dict(\n                    msg=\"Deployed Virtual Machine '%s'.\" % self.vm_name,\n                    vm_id=result.resource_id.id,\n                )\n            )\n        self.module.exit_json(changed=False,\n                              vm_deploy_info=dict(msg=\"Virtual Machine deployment failed\", vm_id=''))\n\n\ndef main():\n    argument_spec = VmwareRestClient.vmware_client_argument_spec()\n    argument_spec.update(\n        ovf_template=dict(type='str', aliases=['template_src', 'ovf'], required=True),\n        content_library=dict(type='str', required=False),\n        name=dict(type='str', required=True, aliases=['vm_name']),\n        datacenter=dict(type='str', required=True),\n        datastore=dict(type='str', required=True),\n        folder=dict(type='str', required=True),\n        host=dict(type='str', required=True),\n        resource_pool=dict(type='str', required=True),\n        cluster=dict(type='str', required=False),\n        storage_provisioning=dict(type='str',\n                                  required=False,\n                                  choices=['thin', 'thick', 'eagerZeroedThick'],\n                                  default=None),\n    )\n    module = AnsibleModule(argument_spec=argument_spec,\n                           supports_check_mode=True)\n    result = {'failed': False, 'changed': False}\n    pyv = PyVmomi(module=module)\n    vm = pyv.get_vm()\n    if vm:\n        module.exit_json(\n            changed=False,\n            vm_deploy_info=dict(\n                msg=\"Virtual Machine '%s' already Exists.\" % module.params['name'],\n                vm_id=vm._moId,\n            )\n        )\n    vmware_contentlib_create = VmwareContentDeployOvfTemplate(module)\n    if module.check_mode:\n        result.update(\n            vm_name=module.params['name'],\n            changed=True,\n            desired_operation='Create VM with PowerOff State',\n        )\n        module.exit_json(**result)\n    vmware_contentlib_create.deploy_vm_from_ovf_template()\n\n\nif __name__ == '__main__':\n    main()\n", "path": "plugins/modules/vmware_content_deploy_ovf_template.py"}]}