Simplify dynamic inventory to only use tags as groups

This commit is contained in:
Paul-Henri Froidmont 2018-09-16 01:37:10 +02:00
parent 9e83baffb3
commit 9f8e3dc0c7

View file

@ -52,22 +52,17 @@ class SCWInventory(object):
[i['name'], i['public_ip'], i['tags'], i['private_ip']] for i in result_par1['servers'] + result_ams1['servers'] [i['name'], i['public_ip'], i['tags'], i['private_ip']] for i in result_par1['servers'] + result_ams1['servers']
] ]
for host, ip_info, tags, private_ip in self.inventory: for host, ip_info, tags, private_ip in self.inventory:
if 'env:'+self.environment in tags:
if ip_info:
self.response['_meta']['hostvars'][host] = { self.response['_meta']['hostvars'][host] = {
'ansible_host': ip_info['address'], 'ansible_host': ip_info['address'] if ip_info else private_ip,
'public_ip': ip_info['address'], 'public_ip': ip_info['address'] if ip_info else None,
'private_ip': private_ip 'private_ip': private_ip
} }
if tags: if tags:
for tag in tags: for tag in tags:
if tag.startswith('group:'):
self._add_to_response( self._add_to_response(
tag.split(':')[1], tag,
host host
) )
if tag.startswith('fact'):
self.response['_meta']['hostvars'][host][tag.split(':')[1]] = tag.split(':')[2]
def _add_to_response(self, group, hostname): def _add_to_response(self, group, hostname):
''' '''