diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index f8f5b1cf16c..275fa250b22 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -1086,7 +1086,7 @@ class PyVmomiHelper(object): datastore_freespace = 0 for ds in datastores: - if ds.summary.freeSpace > datastore_freespace: + if (ds.summary.freeSpace > datastore_freespace) or (ds.summary.freeSpace == datastore_freespace and not datastore): # If datastore field is provided, filter destination datastores if 'datastore' in self.params['disk'][0] and \ isinstance(self.params['disk'][0]['datastore'], str) and \ diff --git a/test/integration/targets/vmware_guest/tasks/clone_d1_c1_f0.yml b/test/integration/targets/vmware_guest/tasks/clone_d1_c1_f0.yml new file mode 100644 index 00000000000..fb677ea9177 --- /dev/null +++ b/test/integration/targets/vmware_guest/tasks/clone_d1_c1_f0.yml @@ -0,0 +1,40 @@ +- name: kill vcsim + uri: + url: "{{ 'http://' + vcsim + ':5000/killall' }}" +- name: start vcsim with no folders + uri: + url: "{{ 'http://' + vcsim + ':5000/spawn?datacenter=1&cluster=1&folder=0' }}" + register: vcsim_instance + +- name: get a list of VMS from vcsim + uri: + url: "{{ 'http://' + vcsim + ':5000/govc_find?filter=VM' }}" + register: vmlist + +- debug: var=vcsim_instance +- debug: var=vmlist + +- name: set state to poweroff on all VMs + vmware_guest: + validate_certs: False + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + name: "{{ 'newvm_' + item|basename }}" + template: "{{ item|basename }}" + datacenter: "{{ (item|basename).split('_')[0] }}" + disk: + - size: 0gb + type: thin + autoselect_datastore: True + state: poweredoff + folder: "{{ item|dirname }}" + with_items: "{{ vmlist['json'] }}" + register: clone_d1_c1_f0 + +- debug: var=clone_d1_c1_f0 + +- name: assert that changes were made + assert: + that: + - "clone_d1_c1_f0.results|map(attribute='changed')|unique|list == [true]" diff --git a/test/integration/targets/vmware_guest/tasks/main.yml b/test/integration/targets/vmware_guest/tasks/main.yml index 16a812151b1..9a8b5856c2e 100644 --- a/test/integration/targets/vmware_guest/tasks/main.yml +++ b/test/integration/targets/vmware_guest/tasks/main.yml @@ -2,6 +2,7 @@ pip: name: pyvmomi state: latest + when: "{{ ansible_user_id == 'root' }}" - name: store the vcenter container ip set_fact: @@ -10,3 +11,4 @@ - include: poweroff_d1_c1_f0.yml - include: poweroff_d1_c1_f1.yml +- include: clone_d1_c1_f0.yml