Add role_data* keys to inventory

This exposes the RoleData output from the overcloud stack, as noted
there is a workaround for ansible treating variables with nested j2
as undefined that is to expose each key as role_data_<key>

Change-Id: I751abe3673648e1ed7e8cb949af71c2fe1acd016
This commit is contained in:
Steven Hardy 2017-12-15 17:29:49 +00:00 committed by Emilien Macchi
parent 6d52b6aaa3
commit a7563079da
2 changed files with 28 additions and 2 deletions

View File

@ -194,6 +194,7 @@ class TripleoInventory(object):
role_net_ip_map = self.stack_outputs.get('RoleNetIpMap', {})
role_node_id_map = self.stack_outputs.get('ServerIdData', {})
networks = set()
role_data = self.stack_outputs.get('RoleData', {})
role_net_hostname_map = self.stack_outputs.get(
'RoleNetHostnameMap', {})
children = []
@ -228,6 +229,16 @@ class TripleoInventory(object):
'role_name': role,
}
}
# Note we add each individual key from role_data, because if
# any template sections define inline ansible with j2 variables
# ansible silently treats those inventory variables as
# undefined
# This at least means we can consume those keys which don't
# have this problem (in general we don't need the nested
# ansible *tasks because these are available via config
# download already)
for k in role_data[role]:
ret[role]['vars']["role_data_%s" % k] = role_data[role][k]
if children:
vip_map = self.stack_outputs.get('VipMap', {})

View File

@ -93,7 +93,12 @@ class TestInventory(base.TestCase):
{'output_key': 'VipMap',
'output_value': {
'ctlplane': 'x.x.x.4',
'redis': 'x.x.x.6'}}]}
'redis': 'x.x.x.6'}},
{'output_key': 'RoleData',
'output_value': {
'Controller': {'config_settings': 'foo1'},
'Compute': {'config_settings': 'foo2'},
'CustomRole': {'config_settings': 'foo3'}}}]}
self.plan_name = 'overcloud'
self.hclient = MagicMock()
@ -159,7 +164,8 @@ class TestInventory(base.TestCase):
def test_outputs_iterating_returns_list_of_output_keys(self):
self.assertEqual(
{'EnabledServices', 'KeystoneURL', 'ServerIdData',
'RoleNetHostnameMap', 'RoleNetIpMap', 'VipMap'},
'RoleNetHostnameMap', 'RoleNetIpMap', 'VipMap',
'RoleData'},
set([o for o in self.outputs]))
def test_inventory_list(self):
@ -196,11 +202,13 @@ class TestInventory(base.TestCase):
'children': ['cp-0'],
'vars': {'ansible_ssh_user': 'heat-admin',
'bootstrap_server_id': 'a',
'role_data_config_settings': 'foo2',
'role_name': 'Compute'}},
'Controller': {
'children': ['c-0', 'c-1', 'c-2'],
'vars': {'ansible_ssh_user': 'heat-admin',
'bootstrap_server_id': 'a',
'role_data_config_settings': 'foo1',
'role_name': 'Controller'}},
'cp-0': {'hosts': ['y.y.y.1'],
'vars': {'deploy_server_id': 'd',
@ -214,6 +222,7 @@ class TestInventory(base.TestCase):
'children': ['cs-0'],
'vars': {'ansible_ssh_user': 'heat-admin',
'bootstrap_server_id': 'a',
'role_data_config_settings': 'foo3',
'role_name': 'CustomRole'}},
'overcloud': {
'children': ['Compute', 'Controller', 'CustomRole'],
@ -282,11 +291,13 @@ class TestInventory(base.TestCase):
'children': ['cp-0'],
'vars': {'ansible_ssh_user': ansible_ssh_user,
'bootstrap_server_id': 'a',
'role_data_config_settings': 'foo2',
'role_name': 'Compute'}},
'Controller': {
'children': ['c-0', 'c-1', 'c-2'],
'vars': {'ansible_ssh_user': ansible_ssh_user,
'bootstrap_server_id': 'a',
'role_data_config_settings': 'foo1',
'role_name': 'Controller'}},
'cp-0': {'hosts': ['y.y.y.1'],
'vars': {'deploy_server_id': 'd',
@ -300,6 +311,7 @@ class TestInventory(base.TestCase):
'children': ['cs-0'],
'vars': {'ansible_ssh_user': ansible_ssh_user,
'bootstrap_server_id': 'a',
'role_data_config_settings': 'foo3',
'role_name': 'CustomRole'}},
'overcloud': {
'children': ['Compute', 'Controller', 'CustomRole'],
@ -347,14 +359,17 @@ class TestInventory(base.TestCase):
'Compute': {'children': {'cp-0': {}},
'vars': {'ansible_ssh_user': 'heat-admin',
'bootstrap_server_id': 'a',
'role_data_config_settings': 'foo2',
'role_name': 'Compute'}},
'Controller': {'children': {'c-0': {}, 'c-1': {}, 'c-2': {}},
'vars': {'ansible_ssh_user': 'heat-admin',
'bootstrap_server_id': 'a',
'role_data_config_settings': 'foo1',
'role_name': 'Controller'}},
'CustomRole': {'children': {'cs-0': {}},
'vars': {'ansible_ssh_user': 'heat-admin',
'bootstrap_server_id': 'a',
'role_data_config_settings': 'foo3',
'role_name': 'CustomRole'}},
'_meta': {'hostvars': {}},
'c-0': {'hosts': {'x.x.x.1': {}},