Add ceph-ansible support to tripleo-ansible-inventory

The tripleo-ansible-inventory command produces an inventory
which works with TripleO but not with ceph-ansible. TripleO
ceph-ansible integration then creates its own inventory for
the ceph-ansible playbook run. This patch makes generating
a separate inventory for ceph-ansible no longer necessary.

TripleO services already map to the same inventory groups
used by ceph-ansible, e.g. ceph_clients:clients, ceph_mons:
mons, ceph_osds:osds, etc. This patch maps the names of the
TripleO inventory Ceph groups to the names of the inventory
groups used by ceph-ansible and creates a duplicate group
entry in the inventory, but with the names that ceph-ansible
expects.

Change-Id: Ie9880d7b6702b3c5f0e407e4ffe6f297912a1d10
This commit is contained in:
John Fulton 2019-06-05 21:20:42 -04:00
parent 4de9f78b29
commit 3f48630791
2 changed files with 29 additions and 2 deletions

View File

@ -287,6 +287,27 @@ class TripleoInventory(object):
# Associate services with roles # Associate services with roles
roles_by_service = self.get_roles_by_service( roles_by_service = self.get_roles_by_service(
self.stack_outputs.get('EnabledServices', {})) self.stack_outputs.get('EnabledServices', {}))
# tripleo-groups map to ceph-ansible groups as follows
ceph_group_map = {
'ceph_mon': 'mons',
'ceph_osd': 'osds',
'ceph_mgr': 'mgrs',
'ceph_rgw': 'rgws',
'ceph_mds': 'mdss',
'ceph_nfs': 'nfss',
'ceph_client': 'clients',
'ceph_rbdmirror': 'rbdmirrors'
}
# add a ceph-ansible compatible group to the inventory
# which has the same roles. E.g. if the inventory has
# a group 'ceph_mon' which has childen and vars, then
# the inventory will now also have a group 'mons' with
# the same children and vars.
for service, roles in roles_by_service.copy().items():
if service in ceph_group_map.keys():
roles_by_service[ceph_group_map[service]] = roles
for service, roles in roles_by_service.items(): for service, roles in roles_by_service.items():
service_children = [role for role in roles service_children = [role for role in roles
if ret.get(role) is not None] if ret.get(role) is not None]

View File

@ -39,7 +39,8 @@ MOCK_ENABLED_SERVICES = {
"Compute": [ "Compute": [
"nova_compute", "nova_compute",
"kernel", "kernel",
"tripleo_packages" "tripleo_packages",
"ceph_client"
], ],
"CephStorage": [ "CephStorage": [
"kernel", "kernel",
@ -60,7 +61,7 @@ class TestInventory(base.TestCase):
{'output_key': 'EnabledServices', {'output_key': 'EnabledServices',
'output_value': { 'output_value': {
'Controller': ['sa', 'sb'], 'Controller': ['sa', 'sb'],
'Compute': ['sd', 'se'], 'Compute': ['sd', 'se', 'ceph_client'],
'CustomRole': ['sg', 'sh']}}, 'CustomRole': ['sg', 'sh']}},
{'output_key': 'KeystoneURL', {'output_key': 'KeystoneURL',
'output_value': 'xyz://keystone'}, 'output_value': 'xyz://keystone'},
@ -138,6 +139,7 @@ class TestInventory(base.TestCase):
'keystone': ['Controller'], 'keystone': ['Controller'],
'nova_compute': ['Compute'], 'nova_compute': ['Compute'],
'cinder_volume': ['BlockStorage'], 'cinder_volume': ['BlockStorage'],
'ceph_client': ['Compute'],
} }
self.assertDictEqual(services, expected) self.assertDictEqual(services, expected)
@ -389,6 +391,10 @@ class TestInventory(base.TestCase):
'vars': {'ansible_ssh_user': 'heat-admin'}}, 'vars': {'ansible_ssh_user': 'heat-admin'}},
'se': {'children': {'Compute': {}}, 'se': {'children': {'Compute': {}},
'vars': {'ansible_ssh_user': 'heat-admin'}}, 'vars': {'ansible_ssh_user': 'heat-admin'}},
'ceph_client': {'children': {'Compute': {}},
'vars': {'ansible_ssh_user': 'heat-admin'}},
'clients': {'children': {'Compute': {}},
'vars': {'ansible_ssh_user': 'heat-admin'}},
'sg': {'children': {'CustomRole': {}}, 'sg': {'children': {'CustomRole': {}},
'vars': {'ansible_ssh_user': 'heat-admin'}}, 'vars': {'ansible_ssh_user': 'heat-admin'}},
'sh': {'children': {'CustomRole': {}}, 'sh': {'children': {'CustomRole': {}},