Repository: ansible/ansible

Issue:
Unable to use the module to query Vmware host
##### ISSUE TYPE
Bug Report

##### COMPONENT NAME
vmware_vm_facts module

##### ANSIBLE VERSION
N/A

##### SUMMARY
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


Discussion:
Can you paste the latest error log verbatim ?
Using module file /usr/lib/python2.7/site-packages/ansible/modules/extras/cloud/vmware/vmware_vm_facts.py
<sae3201> ESTABLISH SSH CONNECTION FOR USER: root
<sae3201> 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'"'"''
<sae3201> PUT /tmp/tmpovJ3oH TO //.ansible/tmp/ansible-tmp-1490120215.48-188286845186507/vmware_vm_facts.py
<sae3201> 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]'
<sae3201> ESTABLISH SSH CONNECTION FOR USER: root
<sae3201> 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'"'"''
<sae3201> ESTABLISH SSH CONNECTION FOR USER: root
<sae3201> 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"**

It requires pyvmomi on the server you are running this module on. Usually you delegate this task to localhost (if it can connect to your vCenter infrastructure) or some other target. But it's that target that requires pyvmomi.

needs_info

**BTW You did not fill out the issue template. Please don't do that, because this issue is now not triggering the right people.**
@alstarian Let us know if that's the issue.  If we don't hear back we'll assume that's what's going on and close in a few days.  Thanks!
Hi,
has the same issue : 

OS: Red Hat Enterprise Linux Server release 7.3 (Maipo)
ansible : ansible-2.2.1.0-1.el7.noarch
pyvmomi : python2-pyvmomi-6.5-1.el7.noarch

All patched to the latest lvl.

So i get the msg : "msg": "pyvmomi is required for this module"


@wernermarcel please provide a full -vvvv output.
Using module file /usr/lib/python2.7/site-packages/ansible/modules/extras/cloud/vmware/vmware_local_user_manager.py
<defr2eecsta01> ESTABLISH SSH CONNECTION FOR USER: None
<defr2eecsta01> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=22 -o 'IdentityFile="/root/.ssh/btid_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r defr2eecsta01 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /pkg/tmp/$HOME/.ansible/tmp/ansible-tmp-1490274005.4-7094170535863 `" && echo ansible-tmp-1490274005.4-7094170535863="` echo /pkg/tmp/$HOME/.ansible/tmp/ansible-tmp-1490274005.4-7094170535863 `" ) && sleep 0'"'"''
<defr2eecsta01> PUT /tmp/tmpq6d9fg TO /pkg/tmp///.ansible/tmp/ansible-tmp-1490274005.4-7094170535863/vmware_local_user_manager.py
<defr2eecsta01> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=22 -o 'IdentityFile="/root/.ssh/btid_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r '[defr2eecsta01]'
<defr2eecsta01> ESTABLISH SSH CONNECTION FOR USER: None
<defr2eecsta01> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=22 -o 'IdentityFile="/root/.ssh/btid_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r defr2eecsta01 '/bin/sh -c '"'"'chmod u+x /pkg/tmp///.ansible/tmp/ansible-tmp-1490274005.4-7094170535863/ /pkg/tmp///.ansible/tmp/ansible-tmp-1490274005.4-7094170535863/vmware_local_user_manager.py && sleep 0'"'"''
<defr2eecsta01> ESTABLISH SSH CONNECTION FOR USER: None
<defr2eecsta01> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=22 -o 'IdentityFile="/root/.ssh/btid_rsa"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r -tt defr2eecsta01 '/bin/sh -c '"'"'/usr/bin/python /pkg/tmp///.ansible/tmp/ansible-tmp-1490274005.4-7094170535863/vmware_local_user_manager.py; rm -rf "/pkg/tmp///.ansible/tmp/ansible-tmp-1490274005.4-7094170535863/" > /dev/null 2>&1 && sleep 0'"'"''
fatal: [defr2eecsta01]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "hostname": "defr2eecsta01", 
            "local_user_description": null, 
            "local_user_name": "root", 
            "local_user_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "state": "present", 
            "username": "root", 
            "validate_certs": false
        }, 
        "module_name": "vmware_local_user_manager"
    }, 
    "msg": "pyvmomi is required for this module"
}

@wernermarcel please run this command by hand ...

```
ssh defr2eecsta01 'python -c "from pyVmomi import vim"'
```
Hi , 
that returned nothing but that is normal so defr2eecsta01  is an ESXI Server . 

@wernermarcel As I mentioned a few comments above, you are running your module on the target (your ESX server) and not on a system that has pyvmomi installed. Please add: `delegate_to: localhost` to your task.

Resolving patch:
diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest_facts.py b/lib/ansible/modules/cloud/vmware/vmware_guest_facts.py
--- a/lib/ansible/modules/cloud/vmware/vmware_guest_facts.py
+++ b/lib/ansible/modules/cloud/vmware/vmware_guest_facts.py
@@ -63,15 +63,15 @@
 '''
 
 EXAMPLES = '''
-# Gather facts
-  - name: gather the VM facts
-    vmware_guest_facts:
-      hostname: 192.168.1.209
-      username: administrator@vsphere.local
-      password: vmware
-      validate_certs: no
-      uuid: 421e4592-c069-924d-ce20-7e7533fab926
-    register: facts
+- name: Gather VM facts
+  vmware_guest_facts:
+    hostname: 192.168.1.209
+    username: administrator@vsphere.local
+    password: vmware
+    validate_certs: no
+    uuid: 421e4592-c069-924d-ce20-7e7533fab926
+  delegate_to: localhost
+  register: facts
 '''
 
 RETURN = """


Test patch: