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

parser = ConfigParser({
            'vcenter_port': '443',
            'vmware_proxy_host': '',
            'vmware_proxy_port': ''})
        parser.read(self.config_static_path)
        self.endpoint = parser.get('DEFAULT', 'vcenter_hostname')
        self.port = parser.get('DEFAULT', 'vcenter_port')
        if parser.get('DEFAULT', 'vmware_validate_certs').lower() in ('no', 'false'):
            self.insecure = True
        proxy_host = parser.get('DEFAULT', 'vmware_proxy_host')
        proxy_port = int(parser.get('DEFAULT', 'vmware_proxy_port'))
        if proxy_host and proxy_port:
            self.proxy = 'http://%s:%d' % (proxy_host, proxy_port)
        self._wait_for_service()
    def _wait_for_service(self):
        """Wait for the vCenter service endpoint to accept connections."""
        if self.args.explain:
            return
        client = HttpClient(self.args, always=True, insecure=self.insecure, proxy=self.proxy)
        endpoint = 'https://%s:%s' % (self.endpoint, self.port)
        for i in range(1, 30):
            display.info('Waiting for vCenter service: %s' % endpoint, verbosity=1)
            try:
                client.get(endpoint)
                return
            except SubprocessError:
                pass
            time.sleep(10)
        raise ApplicationError('Timeout waiting for vCenter service.')
class VcenterEnvironment(CloudEnvironment):