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