mirror of
https://github.com/phfroidmont/self-hosting.git
synced 2025-12-25 05:36:59 +01:00
Simplify dynamic inventory to only use tags as groups
This commit is contained in:
parent
9e83baffb3
commit
9f8e3dc0c7
1 changed files with 11 additions and 16 deletions
|
|
@ -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']
|
||||
]
|
||||
for host, ip_info, tags, private_ip in self.inventory:
|
||||
if 'env:'+self.environment in tags:
|
||||
if ip_info:
|
||||
self.response['_meta']['hostvars'][host] = {
|
||||
'ansible_host': ip_info['address'],
|
||||
'public_ip': ip_info['address'],
|
||||
'ansible_host': ip_info['address'] if ip_info else private_ip,
|
||||
'public_ip': ip_info['address'] if ip_info else None,
|
||||
'private_ip': private_ip
|
||||
}
|
||||
if tags:
|
||||
for tag in tags:
|
||||
if tag.startswith('group:'):
|
||||
self._add_to_response(
|
||||
tag.split(':')[1],
|
||||
tag,
|
||||
host
|
||||
)
|
||||
if tag.startswith('fact'):
|
||||
self.response['_meta']['hostvars'][host][tag.split(':')[1]] = tag.split(':')[2]
|
||||
|
||||
def _add_to_response(self, group, hostname):
|
||||
'''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue