How to use an IF Else Statement with Ansible Playbook

Hi,

Can Someone help with a IF Else Statment within Ansible.

If i Run a a GetStatus Playbook the Register: vminfo outputs the Following:

ok: [localhost] => {
“vminfo”: {
“changed”: false,
“failed”: false,
“instance”: {
“runtime”: {
“powerState”: “poweredOn”
}
}
}

What I’m trying to-do is place this into an if Else Statment
My play book is below

Please, don’t do this. Register a variable and use the when condition.
https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#the-when-statement

HI Davide

When i use

when: vminfo[“runtime.powerState”] == “poweredOn”

Im Getting

fatal: [localhost]: FAILED! => {“msg”: “The conditional check ‘vminfo["runtime.powerState"] == "poweredOn"’ failed. The error was: error while evaluating conditional (vminfo["runtime.powerState"] == "poweredOn"): ‘dict object’ has no attribute ‘runtime.powerState’\n\nThe error appears to be in ‘/srv/ansible/t.yaml’: line 20, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - vmware_guest_powerstate:\n ^ here\n”}

So i have updated the Script as follows: