From c7f6b5e41f9ebf8e9e3cd9c9e5afbdc4599553be Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Sun, 20 Dec 2015 00:29:20 +0100 Subject: [PATCH] cloudstack: cs_volume: simplify detach on state=absent --- lib/ansible/modules/extras/cloud/cloudstack/cs_volume.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_volume.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_volume.py index 34d464bd53..ccf844eec9 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_volume.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_volume.py @@ -394,18 +394,15 @@ class AnsibleCloudStackVolume(AnsibleCloudStack): volume = self.get_volume() if volume: - if 'attached' in volume: - if self.module.param.get('force'): - self.detached_volume() - else: - self.module.fail_json(msg="Volume '%s' is attached, use force=true for detaching and removing the volume." % volume.get('name')) + if 'attached' in volume and not self.module.param.get('force'): + self.module.fail_json(msg="Volume '%s' is attached, use force=true for detaching and removing the volume." % volume.get('name')) self.result['changed'] = True if not self.module.check_mode: volume = self.detached_volume() res = self.cs.deleteVolume(id=volume['id']) - if 'errortext' in volume: + if 'errortext' in res: self.module.fail_json(msg="Failed: '%s'" % res['errortext']) poll_async = self.module.params.get('poll_async') if poll_async: