Get basic vmware module working - vmware_guest_find

Hi,

I’m having issues with getting basic VMware modules working. For example vmware_guest_find. I’m running the below from a RHEL 7 server.

Versions installed:

`
pyvmomi 6.7.0
ansible 2.5.2
vSphere vCenter 6.0

`

playbook:

`

It looks like your problem is using the “vm_hostname” in the task.

In my experiments, I either use “{{ inventory_hostname }}” for a per vm/host/target definition in the hosts group or a “with_items” loop:

`

  • name: Find Guest’s Folder using name
    vmware_guest_find:
    hostname: “{{ vmware_esxi.hostname }}”
    validate_certs: “{{ vmware_esxi.validate_certs }}”
    username: “{{ vmware_esxi.username }}”
    password: “{{ vmware_esxi.password }}”
    datacenter: “{{ vmware_esxi.datacenter }}”
    name: “{{ item }}”
    delegate_to: localhost
    tags: findvm
    with_items:
  • “{{ vm_hostname }}”
    `

Hi Nick,

Thanks for the response. I’m actually basing my tasks on your github repo you shared!
So I’ve tried what you suggested but its not returning any data.

Updated task:

`

  • name: Find Guest’s Folder using name
    vmware_guest_find:
    hostname: “{{ vmware_esxi.hostname }}”
    validate_certs: “{{ vmware_esxi.validate_certs }}”
    username: “{{ vmware_esxi.username }}”
    password: “{{ vmware_esxi.password }}”
    datacenter: “{{ vmware_esxi.datacenter }}”
    name: “{{ item }}”
    delegate_to: localhost
    tags: findvm
    with_items:
  • “{{ vm_hostname }}”
    `

Playbook run:

`

ansible-playbook -i hosts vmware-template.yml --tags findvm

PLAY [vms] *********************************************************************************************************************************************************************************
TASK [vmware-template : Find Guest’s Folder using name] ************************************************************************************************************************************
ok: [testvm01 → localhost]
PLAY RECAP *********************************************************************************************************************************************************************************
testvm01 : ok=1 changed=0 unreachable=0 failed=0
`

The VM is definitely in a folder.
I can see the session opening in the VMware client so I’m assuming that its connecting and versions of the various software components are compatible.
Must be missing something simple

Regards,

Ted

The play is running properly, but I’m not sure what your intent is for the output. Try running it with -vvv, or if you register a variable like

`

  • name: “Find Guest’s Folder using name”
    vmware_guest_find:
    hostname: “{{ vmware_esxi.hostname }}”
    validate_certs: “{{ vmware_esxi.validate_certs }}”
    username: “{{ vmware_esxi.username }}”
    password: “{{ vmware_esxi.password }}”
    datacenter: “{{ vmware_esxi.datacenter }}”
    name: “{{ item }}”
    delegate_to: localhost
    register: vm_folder
    tags: findvm
    with_items:

  • “{{ vm_hostname }}”

  • name: debug vm_folder
    debug:
    var: vm_folder

`

You will then see what it’s doing and can move on from there.