Fix dynamic inventory
Commit If834e5e60f79a7418cbc1441d2aaf85507ac7bd2 broke support for the
dynamic inventory since Ansible requires different formats for the hosts
value in groups.
This patch corrects the issue and restores the ability to use
tripleo-ansible-inventory as either a static or dynamic inventory
source.
Change-Id: I035bb878508ceab06279cbaf07969aafeb66b9e5
Story: 2001929
(cherry picked from commit 480aeadc1c
)
This commit is contained in:
parent
7901fb43cb
commit
18324fb412
|
@ -106,6 +106,7 @@ class TripleoInventory(object):
|
||||||
self.ansible_ssh_user = ansible_ssh_user
|
self.ansible_ssh_user = ansible_ssh_user
|
||||||
self.plan_name = plan_name
|
self.plan_name = plan_name
|
||||||
self.stack_outputs = StackOutputs(self.plan_name, self.hclient)
|
self.stack_outputs = StackOutputs(self.plan_name, self.hclient)
|
||||||
|
self.hostvars = {}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_roles_by_service(enabled_services):
|
def get_roles_by_service(enabled_services):
|
||||||
|
@ -152,10 +153,9 @@ class TripleoInventory(object):
|
||||||
def list(self):
|
def list(self):
|
||||||
ret = OrderedDict({
|
ret = OrderedDict({
|
||||||
'Undercloud': {
|
'Undercloud': {
|
||||||
'hosts': {
|
'hosts': self._hosts(['undercloud']),
|
||||||
'undercloud': {
|
|
||||||
'ansible_host': 'localhost'}},
|
|
||||||
'vars': {
|
'vars': {
|
||||||
|
'ansible_host': 'localhost',
|
||||||
'ansible_connection': 'local',
|
'ansible_connection': 'local',
|
||||||
# see https://github.com/ansible/ansible/issues/41808
|
# see https://github.com/ansible/ansible/issues/41808
|
||||||
'ansible_remote_tmp': '/tmp/ansible-${USER}',
|
'ansible_remote_tmp': '/tmp/ansible-${USER}',
|
||||||
|
@ -229,16 +229,26 @@ class TripleoInventory(object):
|
||||||
networks.update(hosts[name]['enabled_networks'])
|
networks.update(hosts[name]['enabled_networks'])
|
||||||
|
|
||||||
children.append(role)
|
children.append(role)
|
||||||
|
|
||||||
|
if self.hosts_format_dict:
|
||||||
|
hosts_format = hosts
|
||||||
|
else:
|
||||||
|
hosts_format = [h for h in hosts.keys()]
|
||||||
|
hosts_format.sort()
|
||||||
|
|
||||||
ret[role] = {
|
ret[role] = {
|
||||||
'hosts': hosts,
|
'hosts': hosts_format,
|
||||||
'vars': {
|
'vars': {
|
||||||
'ansible_ssh_user': self.ansible_ssh_user,
|
'ansible_ssh_user': self.ansible_ssh_user,
|
||||||
'bootstrap_server_id': role_node_id_map.get(
|
'bootstrap_server_id': role_node_id_map.get(
|
||||||
'bootstrap_server_id'),
|
'bootstrap_server_id'),
|
||||||
'role_name': role,
|
'role_name': role,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.hostvars.update(hosts)
|
||||||
|
|
||||||
if children:
|
if children:
|
||||||
vip_map = self.stack_outputs.get('VipMap', {})
|
vip_map = self.stack_outputs.get('VipMap', {})
|
||||||
vips = {(vip_name + "_vip"): vip
|
vips = {(vip_name + "_vip"): vip
|
||||||
|
@ -263,8 +273,10 @@ class TripleoInventory(object):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Prevent Ansible from repeatedly calling us to get empty host details
|
if not self.hosts_format_dict:
|
||||||
ret['_meta'] = {'hostvars': {}}
|
# Prevent Ansible from repeatedly calling us to get empty host
|
||||||
|
# details
|
||||||
|
ret['_meta'] = {'hostvars': self.hostvars}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
|
@ -189,42 +189,17 @@ class TestInventory(base.TestCase):
|
||||||
ansible_ssh_user = 'heat-admin'
|
ansible_ssh_user = 'heat-admin'
|
||||||
expected = {
|
expected = {
|
||||||
'Compute': {
|
'Compute': {
|
||||||
'hosts': {
|
'hosts': ['cp-0'],
|
||||||
'cp-0': {
|
|
||||||
'ansible_host': 'y.y.y.1',
|
|
||||||
'ctlplane_ip': 'y.y.y.1',
|
|
||||||
'deploy_server_id': 'd',
|
|
||||||
'enabled_networks': ['ctlplane']}},
|
|
||||||
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
||||||
'bootstrap_server_id': 'a',
|
'bootstrap_server_id': 'a',
|
||||||
'role_name': 'Compute'}},
|
'role_name': 'Compute'}},
|
||||||
'Controller': {
|
'Controller': {
|
||||||
'hosts': {
|
'hosts': ['c-0', 'c-1', 'c-2'],
|
||||||
'c-0': {
|
|
||||||
'ansible_host': 'x.x.x.1',
|
|
||||||
'ctlplane_ip': 'x.x.x.1',
|
|
||||||
'deploy_server_id': 'a',
|
|
||||||
'enabled_networks': ['ctlplane']},
|
|
||||||
'c-1': {
|
|
||||||
'ansible_host': 'x.x.x.2',
|
|
||||||
'ctlplane_ip': 'x.x.x.2',
|
|
||||||
'deploy_server_id': 'b',
|
|
||||||
'enabled_networks': ['ctlplane']},
|
|
||||||
'c-2': {
|
|
||||||
'ansible_host': 'x.x.x.3',
|
|
||||||
'ctlplane_ip': 'x.x.x.3',
|
|
||||||
'deploy_server_id': 'c',
|
|
||||||
'enabled_networks': ['ctlplane']}},
|
|
||||||
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
||||||
'bootstrap_server_id': 'a',
|
'bootstrap_server_id': 'a',
|
||||||
'role_name': 'Controller'}},
|
'role_name': 'Controller'}},
|
||||||
'CustomRole': {
|
'CustomRole': {
|
||||||
'hosts': {
|
'hosts': ['cs-0'],
|
||||||
'cs-0': {
|
|
||||||
'ansible_host': 'z.z.z.1',
|
|
||||||
'ctlplane_ip': 'z.z.z.1',
|
|
||||||
'deploy_server_id': 'e',
|
|
||||||
'enabled_networks': ['ctlplane']}},
|
|
||||||
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
||||||
'bootstrap_server_id': 'a',
|
'bootstrap_server_id': 'a',
|
||||||
'role_name': 'CustomRole'}},
|
'role_name': 'CustomRole'}},
|
||||||
|
@ -235,10 +210,9 @@ class TestInventory(base.TestCase):
|
||||||
'ctlplane_vip': 'x.x.x.4',
|
'ctlplane_vip': 'x.x.x.4',
|
||||||
'redis_vip': 'x.x.x.6'}},
|
'redis_vip': 'x.x.x.6'}},
|
||||||
'Undercloud': {
|
'Undercloud': {
|
||||||
'hosts': {
|
'hosts': ['undercloud'],
|
||||||
'undercloud': {
|
|
||||||
'ansible_host': 'localhost'}},
|
|
||||||
'vars': {'ansible_connection': 'local',
|
'vars': {'ansible_connection': 'local',
|
||||||
|
'ansible_host': 'localhost',
|
||||||
'ansible_remote_tmp': '/tmp/ansible-${USER}',
|
'ansible_remote_tmp': '/tmp/ansible-${USER}',
|
||||||
'auth_url': 'xyz://keystone.local',
|
'auth_url': 'xyz://keystone.local',
|
||||||
'cacert': 'acacert',
|
'cacert': 'acacert',
|
||||||
|
@ -285,42 +259,17 @@ class TestInventory(base.TestCase):
|
||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
'Compute': {
|
'Compute': {
|
||||||
'hosts': {
|
'hosts': ['cp-0'],
|
||||||
'cp-0': {
|
|
||||||
'ansible_host': 'y.y.y.1',
|
|
||||||
'ctlplane_ip': 'y.y.y.1',
|
|
||||||
'deploy_server_id': 'd',
|
|
||||||
'enabled_networks': ['ctlplane']}},
|
|
||||||
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
||||||
'bootstrap_server_id': 'a',
|
'bootstrap_server_id': 'a',
|
||||||
'role_name': 'Compute'}},
|
'role_name': 'Compute'}},
|
||||||
'Controller': {
|
'Controller': {
|
||||||
'hosts': {
|
'hosts': ['c-0', 'c-1', 'c-2'],
|
||||||
'c-0': {
|
|
||||||
'ansible_host': 'x.x.x.1',
|
|
||||||
'ctlplane_ip': 'x.x.x.1',
|
|
||||||
'deploy_server_id': 'a',
|
|
||||||
'enabled_networks': ['ctlplane']},
|
|
||||||
'c-1': {
|
|
||||||
'ansible_host': 'x.x.x.2',
|
|
||||||
'ctlplane_ip': 'x.x.x.2',
|
|
||||||
'deploy_server_id': 'b',
|
|
||||||
'enabled_networks': ['ctlplane']},
|
|
||||||
'c-2': {
|
|
||||||
'ansible_host': 'x.x.x.3',
|
|
||||||
'ctlplane_ip': 'x.x.x.3',
|
|
||||||
'deploy_server_id': 'c',
|
|
||||||
'enabled_networks': ['ctlplane']}},
|
|
||||||
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
||||||
'bootstrap_server_id': 'a',
|
'bootstrap_server_id': 'a',
|
||||||
'role_name': 'Controller'}},
|
'role_name': 'Controller'}},
|
||||||
'CustomRole': {
|
'CustomRole': {
|
||||||
'hosts': {
|
'hosts': ['cs-0'],
|
||||||
'cs-0': {
|
|
||||||
'ansible_host': 'z.z.z.1',
|
|
||||||
'ctlplane_ip': 'z.z.z.1',
|
|
||||||
'deploy_server_id': 'e',
|
|
||||||
'enabled_networks': ['ctlplane']}},
|
|
||||||
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
||||||
'bootstrap_server_id': 'a',
|
'bootstrap_server_id': 'a',
|
||||||
'role_name': 'CustomRole'}},
|
'role_name': 'CustomRole'}},
|
||||||
|
@ -330,10 +279,9 @@ class TestInventory(base.TestCase):
|
||||||
'ctlplane_vip': 'x.x.x.4',
|
'ctlplane_vip': 'x.x.x.4',
|
||||||
'redis_vip': 'x.x.x.6'}},
|
'redis_vip': 'x.x.x.6'}},
|
||||||
'Undercloud': {
|
'Undercloud': {
|
||||||
'hosts': {
|
'hosts': ['undercloud'],
|
||||||
'undercloud': {
|
|
||||||
'ansible_host': 'localhost'}},
|
|
||||||
'vars': {'ansible_connection': 'local',
|
'vars': {'ansible_connection': 'local',
|
||||||
|
'ansible_host': 'localhost',
|
||||||
'ansible_remote_tmp': '/tmp/ansible-${USER}',
|
'ansible_remote_tmp': '/tmp/ansible-${USER}',
|
||||||
'auth_url': 'xyz://keystone.local',
|
'auth_url': 'xyz://keystone.local',
|
||||||
'cacert': 'acacert',
|
'cacert': 'acacert',
|
||||||
|
@ -411,7 +359,6 @@ class TestInventory(base.TestCase):
|
||||||
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
'vars': {'ansible_ssh_user': ansible_ssh_user,
|
||||||
'bootstrap_server_id': 'a',
|
'bootstrap_server_id': 'a',
|
||||||
'role_name': 'CustomRole'}},
|
'role_name': 'CustomRole'}},
|
||||||
'_meta': {'hostvars': {}},
|
|
||||||
'overcloud': {'children': {'Compute': {},
|
'overcloud': {'children': {'Compute': {},
|
||||||
'Controller': {},
|
'Controller': {},
|
||||||
'CustomRole': {}},
|
'CustomRole': {}},
|
||||||
|
@ -429,9 +376,9 @@ class TestInventory(base.TestCase):
|
||||||
'vars': {'ansible_ssh_user': 'heat-admin'}},
|
'vars': {'ansible_ssh_user': 'heat-admin'}},
|
||||||
'sh': {'children': {'CustomRole': {}},
|
'sh': {'children': {'CustomRole': {}},
|
||||||
'vars': {'ansible_ssh_user': 'heat-admin'}},
|
'vars': {'ansible_ssh_user': 'heat-admin'}},
|
||||||
'Undercloud': {'hosts': {'undercloud': {
|
'Undercloud': {'hosts': {'undercloud': {}},
|
||||||
'ansible_host': 'localhost'}},
|
|
||||||
'vars': {'ansible_connection': 'local',
|
'vars': {'ansible_connection': 'local',
|
||||||
|
'ansible_host': 'localhost',
|
||||||
'ansible_remote_tmp':
|
'ansible_remote_tmp':
|
||||||
'/tmp/ansible-${USER}',
|
'/tmp/ansible-${USER}',
|
||||||
'auth_url': 'xyz://keystone.local',
|
'auth_url': 'xyz://keystone.local',
|
||||||
|
|
Loading…
Reference in New Issue