# Unable to use the module to query Vmware host

**URL:** <https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [March 21, 2017, 3:42pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024 "2017-03-21T15:42:52Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alstar\_Films](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@Alstar\_Films](https://forum.ansible.com/u/Alstar_Films)\
**Post date:** [March 21, 2017, 3:42pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/1 "2017-03-21T15:42:52Z")

</div>

Hi Guys,

For the most part I have got anisble almost working to talk to my Esxi host. I have created my playbook to use the module “vmware\_get\_facts” but when I run my “ansible-playbook vmware.yml” file I get the error

“FAILED! =\> {“changed”: false, “failed”: true, “msg”: “pyvmomi is required for this module”}  
[WARNING]: Could not create retry file ‘/etc/ansible/playbooks/vmware.retry’. [Errno 13] Permission denied: u’/etc/ansible/playbooks/vmware.retry’”

My python version is 2.7 and I have installed the PyVmomi module using pip install pyvmomi and then pip install --upgrade pyvmomi, however i still get the error which says the module isnt installed? (wierd).  
I have gotten past all the authentication errors but sadly stuck on this…

Any ideas?!

-A

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 21, 2017, 3:49pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/2 "2017-03-21T15:49:50Z")

</div>

pyvmomi needs to be installed on the machine on which you execute  
vmware\_get\_facts.

---

<div class="post-metadata">

**Author:** ![Alstar\_Films](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@Alstar\_Films](https://forum.ansible.com/u/Alstar_Films)\
**Post date:** [March 21, 2017, 3:54pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/3 "2017-03-21T15:54:23Z")

</div>

That would be my CentOS machine from which I am running the command correct?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 21, 2017, 6:36pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/4 "2017-03-21T18:36:03Z")

</div>

Depends, cannot say w/o looking at play and verbose output

---

<div class="post-metadata">

**Author:** ![Alstar\_Films](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@Alstar\_Films](https://forum.ansible.com/u/Alstar_Films)\
**Post date:** [March 21, 2017, 6:53pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/5 "2017-03-21T18:53:40Z")

</div>

**This is my play**

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 21, 2017, 8:45pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/6 "2017-03-21T20:45:02Z")

</div>

the plugin is not designed to run on the vm itself, but against  
vsphere, since you installed the library on the controller, that is  
where you need to run it (i added delegate\_to: localhost for this).  
Otherwise you would need it installed on the target vm and have it  
access vsphere.

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;- name: Gather Vmware Facts  
&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: localhost  
&nbsp;&nbsp;&nbsp;&nbsp;vmware\_vm\_facts:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hostname: SAE3201  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username: root  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password: XXXXX  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;validate\_certs: false

---

<div class="post-metadata">

**Author:** ![Alstar\_Films](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@Alstar\_Films](https://forum.ansible.com/u/Alstar_Films)\
**Post date:** [March 24, 2017, 11:39am UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/7 "2017-03-24T11:39:58Z")

</div>

Hi Brian,

I ran the playbook with the locahost option and this is what I get now… I expected a different result though

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 24, 2017, 12:21pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/8 "2017-03-24T12:21:20Z")

</div>

> Hi Brian,
> 
> I ran the playbook with the locahost option and this is what I get now.. I  
> expected a different result though

And what did you expect? We are mind readers, yet...

> [ansible@ansible ansible]$ sudo ansible-playbook playbooks/vmware.yml
> 
> PLAY [sae3201]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> TASK [setup]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [sae3201]
> 
> TASK [Gather Vmware Facts]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [sae3201 -\> localhost]
> 
> PLAY RECAP  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> sae3201 : ok=2 changed=0 unreachable=0 failed=0

It's working fine, everything is ok.

---

<div class="post-metadata">

**Author:** ![Alstar\_Films](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@Alstar\_Films](https://forum.ansible.com/u/Alstar_Films)\
**Post date:** [March 24, 2017, 12:47pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/9 "2017-03-24T12:47:51Z")

</div>

Sure, I should have been a little more detailed in my expectation then. What I meant was that the output doesn’t tell me anything worthwhile, unless this is what the module is meant for. It just queried my vmware host and reported back saying OK? I mean what “facts” did it gather or outputted? Unless this is the purpose of the module…

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 24, 2017, 12:57pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/10 "2017-03-24T12:57:08Z")

</div>

You can add -v to ansible-playbook and you see the output of the modules on screen.

If you would like to use the values in Ansible you will need register the output in a variable  
[https://docs.ansible.com/ansible/playbooks\_variables.html#registered-variables](https://docs.ansible.com/ansible/playbooks_variables.html#registered-variables)

To get the content of the variable on screen you can use the debug module to print out the content.

---

<div class="post-metadata">

**Author:** ![Alstar\_Films](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@Alstar\_Films](https://forum.ansible.com/u/Alstar_Films)\
**Post date:** [March 24, 2017, 1:01pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/11 "2017-03-24T13:01:16Z")

</div>

Thanks Kai! the -v did the trick and I can now see all the vm’s listed! Fun times

---

<div class="post-metadata">

**Author:** ![Alstar\_Films](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@Alstar\_Films](https://forum.ansible.com/u/Alstar_Films)\
**Post date:** [March 24, 2017, 1:03pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/12 "2017-03-24T13:03:01Z")

</div>

The formatting of the output is a little messy but will see if i can get a clean output somehow…

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 24, 2017, 1:20pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/13 "2017-03-24T13:20:29Z")

</div>

You can add this under the [defaults] section in ansible.cfg to get a more human readable format.

stdout\_callback = debug

or you can register the output and print it.

- name: Gather Vmware Facts  
&nbsp;&nbsp;&nbsp;vmware\_vm\_facts:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hostname: SAE3201  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username: root  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password: XXXXX  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;validate\_certs: false  
&nbsp;&nbsp;&nbsp;delegate\_to: localhost  
&nbsp;&nbsp;&nbsp;register: vm\_results

- debug: var=results

---

<div class="post-metadata">

**Author:** ![Alstar\_Films](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@Alstar\_Films](https://forum.ansible.com/u/Alstar_Films)\
**Post date:** [March 24, 2017, 1:45pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/14 "2017-03-24T13:45:56Z")

</div>

Hi Kai… ur a star!!

---

<div class="post-metadata">

**Author:** ![americanoz](https://avatars.discourse-cdn.com/v4/letter/a/5e9695/32.png) [@americanoz](https://forum.ansible.com/u/americanoz)\
**Post date:** [May 16, 2017, 1:02pm UTC](https://forum.ansible.com/t/unable-to-use-the-module-to-query-vmware-host/24024/15 "2017-05-16T13:02:23Z")

</div>

Hi Kai thank you for you help I just got mine to work as well with you info you provided.
