Unable to use the module to query Vmware host

1,210 views
Skip to first unread message

Alstar Films

unread,
Mar 21, 2017, 11:42:52 AM3/21/17
to Ansible Project

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

Brian Coca

unread,
Mar 21, 2017, 11:50:05 AM3/21/17
to Ansible Project
pyvmomi needs to be installed on the machine on which you execute
vmware_get_facts.


----------
Brian Coca

Alstar Films

unread,
Mar 21, 2017, 11:54:23 AM3/21/17
to Ansible Project
That would be my CentOS machine from which I am running the command correct?

Brian Coca

unread,
Mar 21, 2017, 2:36:16 PM3/21/17
to Ansible Project
Depends, cannot say w/o looking at play and verbose output


----------
Brian Coca

Alstar Films

unread,
Mar 21, 2017, 2:53:40 PM3/21/17
to Ansible Project
This is my play

---
- hosts: vmware
  connection: ssh
  become: yes
  become_method: sudo
  gather_facts: no

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

This is my error log

Using module file /usr/lib/python2.7/site-packages/ansible/modules/extras/cloud/vmware/vmware_vm_facts.py
ESTABLISH SSH CONNECTION FOR USER: root
SSH: EXEC sshpass -d13 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/ansible-ssh-%h-%p-%r sae3201 '/bin/sh -c '"'"'( umask 77 && mkdir -p "echo ~/.ansible/tmp/ansible-tmp-1490120215.48-188286845186507" && echo ansible-tmp-1490120215.48-188286845186507="echo ~/.ansible/tmp/ansible-tmp-1490120215.48-188286845186507" ) && sleep 0'"'"''
PUT /tmp/tmpovJ3oH TO //.ansible/tmp/ansible-tmp-1490120215.48-188286845186507/vmware_vm_facts.py
SSH: EXEC sshpass -d13 sftp -o BatchMode=no -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/ansible-ssh-%h-%p-%r '[sae3201]'
ESTABLISH SSH CONNECTION FOR USER: root
SSH: EXEC sshpass -d13 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/ansible-ssh-%h-%p-%r sae3201 '/bin/sh -c '"'"'chmod u+x //.ansible/tmp/ansible-tmp-1490120215.48-188286845186507/ //.ansible/tmp/ansible-tmp-1490120215.48-188286845186507/vmware_vm_facts.py && sleep 0'"'"''
ESTABLISH SSH CONNECTION FOR USER: root
SSH: EXEC sshpass -d13 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/ansible-ssh-%h-%p-%r -tt sae3201 '/bin/sh -c '"'"'/usr/bin/python //.ansible/tmp/ansible-tmp-1490120215.48-188286845186507/vmware_vm_facts.py; rm -rf "//.ansible/tmp/ansible-tmp-1490120215.48-188286845186507/" > /dev/null 2>&1 && sleep 0'"'"''
fatal: [sae3201]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"hostname": "sae3201",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"username": "root",
"validate_certs": false
},
"module_name": "vmware_vm_facts"
},

"msg": "pyvmomi is required for this module"

On Tuesday, March 21, 2017 at 7:42:52 PM UTC+4, Alstar Films wrote:

Brian Coca

unread,
Mar 21, 2017, 4:45:10 PM3/21/17
to Ansible Project
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


----------
Brian Coca

Alstar Films

unread,
Mar 24, 2017, 7:39:58 AM3/24/17
to Ansible Project
Hi Brian,

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

===============

==================
[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




On Tuesday, March 21, 2017 at 7:42:52 PM UTC+4, Alstar Films wrote:

Kai Stian Olstad

unread,
Mar 24, 2017, 8:21:39 AM3/24/17
to ansible...@googlegroups.com
On 24.03.2017 12:39, Alstar Films wrote:
> 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.

--
Kai Stian Olstad

Alstar Films

unread,
Mar 24, 2017, 8:47:52 AM3/24/17
to Ansible Project
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...


On Tuesday, March 21, 2017 at 7:42:52 PM UTC+4, Alstar Films wrote:

Kai Stian Olstad

unread,
Mar 24, 2017, 8:57:31 AM3/24/17
to ansible...@googlegroups.com
On 24.03.2017 13:47, Alstar Films wrote:
> 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.

--
Kai Stian Olstad

Alstar Films

unread,
Mar 24, 2017, 9:01:16 AM3/24/17
to Ansible Project
Thanks Kai! the -v did the trick and I can now see all the vm's listed! Fun times


On Tuesday, March 21, 2017 at 7:42:52 PM UTC+4, Alstar Films wrote:

Alstar Films

unread,
Mar 24, 2017, 9:03:01 AM3/24/17
to Ansible Project
The formatting of the output is a little messy but will see if i can get a clean output somehow..


On Tuesday, March 21, 2017 at 7:42:52 PM UTC+4, Alstar Films wrote:

Kai Stian Olstad

unread,
Mar 24, 2017, 9:20:46 AM3/24/17
to ansible...@googlegroups.com
On 24.03.2017 14:03, Alstar Films wrote:
> 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


--
Kai Stian Olstad

Alstar Films

unread,
Mar 24, 2017, 9:45:56 AM3/24/17
to Ansible Project
Hi Kai.. ur a star!!


On Tuesday, March 21, 2017 at 7:42:52 PM UTC+4, Alstar Films wrote:

ameri...@optonline.net

unread,
May 16, 2017, 9:02:23 AM5/16/17
to Ansible Project
Hi Kai thank you for you help I just got mine to work as well with you info you provided.
Reply all
Reply to author
Forward
0 new messages