diff options
author | Kenny Woodson <kwoodson@redhat.com> | 2015-02-05 17:06:56 -0500 |
---|---|---|
committer | Kenny Woodson <kwoodson@redhat.com> | 2015-02-05 17:06:56 -0500 |
commit | aafbcce3605b7f992ba4b73d67286dbb40461baa (patch) | |
tree | c902148de7e314a51771d94df1331b9fb28e1d99 /inventory | |
parent | 04343e7588118359d178fa63554909efb222648a (diff) | |
parent | 04582ead281239524df87f1dabc53125038ff9a5 (diff) | |
download | openshift-aafbcce3605b7f992ba4b73d67286dbb40461baa.tar.gz openshift-aafbcce3605b7f992ba4b73d67286dbb40461baa.tar.bz2 openshift-aafbcce3605b7f992ba4b73d67286dbb40461baa.tar.xz openshift-aafbcce3605b7f992ba4b73d67286dbb40461baa.zip |
Merge pull request #54 from kwoodson/ossh
Adding ssh dynamic hosts capabilities
Diffstat (limited to 'inventory')
-rw-r--r-- | inventory/aws/ec2.ini | 3 | ||||
-rwxr-xr-x | inventory/multi_ec2.py | 16 |
2 files changed, 16 insertions, 3 deletions
diff --git a/inventory/aws/ec2.ini b/inventory/aws/ec2.ini index c6693bb1c..8a0c3ad45 100644 --- a/inventory/aws/ec2.ini +++ b/inventory/aws/ec2.ini @@ -11,8 +11,7 @@ # 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 # separated list of regions. E.g. 'us-east-1,us-west-1,us-west-2' -#regions = all -regions = us-east-1 +regions = all regions_exclude = us-gov-west-1,cn-north-1 # When generating inventory, Ansible needs to know how to address a server. diff --git a/inventory/multi_ec2.py b/inventory/multi_ec2.py index d8c2dc854..499264267 100755 --- a/inventory/multi_ec2.py +++ b/inventory/multi_ec2.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# vim: expandtab:tabstop=4:shiftwidth=4 from time import time import argparse @@ -42,9 +43,15 @@ class MultiEc2(object): else: raise RuntimeError("Could not find valid ec2 credentials in the environment.") + if self.args.cache_only: + # get data from disk + result = self.get_inventory_from_cache() + if not result: + self.get_inventory() + self.write_to_cache() # if its a host query, fetch and do not cache - if self.args.host: + elif self.args.host: self.get_inventory() elif not self.is_cache_valid(): # go fetch the inventories and cache them if cache is expired @@ -185,6 +192,8 @@ class MultiEc2(object): ''' Command line argument processing ''' parser = argparse.ArgumentParser(description='Produce an Ansible Inventory file based on a provider') + parser.add_argument('--cache-only', action='store_true', default=False, + help='Fetch cached only instances (default: False)') parser.add_argument('--list', action='store_true', default=True, help='List instances (default: True)') parser.add_argument('--host', action='store', default=False, @@ -202,9 +211,14 @@ class MultiEc2(object): ''' Reads the inventory from the cache file and returns it as a JSON object ''' + if not os.path.isfile(self.cache_path): + return None + with open(self.cache_path, 'r') as cache: self.result = json.loads(cache.read()) + return True + def json_format_dict(self, data, pretty=False): ''' Converts a dict to a JSON object and dumps it as a formatted string ''' |