From 8c11ea5666168ce5e9cd1f42e9cc486af5f40da5 Mon Sep 17 00:00:00 2001 From: Jeff '2 bits' Bachtel Date: Tue, 12 Aug 2014 16:01:36 -0400 Subject: [PATCH] Add an ec2 inventory option "boto_profile" that allows the use of boto profiles for separating credentials as specified in http://boto.readthedocs.org/en/latest/boto_config_tut.html --- contrib/inventory/ec2.ini | 4 ++++ contrib/inventory/ec2.py | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/contrib/inventory/ec2.ini b/contrib/inventory/ec2.ini index 50430ce0ed4..93be4c8acb4 100644 --- a/contrib/inventory/ec2.ini +++ b/contrib/inventory/ec2.ini @@ -139,3 +139,7 @@ group_by_elasticache_replication_group = True # tag Name value matches webservers1* # (ex. webservers15, webservers1a, webservers123 etc) # instance_filters = tag:Name=webservers1* + +# A boto configuration profile may be used to separate out credentials +# see http://boto.readthedocs.org/en/latest/boto_config_tut.html +# boto_profile = some-boto-profile-name diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py index 6af748f9186..d34291f2566 100755 --- a/contrib/inventory/ec2.py +++ b/contrib/inventory/ec2.py @@ -318,6 +318,11 @@ class Ec2Inventory(object): self.cache_path_index = cache_dir + "/ansible-ec2.index" self.cache_max_age = config.getint('ec2', 'cache_max_age') + # boto configuration profile + self.boto_profile = None + if config.has_option('ec2', 'boto_profile'): + self.boto_profile = config.get('ec2', 'boto_profile') + # Configure nested groups instead of flat namespace. if config.has_option('ec2', 'nested_groups'): self.nested_groups = config.getboolean('ec2', 'nested_groups') @@ -452,7 +457,7 @@ class Ec2Inventory(object): for filter_key, filter_values in self.ec2_instance_filters.items(): reservations.extend(conn.get_all_instances(filters = { filter_key : filter_values })) else: - conn = self.connect_to_aws(ec2, region) + conn = ec2.connect_to_region(region, profile_name=self.boto_profile) # connect_to_region will fail "silently" by returning None if the region name is wrong or not supported if conn is None: