1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Only read EC2 regions_exclude list if necessary (#18720)

When specifying a literal whitelist of AWS EC2 regions in the dynamic
inventory configuration file, it should not be necessary to also include
a literal blacklist, especially as the blacklist is not honored in this
case anyway. By reading the literal blacklist only when necessary, it is
possible for a user to provide a more minimal EC2 configuration file.

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
This commit is contained in:
Steve Kuznetsov 2017-03-22 09:31:58 -04:00 committed by Sloane Hertel
parent 98c98125f0
commit 6318229bc4
2 changed files with 4 additions and 3 deletions

View file

@ -10,8 +10,9 @@
# AWS regions to make calls to. Set this to 'all' to make request to all regions # AWS regions to make calls to. Set this to 'all' to make request to all regions
# in AWS and merge the results together. Alternatively, set this to a comma # 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' # separated list of regions. E.g. 'us-east-1,us-west-1,us-west-2' and do not
# 'auto' is AWS_REGION or AWS_DEFAULT_REGION environment variable. # provide the 'regions_exclude' option. If this is set to 'auto', AWS_REGION or
# AWS_DEFAULT_REGION environment variable will be read to determine the region.
regions = all regions = all
regions_exclude = us-gov-west-1, cn-north-1 regions_exclude = us-gov-west-1, cn-north-1

View file

@ -250,11 +250,11 @@ class Ec2Inventory(object):
# Regions # Regions
self.regions = [] self.regions = []
configRegions = config.get('ec2', 'regions') configRegions = config.get('ec2', 'regions')
configRegions_exclude = config.get('ec2', 'regions_exclude')
if (configRegions == 'all'): if (configRegions == 'all'):
if self.eucalyptus_host: if self.eucalyptus_host:
self.regions.append(boto.connect_euca(host=self.eucalyptus_host).region.name, **self.credentials) self.regions.append(boto.connect_euca(host=self.eucalyptus_host).region.name, **self.credentials)
else: else:
configRegions_exclude = config.get('ec2', 'regions_exclude')
for regionInfo in ec2.regions(): for regionInfo in ec2.regions():
if regionInfo.name not in configRegions_exclude: if regionInfo.name not in configRegions_exclude:
self.regions.append(regionInfo.name) self.regions.append(regionInfo.name)