From 551adfa26e8c942e76207c68a80f7a20165f7605 Mon Sep 17 00:00:00 2001 From: willthames Date: Thu, 15 May 2014 12:14:05 +1000 Subject: [PATCH] Fix parameters check for ec2_vol Split the error check into two error checks and delay the checks so that listing existing volumes works more nicely. The error check should check that: * One and only one of volume_size id or name is set This fix adds the 'only one' part of that check and provides more useful error messages. --- library/cloud/ec2_vol | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/cloud/ec2_vol b/library/cloud/ec2_vol index 59347a6a175..6db062617a2 100644 --- a/library/cloud/ec2_vol +++ b/library/cloud/ec2_vol @@ -325,9 +325,6 @@ def main(): if id and name: module.fail_json(msg="Both id and name cannot be specified") - if not (id or name or volume_size): - module.fail_json(msg="Cannot specify volume_size and either one of name or id") - # Here we need to get the zone info for the instance. This covers situation where # instance is specified but zone isn't. # Useful for playbooks chaining instance launch with volume create + attach and where the @@ -345,6 +342,15 @@ def main(): device=device_name, changed=False) + # Delaying the checks until after the instance check allows us to get volume ids for existing volumes + # without needing to pass an unused volume_size + if not volume_size and not (id or name): + module.fail_json(msg="You must specify an existing volume with id or name or a volume_size") + + if volume_size and (id or name): + module.fail_json(msg="Cannot specify volume_size and either one of name or id") + + if state == 'absent': delete_volume(module, ec2) else: