Unable to use the module to query Vmware host

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

pyvmomi needs to be installed on the machine on which you execute
vmware_get_facts.

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

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

This is my play

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.

  tasks:
  - name: Gather Vmware Facts
    delegate_to: localhost
    vmware_vm_facts:
     hostname: SAE3201
     username: root
     password: XXXXX
     validate_certs: false

Hi Brian,

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

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.

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…

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

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

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

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

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
   vmware_vm_facts:
     hostname: SAE3201
     username: root
     password: XXXXX
     validate_certs: false
   delegate_to: localhost
   register: vm_results

- debug: var=results

Hi Kai… ur a star!!

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