From 8bf122e97f648d0cf610abcad62fec7dd2556533 Mon Sep 17 00:00:00 2001 From: mooninite Date: Sat, 18 Aug 2018 01:37:13 -0500 Subject: [PATCH] vmware_deploy_ovf: Add cluster support (#43606) When a datacenter has multiple clusters it is required to use the cluster name to find the correct default resource pool to import OVF images to. Fixes issue 42644. Signed-off-by: Michael Cronenworth --- .../modules/cloud/vmware/vmware_deploy_ovf.py | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_deploy_ovf.py b/lib/ansible/modules/cloud/vmware/vmware_deploy_ovf.py index 04892796136..27b0be8b474 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_deploy_ovf.py +++ b/lib/ansible/modules/cloud/vmware/vmware_deploy_ovf.py @@ -31,6 +31,9 @@ options: default: ha-datacenter description: - Datacenter to deploy to. + cluster: + description: + - Cluster to deploy to. datastore: default: datastore1 description: @@ -138,8 +141,8 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six import string_types from ansible.module_utils.urls import generic_urlparse, open_url, urlparse, urlunparse from ansible.module_utils.vmware import (HAS_PYVMOMI, connect_to_api, find_datacenter_by_name, find_datastore_by_name, - find_network_by_name, find_resource_pool_by_name, find_vm_by_name, gather_vm_facts, - vmware_argument_spec, wait_for_task, wait_for_vm_ip) + find_network_by_name, find_resource_pool_by_name, find_vm_by_name, find_cluster_by_name, + gather_vm_facts, vmware_argument_spec, wait_for_task, wait_for_vm_ip) try: from ansible.module_utils.vmware import vim from pyVmomi import vmodl @@ -282,9 +285,16 @@ class VMwareDeployOvf: if not self.datacenter: self.module.fail_json(msg='%(datacenter)s could not be located' % self.params) - self.resource_pool = find_resource_pool_by_name(self.si, self.params['resource_pool']) - if not self.resource_pool: - self.module.fail_json(msg='%(resource_pool)s could not be located' % self.params) + if self.params['cluster']: + cluster = find_cluster_by_name(self.si, self.params['cluster']) + if cluster is None: + self.module.fail_json(msg="Unable to find cluster '%(cluster)s'" % self.params) + else: + self.resource_pool = cluster.resourcePool + else: + self.resource_pool = find_resource_pool_by_name(self.si, self.params['resource_pool']) + if not self.resource_pool: + self.module.fail_json(msg='%(resource_pool)s could not be located' % self.params) for key, value in self.params['networks'].items(): network = find_network_by_name(self.si, value) @@ -509,6 +519,9 @@ def main(): 'datacenter': { 'default': 'ha-datacenter', }, + 'cluster': { + 'default': None, + }, 'deployment_option': { 'default': None, },