# vmware\_guest can't find the VM when the state is "poweredoff" or "poweredon"

**URL:** <https://forum.ansible.com/t/vmware-guest-cant-find-the-vm-when-the-state-is-poweredoff-or-poweredon/24150>\
**Category:** Ansible Project\
**Created:** [April 5, 2017, 5:02pm UTC](https://forum.ansible.com/t/vmware-guest-cant-find-the-vm-when-the-state-is-poweredoff-or-poweredon/24150 "2017-04-05T17:02:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego\_Puertas](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@Diego\_Puertas](https://forum.ansible.com/u/Diego_Puertas)\
**Post date:** [April 5, 2017, 5:02pm UTC](https://forum.ansible.com/t/vmware-guest-cant-find-the-vm-when-the-state-is-poweredoff-or-poweredon/24150/1 "2017-04-05T17:02:53Z")

</div>

When in state poweredoff or poweredon, vmware\_guest can’t find my vm, therefore it assumes I want to create a new VM.

When in state present, it has no problem finding it.

Consider the playbook:

> - name: Modify existing VM’s networking, memory and CPU  
> hosts: modify  
> gather\_facts: False  
> connection: local  
> vars\_files:
> - group\_vars/vault/lab\_credentials.yml  
> tasks:
> - name: Power Off the VM  
> vmware\_guest:  
> validate\_certs: False  
> datacenter: “{{ vcenter\_datacenter }}”  
> hostname: “{{ vcenter\_hostname }}”  
> username: “{{ vcenter\_user }}”  
> password: “{{ vcenter\_passwd }}”  
> guest\_id: “{{ vmware\_guest\_id }}”  
> name: “{{ guest\_name }}”  
> state: poweredoff
> - name: Modify the VM Specs  
> vmware\_guest:  
> validate\_certs: False  
> datacenter: “{{ vcenter\_datacenter }}”  
> hostname: “{{ vcenter\_hostname }}”  
> username: “{{ vcenter\_user }}”  
> password: “{{ vcenter\_passwd }}”  
> name: “{{ guest\_name }}”  
> folder: “{{ guest\_folder }}”  
> hardware:  
> memory\_mb: “{{ guest\_memory }}”  
> num\_cpus: “{{ guest\_cpus }}”  
> networks:
> - name: “{{ guest\_network }}”  
> device\_type: “{{ guest\_nic }}”  
> ip: “{{ guest\_ipaddr }}”  
> netmask: “{{ guest\_netmask }}”  
> gateway: “{{ guest\_gateway }}”  
> customization:  
> domain: “{{ guest\_domain }}”  
> dns\_servers: “{{ guest\_dns\_servers }}”  
> dns\_suffix: “{{ guest\_dns\_suffix }}”  
> state: present
> - name: Turn on the VM  
> vmware\_guest:  
> validate\_certs: False  
> datacenter: “{{ vcenter\_datacenter }}”  
> hostname: “{{ vcenter\_hostname }}”  
> username: “{{ vcenter\_user }}”  
> password: “{{ vcenter\_passwd }}”  
> guest\_id: “{{ vmware\_guest\_id }}”  
> name: “{{ guest\_name }}”  
> state: poweredon

If I power off my VM by hand, and only run the task Modify the VM Specs, then the task runs fine, vmware\_guest has no problems finding my VM, using the variable “{{ guest\_name }}”.

But if I run the tasks Power Off the VM or Turn on the VM, vmware\_guest cannot find the VM, thus assumes I want to create a new one.

Is this a bug, or am I doing something wrong?

Thanks

---

<div class="post-metadata">

**Author:** ![Diego\_Puertas](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@Diego\_Puertas](https://forum.ansible.com/u/Diego_Puertas)\
**Post date:** [April 5, 2017, 5:04pm UTC](https://forum.ansible.com/t/vmware-guest-cant-find-the-vm-when-the-state-is-poweredoff-or-poweredon/24150/2 "2017-04-05T17:04:16Z")

</div>

I’m using Ansible 2.3 RC2

---

<div class="post-metadata">

**Author:** ![Diego\_Puertas](https://avatars.discourse-cdn.com/v4/letter/d/e480ec/32.png) [@Diego\_Puertas](https://forum.ansible.com/u/Diego_Puertas)\
**Post date:** [April 5, 2017, 5:22pm UTC](https://forum.ansible.com/t/vmware-guest-cant-find-the-vm-when-the-state-is-poweredoff-or-poweredon/24150/3 "2017-04-05T17:22:29Z")

</div>

I found the problem. You have to specify the “folder” attribute, else vmware\_guest won’t be able to find the VM.
