On 11. nov. 2016 11:36, Mathias Waack wrote:
We use cloning to create new VMs in our vsphere cluster. The template is
usually powered on (to receive regular updates), so we power it off before
we create a clone:

  - name: power off the template
    vsphere_guest:
      vcenter_hostname: "{{ vcenter }}"
      username: "{{ user }}"
      password: "{{ pass }}"
      guest: "{{ template }}"
      validate_certs: False
      state: powered_off
      force: yes

  - debug: msg="template state is {{ hw_power_status }}."

  - name: ensure the template is powered off
    assert: { that: hw_power_status == "POWERED OFF" }

 This used to work for VSphere 5.x, since the upgrade to VSphere 6.0 the
assert fails:

So how can I ensure the VM is really powered off before the next task
starts? Is there a way to wait till hw_power_status changes?

Something like this.

- name: Check if {{ template }} is down
  vsphere_guest:
    vcenter_hostname: "{{ vcenter }}"
    username: "{{ user }}"
    password: "{{ pass }}"
    guest: "{{ template }}"
    vmware_guest_facts: yes
  register:  result
  until: result.hw_power_status == "POWERED OFF"
  reties: 10
  delay: 5

--
Kai Stian Olstad

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e5a497f6-8334-98d0-6655-462434483913%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to