From ad75350919cfb762fb25aa522468fe9db05f2bb1 Mon Sep 17 00:00:00 2001 From: Jeremy Price Date: Sat, 31 Aug 2013 17:58:37 -0400 Subject: [PATCH] adding regions_exclude parameter to be able to do subtractive region exclusion. Defaults to us-gov-west-1 so as to not cause errors for people who don't have govcloud credentials but get it in their regions list --- plugins/inventory/ec2.ini | 1 + plugins/inventory/ec2.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/inventory/ec2.ini b/plugins/inventory/ec2.ini index 3e4f08fb5f8..703f07081a5 100644 --- a/plugins/inventory/ec2.ini +++ b/plugins/inventory/ec2.ini @@ -12,6 +12,7 @@ # in AWS and merge the results together. Alternatively, set this to a comma # separated list of regions. E.g. 'us-east-1,us-west-1,us-west-2' regions = all +regions_exclude = us-gov-west-1 # When generating inventory, Ansible needs to know how to address a server. # Each EC2 instance has a lot of variables associated with it. Here is the list: diff --git a/plugins/inventory/ec2.py b/plugins/inventory/ec2.py index eb1d6595f6e..913ddb5f84a 100755 --- a/plugins/inventory/ec2.py +++ b/plugins/inventory/ec2.py @@ -189,12 +189,14 @@ class Ec2Inventory(object): # Regions self.regions = [] configRegions = config.get('ec2', 'regions') + configRegions_exclude = config.get('ec2', 'regions_exclude') if (configRegions == 'all'): if self.eucalyptus_host: self.regions.append(boto.connect_euca(host=self.eucalyptus_host).region.name) else: for regionInfo in ec2.regions(): - self.regions.append(regionInfo.name) + if regionInfo.name not in configRegions_exclude: + self.regions.append(regionInfo.name) else: self.regions = configRegions.split(",")