[ec2 contrib script] Add ability to filter EC2 instances via shell environment (#39034)

pull/38806/merge
Daryl Banttari 7 years ago committed by Sloane Hertel
parent 8d84039aa8
commit e0893aacc5

@ -32,6 +32,13 @@ the AWS_PROFILE variable:
For more details, see: http://docs.pythonboto.org/en/latest/boto_config_tut.html
You can filter for specific EC2 instances by creating an environment variable
named EC2_INSTANCE_FILTERS, which has the same format as the instance_filters
entry documented in ec2.ini. For example, to find all hosts whose name begins
with 'webserver', one might use:
export EC2_INSTANCE_FILTERS='tag:Name=webserver*'
When run against a specific host, this script returns the following variables:
- ec2_ami_launch_index
- ec2_architecture
@ -494,8 +501,8 @@ class Ec2Inventory(object):
# Instance filters (see boto and EC2 API docs). Ignore invalid filters.
self.ec2_instance_filters = []
if config.has_option('ec2', 'instance_filters'):
filters = config.get('ec2', 'instance_filters')
if config.has_option('ec2', 'instance_filters') or 'EC2_INSTANCE_FILTERS' in os.environ:
filters = os.getenv('EC2_INSTANCE_FILTERS', config.get('ec2', 'instance_filters') if config.has_option('ec2', 'instance_filters') else '')
if self.stack_filters and '&' in filters:
self.fail_with_error("AND filters along with stack_filter enabled is not supported.\n")

Loading…
Cancel
Save