0

I want to perform an async task through ansible, below is the syntax which I am using

- name: Create Virtual Machines
  ansi_generate:
    verb: 'generate_vm'
    type: 'generate'
    body: "{{ create_vm_inputs }}"
  async: "{{ env.asyncRunTime}}"
  poll: "{{ env.asyncPollTime}}"
  register: create_vm_out
  failed_when: create_vm_out.meta.status == "failed"

ansi_generate is the the custom Ansible module which accepts verb, type and body as input and generates an output which gets stored in create_vm_out

As it's aa async task I am giving an async time of 3600 (1 hour) and poll time of 60 (sec)

But the playbook is erring with below error

fatal: [127.0.0.1]: FAILED! => {"failed": true, "msg": "The conditional check 'create_vm_out.meta.status == \"failed\"' failed. The error was: error while evaluating conditional (create_vm_out.meta.status == \"failed\"): 'dict object' has no attribute 'meta'"}

I logged a debug message as below:

- debug:
    msg: "{{ create_vm_out }}"

The output is:

ok: [127.0.0.1] => {
    "msg": {
        "ansible_job_id": "377685088849.225705", 
        "changed": false,  
        "finished": 1, 
        "meta": {
            "error_message": null, 
            "output": [
                {       
                    "vm_hostname": "VIshnu-SSHTI1", 
                    "vm_ip": "10.19.180.68", 
                    "vm_name": "VIshnu_SSHTIMEOUT", 
                    "vm_uuid": "1f1697cb-5803-4631-8784-b73ef529b9ed"
                }       
            ],      
            "status": "success"
        }}

Can anyone point me where I am going wrong

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
  • 1
    Possible duplicate of [Ansible: Perform a failed\_when: on an async task based on a value from stdout](https://stackoverflow.com/questions/39069619/ansible-perform-a-failed-when-on-an-async-task-based-on-a-value-from-stdout) – β.εηοιτ.βε Oct 01 '19 at 21:20
  • 2
    So in short: the `failed_when` condition is evaluated each `poll` interval, so you have to deal with the `not defined` cases of the output going along with it – β.εηοιτ.βε Oct 01 '19 at 21:23
  • @β.εηοιτ.βε Will work in that and get back to you. Thanks – Vishnu Kamavaram Oct 03 '19 at 06:43

0 Answers0