# Vmware\_guest

**URL:** <https://forum.ansible.com/t/vmware-guest/25350>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [August 29, 2017, 9:30am UTC](https://forum.ansible.com/t/vmware-guest/25350 "2017-08-29T09:30:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![olivier\_pouilly](https://avatars.discourse-cdn.com/v4/letter/o/f19dbf/32.png) [@olivier\_pouilly](https://forum.ansible.com/u/olivier_pouilly)\
**Post date:** [August 29, 2017, 9:30am UTC](https://forum.ansible.com/t/vmware-guest/25350/1 "2017-08-29T09:30:12Z")

</div>

Hi all,

I recently discovered the module VMware\_guest for ansible. I would like to know how it’s work. Indeed I installed ansible version 2.3.2.0. and the module python 2.7.6 and PyVmomi.  
And when I run a ansible-playbook like this :

- name: Gather all registered virtual machines  
local\_action:  
module: vmware\_vm\_facts  
hostname: esxi\_or\_vcenter\_ip\_or\_hostname  
username: username  
password: password

And when I run the playbook I see the following message :

ERROR! ‘local\_action’ is not a valid attribute for a Play  
The error appears to have been in ‘/etc/ansible/Vmware.yml’: line 1, column 3, but may  
be elsewhere in the file depending on the exact syntax problem.  
The offending line appears to be:

- name: Gather all registered virtual machines  
^ here

do I forgot Something ?

Best Regards,

---

<div class="post-metadata">

**Author:** ![PhilEv](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@PhilEv](https://forum.ansible.com/u/PhilEv)\
**Post date:** [August 29, 2017, 2:56pm UTC](https://forum.ansible.com/t/vmware-guest/25350/2 "2017-08-29T14:56:21Z")

</div>

What you have is a task that belongs to a tasks section  
You need to put this in the context of a play see [http://docs.ansible.com/ansible/latest/playbooks\_intro.html#playbook-language-example](http://docs.ansible.com/ansible/latest/playbooks_intro.html#playbook-language-example)

Phil

---

<div class="post-metadata">

**Author:** ![olivier\_pouilly](https://avatars.discourse-cdn.com/v4/letter/o/f19dbf/32.png) [@olivier\_pouilly](https://forum.ansible.com/u/olivier_pouilly)\
**Post date:** [August 30, 2017, 8:34am UTC](https://forum.ansible.com/t/vmware-guest/25350/3 "2017-08-30T08:34:32Z")

</div>

Hi,

Thanks for you reply. I discovered this soft recently so I don’t realy have the knowledge to complete my YML.  
I treid to search how I can delete a VM on VMware and I create this Playbook with your advice :

- hosts: all  
gather\_facts: false  
connection: local  
vars\_prompt :
- name: “vsphere\_password”  
prompt: “vSphere Password”
- name: “notes”  
prompt: “VM notes”  
private: no  
default: “Deployed with ansible”  
tasks:
- vmware\_guest:  
hostname: ‘{{ vsphere\_host }}’  
username: ‘{{ vsphere\_user }}’  
password: ‘{{ vsphere\_password }}’  
uuid: 421e4592-c069-924d-ce20-7e7533fab926  
state: absent

But it seems that it missing Something. Because it doesn’t work.  
Do you have an example of completed Playbook to do that ?

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [August 30, 2017, 8:42am UTC](https://forum.ansible.com/t/vmware-guest/25350/4 "2017-08-30T08:42:36Z")

</div>

What error do you get when it doesn’t work?

It looks like you are attempting to delete a vm via its uuid. Has the vm already been deleted?

There are other examples here: [http://docs.ansible.com/ansible/latest/vmware\_guest\_module.html](http://docs.ansible.com/ansible/latest/vmware_guest_module.html)

I suggest removing the vars\_prompt stuff and hard coding values until you have the vmware\_guest module doing something.

Also worth using the debug module to display the contents of any vars you are creating so that you can be sure that they contain values that you expect, like this.

- name: show notes  
debug:  
var: notes

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![olivier\_pouilly](https://avatars.discourse-cdn.com/v4/letter/o/f19dbf/32.png) [@olivier\_pouilly](https://forum.ansible.com/u/olivier_pouilly)\
**Post date:** [August 30, 2017, 12:27pm UTC](https://forum.ansible.com/t/vmware-guest/25350/5 "2017-08-30T12:27:42Z")

</div>

Hi Jonh,

I tried with this :

- hosts: all  
gather\_facts: false  
connection: local  
tasks:
- name: show notes  
debug:  
var: notes
- vmware\_guest:  
hostname: 10.112.100.60  
username: root  
password: password  
uuid: 564d0c49-a688-b277-68b8-09848a0c4ca4  
state: absent

but when I run this playbook I have this error messagee :

ERROR! conflicting action statements: hostname, vmware\_guest  
The error appears to have been in ‘/etc/ansible/new.yml’: line 8, column 5, but may  
be elsewhere in the file depending on the exact syntax problem.  
The offending line appears to be:  
var: notes

- vmware\_guest:  
^ here

The error appears to have been in ‘/etc/ansible/new.yml’: line 8, column 5, but may  
be elsewhere in the file depending on the exact syntax problem.  
The offending line appears to be:  
var: notes

- vmware\_guest:  
^ here

Regards,
