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 % }

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/de617a22-2b8d-489e-a510-0042196dcf68%40googlegroups.com.

Reply via email to