Commit 94d60b53 by Lorrin Nelson

ec2 inventory now include Ansible 1.3 style _meta data each host.

parent 6b45c4a6
...@@ -136,7 +136,7 @@ class Ec2Inventory(object): ...@@ -136,7 +136,7 @@ class Ec2Inventory(object):
# Inventory grouped by instance IDs, tags, security groups, regions, # Inventory grouped by instance IDs, tags, security groups, regions,
# and availability zones # and availability zones
self.inventory = {} self.inventory = {"_meta" : {"hostvars" : {}}}
# Index of hostname (address) to instance ID # Index of hostname (address) to instance ID
self.index = {} self.index = {}
...@@ -376,6 +376,8 @@ class Ec2Inventory(object): ...@@ -376,6 +376,8 @@ class Ec2Inventory(object):
# Global Tag: tag all EC2 instances # Global Tag: tag all EC2 instances
self.push(self.inventory, 'ec2', dest) self.push(self.inventory, 'ec2', dest)
self.inventory["_meta"]["hostvars"][dest] = self.get_host_info_dict_from_instance(instance)
def add_rds_instance(self, instance, region): def add_rds_instance(self, instance, region):
''' Adds an RDS instance to the inventory and index, as long as it is ''' Adds an RDS instance to the inventory and index, as long as it is
...@@ -479,23 +481,7 @@ class Ec2Inventory(object): ...@@ -479,23 +481,7 @@ class Ec2Inventory(object):
return list(name_list) return list(name_list)
def get_host_info(self): def get_host_info_dict_from_instance(self, instance):
''' Get variables about a specific host '''
if len(self.index) == 0:
# Need to load index from cache
self.load_index_from_cache()
if not self.args.host in self.index:
# try updating the cache
self.do_api_calls_update_cache()
if not self.args.host in self.index:
# host migh not exist anymore
return self.json_format_dict({}, True)
(region, instance_id) = self.index[self.args.host]
instance = self.get_instance(region, instance_id)
instance_vars = {} instance_vars = {}
for key in vars(instance): for key in vars(instance):
value = getattr(instance, key) value = getattr(instance, key)
...@@ -536,8 +522,26 @@ class Ec2Inventory(object): ...@@ -536,8 +522,26 @@ class Ec2Inventory(object):
#print type(value) #print type(value)
#print value #print value
return self.json_format_dict(instance_vars, True) return instance_vars
def get_host_info(self):
''' Get variables about a specific host '''
if len(self.index) == 0:
# Need to load index from cache
self.load_index_from_cache()
if not self.args.host in self.index:
# try updating the cache
self.do_api_calls_update_cache()
if not self.args.host in self.index:
# host migh not exist anymore
return self.json_format_dict({}, True)
(region, instance_id) = self.index[self.args.host]
instance = self.get_instance(region, instance_id)
return self.json_format_dict(self.get_host_info_dict_from_instance(instance), True)
def push(self, my_dict, key, element): def push(self, my_dict, key, element):
''' Pushed an element onto an array that may not have been defined in ''' Pushed an element onto an array that may not have been defined in
......
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