From 32822f43d30ccafb2a237109e63df53858c88b07 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Mon, 14 Jul 2014 18:12:01 -0400 Subject: [PATCH] Include ec2 inventory changes from https://github.com/ansible/ansible/pull/8010 and https://github.com/ansible/ansible/pull/8119 --- awx/main/tasks.py | 2 ++ awx/plugins/inventory/ec2.ini.example | 8 ++++++++ awx/plugins/inventory/ec2.py | 23 ++++++++++++++++------- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index af96db06af..5037ab25c1 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -806,6 +806,8 @@ class RunInventoryUpdate(BaseTask): ec2_opts.setdefault('destination_variable', 'public_dns_name') ec2_opts.setdefault('vpc_destination_variable', 'ip_address') ec2_opts.setdefault('route53', 'False') + ec2_opts.setdefault('all_instances', 'True') + ec2_opts.setdefault('all_rds_instances', 'False') ec2_opts.setdefault('nested_groups', 'True') ec2_opts.setdefault('cache_path', tempfile.mkdtemp(prefix='awx_ec2_')) ec2_opts.setdefault('cache_max_age', '300') diff --git a/awx/plugins/inventory/ec2.ini.example b/awx/plugins/inventory/ec2.ini.example index 98856dad51..62ee6c949b 100644 --- a/awx/plugins/inventory/ec2.ini.example +++ b/awx/plugins/inventory/ec2.ini.example @@ -42,6 +42,14 @@ route53 = False # 'route53_excluded_zones' as a comma-separated list. # route53_excluded_zones = samplezone1.com, samplezone2.com +# By default, only EC2 instances in the 'running' state are returned. Set +# 'all_instances' to True to return all instances regardless of state. +all_instances = False + +# By default, only RDS instances in the 'available' state are returned. Set +# 'all_rds_instances' to True return all RDS instances regardless of state. +all_rds_instances = False + # API calls to EC2 are slow. For this reason, we cache the results of an API # call. Set this to the path you want cache files to be written to. Two files # will be written to this directory: diff --git a/awx/plugins/inventory/ec2.py b/awx/plugins/inventory/ec2.py index 0aebb3eead..d8e18c9e61 100755 --- a/awx/plugins/inventory/ec2.py +++ b/awx/plugins/inventory/ec2.py @@ -222,6 +222,16 @@ class Ec2Inventory(object): self.route53_excluded_zones.extend( config.get('ec2', 'route53_excluded_zones', '').split(',')) + # Return all EC2/RDS instances + if config.has_option('ec2', 'all_instances'): + self.all_instances = config.getboolean('ec2', 'all_instances') + else: + self.all_instances = False + if config.has_option('ec2', 'all_rds_instances'): + self.all_rds_instances = config.getboolean('ec2', 'all_rds_instances') + else: + self.all_rds_instances = False + # Cache related cache_dir = os.path.expanduser(config.get('ec2', 'cache_path')) if not os.path.exists(cache_dir): @@ -292,7 +302,7 @@ class Ec2Inventory(object): sys.exit(1) def get_rds_instances_by_region(self, region): - ''' Makes an AWS API call to the list of RDS instances in a particular + ''' Makes an AWS API call to the list of RDS instances in a particular region ''' try: @@ -329,10 +339,9 @@ class Ec2Inventory(object): ''' Adds an instance to the inventory and index, as long as it is addressable ''' - # For Ansible Tower, return all instances regardless of state. - # Only want running instances - #if instance.state != 'running': - # return + # Only want running instances unless all_instances is True + if not self.all_instances and instance.state != 'running': + return # Select the best destination address if instance.subnet_id: @@ -412,8 +421,8 @@ class Ec2Inventory(object): ''' Adds an RDS instance to the inventory and index, as long as it is addressable ''' - # Only want available instances - if instance.status != 'available': + # Only want available instances unless all_rds_instances is True + if not self.all_rds_instances and instance.status != 'available': return # Select the best destination address