From 88b30a74d2ab91525b81c62ebd16f7fda7d1202a Mon Sep 17 00:00:00 2001 From: evanccopengeo Date: Tue, 15 Apr 2014 17:55:26 -0400 Subject: [PATCH 1/2] fixing bug where if both private_ip and assign_public_p are set ansible fails out --- library/cloud/ec2 | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/library/cloud/ec2 b/library/cloud/ec2 index 0752f40fa4b..d09e799359a 100644 --- a/library/cloud/ec2 +++ b/library/cloud/ec2 @@ -814,13 +814,21 @@ def create_instances(module, ec2, override_count=None): msg="assign_public_ip only available with vpc_subnet_id") else: - interface = boto.ec2.networkinterface.NetworkInterfaceSpecification( - subnet_id=vpc_subnet_id, - groups=group_id, - associate_public_ip_address=assign_public_ip) - interfaces = boto.ec2.networkinterface.NetworkInterfaceCollection(interface) - params['network_interfaces'] = interfaces - + if private_ip: + interface = boto.ec2.networkinterface.NetworkInterfaceSpecification( + subnet_id=vpc_subnet_id, + private_ip_address=private_ip, + groups=group_id, + associate_public_ip_address=assign_public_ip) + interfaces = boto.ec2.networkinterface.NetworkInterfaceCollection(interface) + params['network_interfaces'] = interfaces + else: + interface = boto.ec2.networkinterface.NetworkInterfaceSpecification( + subnet_id=vpc_subnet_id, + groups=group_id, + associate_public_ip_address=assign_public_ip) + interfaces = boto.ec2.networkinterface.NetworkInterfaceCollection(interface) + params['network_interfaces'] = interfaces else: params['subnet_id'] = vpc_subnet_id if vpc_subnet_id: @@ -842,13 +850,22 @@ def create_instances(module, ec2, override_count=None): # check to see if we're using spot pricing first before starting instances if not spot_price: - params.update(dict( - min_count = count_remaining, - max_count = count_remaining, - client_token = id, - placement_group = placement_group, - private_ip_address = private_ip, - )) + if assign_public_ip and private_ip: + params.update(dict( + min_count = count_remaining, + max_count = count_remaining, + client_token = id, + placement_group = placement_group, + )) + else: + params.update(dict( + min_count = count_remaining, + max_count = count_remaining, + client_token = id, + placement_group = placement_group, + private_ip_address = private_ip, + )) + res = ec2.run_instances(**params) instids = [ i.id for i in res.instances ] while True: From ac64f3c8cf295c72ffbb6eae83be8fa3a9690f8d Mon Sep 17 00:00:00 2001 From: evanccopengeo Date: Tue, 15 Apr 2014 18:16:34 -0400 Subject: [PATCH 2/2] cleaning up the code a bit more --- library/cloud/ec2 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/library/cloud/ec2 b/library/cloud/ec2 index d09e799359a..5935b7dc578 100644 --- a/library/cloud/ec2 +++ b/library/cloud/ec2 @@ -820,15 +820,13 @@ def create_instances(module, ec2, override_count=None): private_ip_address=private_ip, groups=group_id, associate_public_ip_address=assign_public_ip) - interfaces = boto.ec2.networkinterface.NetworkInterfaceCollection(interface) - params['network_interfaces'] = interfaces else: interface = boto.ec2.networkinterface.NetworkInterfaceSpecification( subnet_id=vpc_subnet_id, groups=group_id, associate_public_ip_address=assign_public_ip) - interfaces = boto.ec2.networkinterface.NetworkInterfaceCollection(interface) - params['network_interfaces'] = interfaces + interfaces = boto.ec2.networkinterface.NetworkInterfaceCollection(interface) + params['network_interfaces'] = interfaces else: params['subnet_id'] = vpc_subnet_id if vpc_subnet_id: