From 0a26b149fc78ae5b4c920fc07032887d5366620a Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Thu, 2 Apr 2015 00:41:07 +0200 Subject: [PATCH] cloudstack: add error result handling in async job --- lib/ansible/module_utils/cloudstack.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/cloudstack.py b/lib/ansible/module_utils/cloudstack.py index f72d270d30b..dd7e60f7334 100644 --- a/lib/ansible/module_utils/cloudstack.py +++ b/lib/ansible/module_utils/cloudstack.py @@ -185,8 +185,10 @@ class AnsibleCloudStack: if 'jobid' in job: while True: res = self.cs.queryAsyncJobResult(jobid=job['jobid']) - if res['jobstatus'] != 0: - if 'jobresult' in res and key is not None and key in res['jobresult']: + if res['jobstatus'] != 0 and 'jobresult' in res: + if 'errortext' in res['jobresult']: + self.module.fail_json(msg="Failed: '%s'" % res['jobresult']['errortext']) + if key and key in res['jobresult']: job = res['jobresult'][key] break time.sleep(2)