# Ansible: vmware\_module does not work and flashes the error "Failed to find a matching datastore"

**URL:** <https://forum.ansible.com/t/ansible-vmware-module-does-not-work-and-flashes-the-error-failed-to-find-a-matching-datastore/25618>\
**Category:** Ansible Project\
**Created:** [September 28, 2017, 1:44am UTC](https://forum.ansible.com/t/ansible-vmware-module-does-not-work-and-flashes-the-error-failed-to-find-a-matching-datastore/25618 "2017-09-28T01:44:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor1](https://avatars.discourse-cdn.com/v4/letter/v/6de8d8/32.png) [@Victor1](https://forum.ansible.com/u/Victor1)\
**Post date:** [September 28, 2017, 1:44am UTC](https://forum.ansible.com/t/ansible-vmware-module-does-not-work-and-flashes-the-error-failed-to-find-a-matching-datastore/25618/1 "2017-09-28T01:44:17Z")

</div>

Hi ,

I have upgraded to ansible 2.4 and using vmware\_guest module to create a VM. I am getting “Failed to find a matching datastore”.  
same code works fine in ansiblke 2.3.

is this a known issue or am i missing something?

Thanks,  
Vijay

msg": “Failed to find a matching datastore”

Here is my ansible snippet:

**- name: Create a virtual machine from the datastore VM ( Using vGPU VM)**  
**local\_action:**  
**module: vmware\_guest**  
**hostname: ‘{{ hostname }}’**  
**username: ‘{{ username }}’**  
**password: ‘{{ password }}’**  
**name: ‘{{ guest\_name}}’**  
**esxi\_hostname: ‘{{ esxi\_hostname1 }}’**  
**# template: ‘’**  
**is\_template: no**  
**datacenter: ‘{{ datacenter\_name }}’**  
**state: poweredon**  
**validate\_certs: False**  
**register: taskresult**  
**ignore\_errors: True**

when i run with -vvvv option i see following parameters are passed:

**fatal: [xxxxxxxx → localhost]: FAILED! =\> {**  
**“changed”: false,**  
**“failed”: true,**  
**“invocation”: {**  
**“module\_args”: {**  
**“annotation”: null,**  
**“cluster”: null,**  
**“customization”: {},**  
**“customvalues”: [],**  
**“datacenter”: “Datacenter”,**  
**“disk”: [],**  
**“esxi\_hostname”: “10…x.x.x”,**  
**“folder”: “/vm”,**  
**“force”: false,**  
**“guest\_id”: null,**  
**“hardware”: {},**  
**“hostname”: “10.x.x.x”,**  
**“is\_template”: false,**  
**“name”: “myvgpu\_clone2”,**  
**“name\_match”: “first”,**  
**“networks”: [],**  
**“password”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,**  
**“resource\_pool”: null,**  
**“state”: “poweredon”,**  
**“template\_src”: null,**  
**“username”: “administrator@vsphere.local”,**  
**“uuid”: null,**  
**“validate\_certs”: false,**  
**“wait\_for\_ip\_address”: false**  
**}**  
**},**  
**“msg”: “Failed to find a matching datastore”**  
**}**  
**…ignoring**

I would appreciate your help if you could please help me in resolving this issue.

---

<div class="post-metadata">

**Author:** ![Sebastien\_Desbois](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@Sebastien\_Desbois](https://forum.ansible.com/u/Sebastien_Desbois)\
**Post date:** [September 28, 2017, 3:23pm UTC](https://forum.ansible.com/t/ansible-vmware-module-does-not-work-and-flashes-the-error-failed-to-find-a-matching-datastore/25618/2 "2017-09-28T15:23:22Z")

</div>

Hello,

when you don’t specify a datastore, ansible will use an autoselect\_datastore function to find a datastore for your VM.  
In this function, there is a check to see if there is enough space in the datastores list for your new VM.  
If not, no datastore is return by this function and you get the " **Failed to find a matching datastore" message.**

I think you need to check first if you have enough space in your datastores to host this new VM.

---

<div class="post-metadata">

**Author:** ![Victor1](https://avatars.discourse-cdn.com/v4/letter/v/6de8d8/32.png) [@Victor1](https://forum.ansible.com/u/Victor1)\
**Post date:** [September 28, 2017, 7:08pm UTC](https://forum.ansible.com/t/ansible-vmware-module-does-not-work-and-flashes-the-error-failed-to-find-a-matching-datastore/25618/3 "2017-09-28T19:08:43Z")

</div>

Thanks for your response !

I checked and Yes I do have enough space on my datastore.

-Vijay

---

<div class="post-metadata">

**Author:** ![Sebastien\_Desbois](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@Sebastien\_Desbois](https://forum.ansible.com/u/Sebastien_Desbois)\
**Post date:** [October 2, 2017, 2:55pm UTC](https://forum.ansible.com/t/ansible-vmware-module-does-not-work-and-flashes-the-error-failed-to-find-a-matching-datastore/25618/4 "2017-10-02T14:55:59Z")

</div>

Hello,

I did some tests with your snippet.  
This is not working and it’s normal.

Either you create the VM based on a template, and the result will be by default in the same datastore as the the template, or you create a VM from scratch and you specifu the disk parameters (size, type, autoselect\_datastore: true if you don’t want to specify the datastore) and all other required parameters.  
This is very strange because you are getting the " **Failed to find a matching datastore"** message first when you are missing 50 to 60% of the parameters needed to create a VM from scratch.

Either fill the template parameter or all the necessary parameters.

Regards,
