vmware_guest can't find the VM when the state is "poweredoff" or "poweredon"

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

I’m using Ansible 2.3 RC2

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