Skip to content

Commit

Permalink
Ensure that VM are created on the requested ESXi host (#400)
Browse files Browse the repository at this point in the history
Ensure that VM are created on the requested ESXi host

Reviewed-by: https://github.com/apps/ansible-zuul
  • Loading branch information
xenlo authored Sep 25, 2020
1 parent 13bdb32 commit 34ef77f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/fragments/400-vm-created-on-specified-host.yml
Original file line number Diff line number Diff line change
@@ -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).
6 changes: 5 additions & 1 deletion plugins/modules/vmware_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 34ef77f

Please sign in to comment.