From 3b8d7531218c0560a39b83e31d34f2cf41997931 Mon Sep 17 00:00:00 2001 From: Owen Tuz Date: Mon, 21 Mar 2016 14:58:55 +0000 Subject: [PATCH] Avoid cache conflicts when using multiple AWS accounts --- contrib/inventory/ec2.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py index 02fdfdf8907..f0214b61f06 100755 --- a/contrib/inventory/ec2.py +++ b/contrib/inventory/ec2.py @@ -331,8 +331,14 @@ class Ec2Inventory(object): if not os.path.exists(cache_dir): os.makedirs(cache_dir) - self.cache_path_cache = cache_dir + "/ansible-ec2.cache" - self.cache_path_index = cache_dir + "/ansible-ec2.index" + cache_name = 'ansible-ec2' + aws_profile = lambda: (self.boto_profile or + os.environ.get('AWS_PROFILE') or + os.environ.get('AWS_ACCESS_KEY_ID')) + if aws_profile(): + cache_name = '%s-%s' % (cache_name, aws_profile()) + self.cache_path_cache = cache_dir + "/%s.cache" % cache_name + self.cache_path_index = cache_dir + "/%s.index" % cache_name self.cache_max_age = config.getint('ec2', 'cache_max_age') if config.has_option('ec2', 'expand_csv_tags'):