Commit a8e3c1b4 by John Jarvis

Merge pull request #871 from edx/jarv/just-tags

option to just return the tags
parents 22ceb19d 60a05e0d
...@@ -156,7 +156,6 @@ class Ec2Inventory(object): ...@@ -156,7 +156,6 @@ class Ec2Inventory(object):
data_to_print = self.get_inventory_from_cache() data_to_print = self.get_inventory_from_cache()
else: else:
data_to_print = self.json_format_dict(self.inventory, True) data_to_print = self.json_format_dict(self.inventory, True)
print data_to_print print data_to_print
...@@ -224,6 +223,8 @@ class Ec2Inventory(object): ...@@ -224,6 +223,8 @@ class Ec2Inventory(object):
''' Command line argument processing ''' ''' Command line argument processing '''
parser = argparse.ArgumentParser(description='Produce an Ansible Inventory file based on EC2') parser = argparse.ArgumentParser(description='Produce an Ansible Inventory file based on EC2')
parser.add_argument('--tags-only', action='store_true', default=False,
help='only return tags (default: False)')
parser.add_argument('--list', action='store_true', default=True, parser.add_argument('--list', action='store_true', default=True,
help='List instances (default: True)') help='List instances (default: True)')
parser.add_argument('--host', action='store', parser.add_argument('--host', action='store',
...@@ -574,7 +575,8 @@ class Ec2Inventory(object): ...@@ -574,7 +575,8 @@ class Ec2Inventory(object):
def json_format_dict(self, data, pretty=False): def json_format_dict(self, data, pretty=False):
''' Converts a dict to a JSON object and dumps it as a formatted ''' Converts a dict to a JSON object and dumps it as a formatted
string ''' string '''
if self.args.tags_only:
data = [key for key in data.keys() if 'tag_' in key]
if pretty: if pretty:
return json.dumps(data, sort_keys=True, indent=2) return json.dumps(data, sort_keys=True, indent=2)
else: else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment