Hi ,

I have written few tests using ansible . basicall suspending a VM and then
resuming again , taking snapshots etc.. I need to check success or failure
of these operations. I am registering a vraibklle to capture the output as
below and writing the results in a local file.

I am not sure about the correct way of capturing the success or failure
through the registered variable.

Thanks for your help!

  - name: Suspend the Single Machine
        local_action:
           module: vmware_guest
           hostname: '{{ hostname }}'
           username: '{{ username }}'
           password: '{{ password }}'
           name: '{{ item }}'
           esxi_hostname:   '{{ esxi_hostname2 }}'
           template: ''
           is_template: no
           datacenter: '{{ datacenter_name }}'
           state: 'suspended'
           force: yes
           validate_certs: False
        with_items:
           - '{{ guest_list[0] }}'
        register: *taskresult1*
        ignore_errors: True


- shell: echo "HPQC xxx Passed Suspend the Single VM" >> results.txt
        when: taskresult1|succeeded
        delegate_to: localhost
      - shell: echo "HPQC xxx Failed Suspend the Single VM" >> results.txt
        when: taskresult1|failed
        delegate_to: localhost


taskresult1 has following content.




TASK [VCENTER_VM_SuspendRes : debug]
************************************************************************************************************************************
task path: /etc/ansible/roles/VCENTER_VM_SuspendRes/tasks/main.yml:54
ok: [xxxxxx] => {
    "msg": {
        "changed": false,
        "msg": "All items completed",
        "results": [
            {
                "_ansible_delegated_vars": {
                    "ansible_delegated_host": "localhost",
                    "ansible_host": "localhost"
                },
                "_ansible_item_result": true,
                "_ansible_no_log": false,
                "_ansible_parsed": true,
                "changed": false,
                "failed": false,
                "invocation": {
                    "module_args": {
                        "annotation": null,
                        "cluster": null,
                        "customization": {},
                        "customvalues": [],
                        "datacenter": "Datacenter",
                        "disk": [],
                        "esxi_hostname": "xxxxx",
                        "folder": "/vm",
                        "force": true,
                        "guest_id": null,
                        "hardware": {},
                        "hostname": "xxxxx",
                        "is_template": false,
                        "name": "test1",
                        "name_match": "first",
                        "networks": [],
                        "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                        "resource_pool": null,
                        "state": "suspended",
                        "template": "",
                        "template_src": "",
                        "username": "administrator@vsphere.local",
                        "uuid": null,
                        "validate_certs": false,
                        "wait_for_ip_address": false
                    }
                },
                "item": "test1"
            }
        ]
    }
}

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAKcuOAwJ_Hq09B2E%2Bj-UFiN9gUdTMKNKzRVE7VGODU2OUsidsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to