##### 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

property_info.type = property_spec.get('type', 'string')
                    property_info.userConfigurable = property_spec.get('userConfigurable', True)
                    property_info.defaultValue = property_spec.get('defaultValue')
                    property_info.value = property_spec.get('value', '')
                    property_info.description = property_spec.get('description')
                    new_vapp_property_spec.info = property_info
                    new_vapp_property_spec.info.key = new_property_index
                    new_property_index += 1
                    is_property_changed = True
                if is_property_changed:
                    new_vmconfig_spec.property.append(new_vapp_property_spec)
        else:
            
            all_keys = [x.key for x in new_vmconfig_spec.property]
            new_property_index = max(all_keys) + 1 if all_keys else 0
            vapp_properties_to_change = dict((x['id'], x) for x in self.params['vapp_properties'])
            is_property_changed = False
            for property_id, property_spec in vapp_properties_to_change.items():
                new_vapp_property_spec = vim.vApp.PropertySpec()
                
                new_vapp_property_spec.operation = 'add'
                property_info = vim.vApp.PropertyInfo()
                property_info.classId = property_spec.get('classId')
                property_info.instanceId = property_spec.get('instanceId')
                property_info.id = property_spec.get('id')
                property_info.category = property_spec.get('category')
                property_info.label = property_spec.get('label')
                property_info.type = property_spec.get('type', 'string')
                property_info.userConfigurable = property_spec.get('userConfigurable', True)
                property_info.defaultValue = property_spec.get('defaultValue')