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

version_added: '2.3'
  folder:
    description:
    - Destination folder, absolute path to find an existing guest or create the new guest.
    - The folder should include the datacenter. ESX's datacenter is ha-datacenter.
    - This parameter is case sensitive.
    - This parameter is required, while deploying new virtual machine. version_added 2.5.
    - 'If multiple machines are found with same name, this parameter is used to identify
       uniqueness of the virtual machine. version_added 2.5'
    - 'Examples:'
    - '   folder: /ha-datacenter/vm'
    - '   folder: ha-datacenter/vm'
    - '   folder: /datacenter1/vm'
    - '   folder: datacenter1/vm'
    - '   folder: /datacenter1/vm/folder1'
    - '   folder: datacenter1/vm/folder1'
    - '   folder: /folder1/datacenter1/vm'
    - '   folder: folder1/datacenter1/vm'
    - '   folder: /folder1/datacenter1/vm/folder2'
  hardware:
    description:
    - Manage virtual machine's hardware attributes.
    - All parameters case sensitive.
    - 'Valid attributes are:'
    - ' - C(hotadd_cpu) (boolean): Allow virtual CPUs to be added while the virtual machine is running.'
    - ' - C(hotremove_cpu) (boolean): Allow virtual CPUs to be removed while the virtual machine is running.
          version_added: 2.5'
    - ' - C(hotadd_memory) (boolean): Allow memory to be added while the virtual machine is running.'
    - ' - C(memory_mb) (integer): Amount of memory in MB.'
    - ' - C(nested_virt) (bool): Enable nested virtualization. version_added: 2.5'