From 668f01c04ce36306c03425a88a51efc189874a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Mon, 20 Jun 2016 12:25:47 +0200 Subject: [PATCH] cloudstack: cs_volume: fix volume may be NoneType in check_mode (#2455) --- .../extras/cloud/cloudstack/cs_volume.py | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_volume.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_volume.py index 844a16a3f6..0836ef9513 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_volume.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_volume.py @@ -341,27 +341,28 @@ class AnsibleCloudStackVolume(AnsibleCloudStack): def attached_volume(self): volume = self.present_volume() - if volume.get('virtualmachineid') != self.get_vm(key='id'): - self.result['changed'] = True + if volume: + if volume.get('virtualmachineid') != self.get_vm(key='id'): + self.result['changed'] = True - if not self.module.check_mode: - volume = self.detached_volume() + if not self.module.check_mode: + volume = self.detached_volume() - if 'attached' not in volume: - self.result['changed'] = True + if 'attached' not in volume: + self.result['changed'] = True - args = {} - args['id'] = volume['id'] - args['virtualmachineid'] = self.get_vm(key='id') - args['deviceid'] = self.module.params.get('device_id') + args = {} + args['id'] = volume['id'] + args['virtualmachineid'] = self.get_vm(key='id') + args['deviceid'] = self.module.params.get('device_id') - if not self.module.check_mode: - res = self.cs.attachVolume(**args) - if 'errortext' in res: - self.module.fail_json(msg="Failed: '%s'" % res['errortext']) - poll_async = self.module.params.get('poll_async') - if poll_async: - volume = self.poll_job(res, 'volume') + if not self.module.check_mode: + res = self.cs.attachVolume(**args) + if 'errortext' in res: + self.module.fail_json(msg="Failed: '%s'" % res['errortext']) + poll_async = self.module.params.get('poll_async') + if poll_async: + volume = self.poll_job(res, 'volume') return volume