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
---
- name: Running Delete Virtual Machine playbook
hosts: localhost
gather_facts: false
connection: local
tasks:
- vmware_guest_info:
hostname: vctst01
username:
password:
validate_certs: no
datacenter: Test
name: Win10
schema: "vsphere"
properties: ["runtime.powerState"]
delegate_to: localhost
register: vminfo
- debug:
var: vminfo
{% if vminfo == 'poweredOff' %}
- name: Deleting
vmware_guest:
hostname: vctst01
username:
password:
validate_certs: no
cluster: Test
name: Win10
state: absent
delegate_to: localhost
register: facts
{% else %}
- name: Powering Down
vmware_guest_powerstate::
validate_certs: no
hostname: vctst01
username:
password:
name: Win10
state: powered-off
delegate_to: localhost
register: deploy
- name: Deleting Machine
vmware_guest:
hostname: vctst01
username:
password:
validate_certs: no
cluster: Test
name: Win10
state: absent
delegate_to: localhost
register: facts
{% endif % }