From 34ef77f6ba52f77cbe1a49d19d9e5caea9b7e699 Mon Sep 17 00:00:00 2001 From: Laurent G Date: Fri, 25 Sep 2020 16:30:04 +0200 Subject: [PATCH] Ensure that VM are created on the requested ESXi host (#400) Ensure that VM are created on the requested ESXi host Reviewed-by: https://github.com/apps/ansible-zuul --- changelogs/fragments/400-vm-created-on-specified-host.yml | 3 +++ plugins/modules/vmware_guest.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/400-vm-created-on-specified-host.yml diff --git a/changelogs/fragments/400-vm-created-on-specified-host.yml b/changelogs/fragments/400-vm-created-on-specified-host.yml new file mode 100644 index 000000000..0b519aaa3 --- /dev/null +++ b/changelogs/fragments/400-vm-created-on-specified-host.yml @@ -0,0 +1,3 @@ +minor_changes: + - vmware_guest - takes now into account the ``esxi_hostname`` argument to create the vm on the right host + according to the doc (https://github.com/ansible-collections/vmware/pull/359). diff --git a/plugins/modules/vmware_guest.py b/plugins/modules/vmware_guest.py index 381d24d8a..869cccf88 100644 --- a/plugins/modules/vmware_guest.py +++ b/plugins/modules/vmware_guest.py @@ -3157,10 +3157,14 @@ def deploy_vm(self): snapshotDirectory=None, suspendDirectory=None, vmPathName="[" + datastore_name + "]") + esx_host = None + # Only select specific host when ESXi hostname is provided + if self.params['esxi_hostname']: + esx_host = self.select_host() clone_method = 'CreateVM_Task' try: - task = destfolder.CreateVM_Task(config=self.configspec, pool=resource_pool) + task = destfolder.CreateVM_Task(config=self.configspec, pool=resource_pool, host=esx_host) except vmodl.fault.InvalidRequest as e: self.module.fail_json(msg="Failed to create virtual machine due to invalid configuration " "parameter %s" % to_native(e.msg))