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:
TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": "template state is POWERED ON."
}
TASK [ensure the template is powered off] **************************************
fatal: [localhost]: FAILED! => {
"assertion": "hw_power_status == \"POWERED OFF\"",
"changed": false,
"evaluated_to": false,
"failed": true
}
VSphere shuts down the VM as requested, so maybe it is just a timing problem?
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?
Mathias