|
|
@ -112,6 +112,14 @@ def get_host_groups(inventory, refresh=False):
|
|
|
|
return groups
|
|
|
|
return groups
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def append_hostvars(hostvars, groups, key, server, namegroup=False):
|
|
|
|
|
|
|
|
hostvars[key] = dict(
|
|
|
|
|
|
|
|
ansible_ssh_host=server['interface_ip'],
|
|
|
|
|
|
|
|
openstack=server)
|
|
|
|
|
|
|
|
for group in get_groups_from_server(server, namegroup=namegroup):
|
|
|
|
|
|
|
|
groups[group].append(key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_host_groups_from_cloud(inventory):
|
|
|
|
def get_host_groups_from_cloud(inventory):
|
|
|
|
groups = collections.defaultdict(list)
|
|
|
|
groups = collections.defaultdict(list)
|
|
|
|
firstpass = collections.defaultdict(list)
|
|
|
|
firstpass = collections.defaultdict(list)
|
|
|
@ -130,20 +138,19 @@ def get_host_groups_from_cloud(inventory):
|
|
|
|
firstpass[server['name']].append(server)
|
|
|
|
firstpass[server['name']].append(server)
|
|
|
|
for name, servers in firstpass.items():
|
|
|
|
for name, servers in firstpass.items():
|
|
|
|
if len(servers) == 1 and use_hostnames:
|
|
|
|
if len(servers) == 1 and use_hostnames:
|
|
|
|
server = servers[0]
|
|
|
|
append_hostvars(hostvars, groups, name, servers[0])
|
|
|
|
hostvars[name] = dict(
|
|
|
|
|
|
|
|
ansible_ssh_host=server['interface_ip'],
|
|
|
|
|
|
|
|
openstack=server)
|
|
|
|
|
|
|
|
for group in get_groups_from_server(server, namegroup=False):
|
|
|
|
|
|
|
|
groups[group].append(server['name'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
server_ids = set()
|
|
|
|
|
|
|
|
# Trap for duplicate results
|
|
|
|
for server in servers:
|
|
|
|
for server in servers:
|
|
|
|
server_id = server['id']
|
|
|
|
server_ids.add(server['id'])
|
|
|
|
hostvars[server_id] = dict(
|
|
|
|
if len(server_ids) == 1 and use_hostnames:
|
|
|
|
ansible_ssh_host=server['interface_ip'],
|
|
|
|
append_hostvars(hostvars, groups, name, servers[0])
|
|
|
|
openstack=server)
|
|
|
|
else:
|
|
|
|
for group in get_groups_from_server(server, namegroup=True):
|
|
|
|
for server in servers:
|
|
|
|
groups[group].append(server_id)
|
|
|
|
append_hostvars(
|
|
|
|
|
|
|
|
hostvars, groups, server['id'], servers[0],
|
|
|
|
|
|
|
|
namegroup=True)
|
|
|
|
groups['_meta'] = {'hostvars': hostvars}
|
|
|
|
groups['_meta'] = {'hostvars': hostvars}
|
|
|
|
return groups
|
|
|
|
return groups
|
|
|
|
|
|
|
|
|
|
|
|