mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #5188 from Multifarious/devel
ec2 inventory now include Ansible 1.3 style _meta data each host.
This commit is contained in:
commit
364ad44db3
1 changed files with 23 additions and 19 deletions
|
@ -136,7 +136,7 @@ class Ec2Inventory(object):
|
|||
|
||||
# Inventory grouped by instance IDs, tags, security groups, regions,
|
||||
# and availability zones
|
||||
self.inventory = {}
|
||||
self.inventory = {"_meta" : {"hostvars" : {}}}
|
||||
|
||||
# Index of hostname (address) to instance ID
|
||||
self.index = {}
|
||||
|
@ -376,6 +376,8 @@ class Ec2Inventory(object):
|
|||
# Global Tag: tag all EC2 instances
|
||||
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):
|
||||
''' Adds an RDS instance to the inventory and index, as long as it is
|
||||
|
@ -479,23 +481,7 @@ class Ec2Inventory(object):
|
|||
return list(name_list)
|
||||
|
||||
|
||||
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)
|
||||
def get_host_info_dict_from_instance(self, instance):
|
||||
instance_vars = {}
|
||||
for key in vars(instance):
|
||||
value = getattr(instance, key)
|
||||
|
@ -536,8 +522,26 @@ class Ec2Inventory(object):
|
|||
#print type(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):
|
||||
''' Pushed an element onto an array that may not have been defined in
|
||||
|
|
Loading…
Reference in a new issue