##### SUMMARY

The following snippet from https://github.com/ansible/ansible/blob/devel/test/integration/targets/vmware_guest/tasks/create_d1_c1_f0.yml uses `autoselect_datastore: True`.

```yaml
- name: create new VMs
  vmware_guest:
    validate_certs: False
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: newvm_1
    #template: "{{ item|basename }}"
    guest_id: centos64Guest
    datacenter: "{{ dc1 }}"
    hardware:
        num_cpus: 1
        num_cpu_cores_per_socket: 1
        memory_mb: 256
        hotadd_memory: true
        hotadd_cpu: false
        max_connections: 10
    disk:
        - size: 1gb
          type: thin
          autoselect_datastore: True
    state: poweredoff
    folder: F0
```

One of my two datastores is dedicated to the ISO image and so, is readOnly. But it still get selected consistently. I use the following hack to avoid the problem:

```diff
diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py
index 6a63e97798..3648e3e87f 100644
--- a/lib/ansible/modules/cloud/vmware/vmware_guest.py
+++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py
@@ -1925,6 +1925,15 @@ class PyVmomiHelper(PyVmomi):
 
                 datastore_freespace = 0
                 for ds in datastores:
+                    is_readonly = False
+                    for h in ds.host:
+                        if h.mountInfo.accessMode == 'readOnly':
+                            is_readonly = True
+                            break
+
+                    if is_readonly:
+                        continue
+
                     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 \
```
<!--- Explain the problem briefly below -->

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->

vmware_guest

except vim.fault.AlreadyUpgraded:
                        
                        pass
            if 'virt_based_security' in self.params['hardware']:
                host_version = self.select_host().summary.config.product.version
                if int(host_version.split('.')[0]) < 6 or (int(host_version.split('.')[0]) == 6 and int(host_version.split('.')[1]) < 7):
                    self.module.fail_json(msg="ESXi version %s not support VBS." % host_version)
                guest_ids = ['windows9_64Guest', 'windows9Server64Guest']
                if vm_obj is None:
                    guestid = self.configspec.guestId
                else:
                    guestid = vm_obj.summary.config.guestId
                if guestid not in guest_ids:
                    self.module.fail_json(msg="Guest '%s' not support VBS." % guestid)
                if (vm_obj is None and int(self.configspec.version.split('-')[1]) >= 14) or \
                        (vm_obj and int(vm_obj.config.version.split('-')[1]) >= 14 and (vm_obj.runtime.powerState == vim.VirtualMachinePowerState.poweredOff)):
                    self.configspec.flags = vim.vm.FlagInfo()
                    self.configspec.flags.vbsEnabled = bool(self.params['hardware']['virt_based_security'])
                    if bool(self.params['hardware']['virt_based_security']):
                        self.configspec.flags.vvtdEnabled = True
                        self.configspec.nestedHVEnabled = True
                        if (vm_obj is None and self.configspec.firmware == 'efi') or \
                                (vm_obj and vm_obj.config.firmware == 'efi'):
                            self.configspec.bootOptions = vim.vm.BootOptions()
                            self.configspec.bootOptions.efiSecureBootEnabled = True
                        else:
                            self.module.fail_json(msg="Not support VBS when firmware is BIOS.")
                    if vm_obj is None or self.configspec.flags.vbsEnabled != vm_obj.config.flags.vbsEnabled:
                        self.change_detected = True
    def get_device_by_type(self, vm=None, type=None):