Merge branch 'ec2_boto' of https://github.com/CharlesBlonde/ansible into CharlesBlonde-ec2_boto

This commit is contained in:
James Cammarata 2013-09-23 14:20:23 -05:00
commit 2d52791c25

View file

@ -166,7 +166,7 @@ options:
instance_profile_name: instance_profile_name:
version_added: "1.3" version_added: "1.3"
description: description:
- Name of the IAM instance profile to use - Name of the IAM instance profile to use. Boto library must be 2.5.0+
required: false required: false
default: null default: null
aliases: [] aliases: []
@ -307,9 +307,7 @@ def get_instance_info(inst):
Retrieves instance information from an instance Retrieves instance information from an instance
ID and returns it as a dictionary ID and returns it as a dictionary
""" """
instance_info = {'id': inst.id,
return({
'id': inst.id,
'ami_launch_index': inst.ami_launch_index, 'ami_launch_index': inst.ami_launch_index,
'private_ip': inst.private_ip_address, 'private_ip': inst.private_ip_address,
'private_dns_name': inst.private_dns_name, 'private_dns_name': inst.private_dns_name,
@ -320,7 +318,6 @@ def get_instance_info(inst):
'architecture': inst.architecture, 'architecture': inst.architecture,
'image_id': inst.image_id, 'image_id': inst.image_id,
'key_name': inst.key_name, 'key_name': inst.key_name,
'virtualization_type': inst.virtualization_type,
'placement': inst.placement, 'placement': inst.placement,
'kernel': inst.kernel, 'kernel': inst.kernel,
'ramdisk': inst.ramdisk, 'ramdisk': inst.ramdisk,
@ -329,8 +326,25 @@ def get_instance_info(inst):
'root_device_type': inst.root_device_type, 'root_device_type': inst.root_device_type,
'root_device_name': inst.root_device_name, 'root_device_name': inst.root_device_name,
'state': inst.state, 'state': inst.state,
'hypervisor': inst.hypervisor 'hypervisor': inst.hypervisor}
}) try:
instance_info['virtualization_type'] = getattr(inst,'virtualization_type')
except AttributeError:
instance_info['virtualization_type'] = None
return instance_info
def boto_supports_profile_name_arg(ec2):
"""
Check if Boto library has instance_profile_name argument. instance_profile_name has been added in Boto 2.5.0
ec2: authenticated ec2 connection object
Returns:
True if Boto library accept instance_profile_name argument, else false
"""
run_instances_method = getattr(ec2, 'run_instances')
return 'instance_profile_name' in run_instances_method.func_code.co_varnames
def create_instances(module, ec2): def create_instances(module, ec2):
@ -426,8 +440,14 @@ def create_instances(module, ec2):
'ramdisk_id': ramdisk, 'ramdisk_id': ramdisk,
'subnet_id': vpc_subnet_id, 'subnet_id': vpc_subnet_id,
'private_ip_address': private_ip, 'private_ip_address': private_ip,
'user_data': user_data, 'user_data': user_data}
'instance_profile_name': instance_profile_name}
if boto_supports_profile_name_arg(ec2):
params['instance_profile_name'] = instance_profile_name
else:
if instance_profile_name is not None:
module.fail_json(
msg="instance_profile_name parameter requires Boto version 2.5.0 or higher")
if vpc_subnet_id: if vpc_subnet_id:
params['security_group_ids'] = group_id params['security_group_ids'] = group_id