Handle missing keys in service_names

Fixes a bug where a service map entry had to have both a systemd_unit and a
container_name defined for any service. Both are possible to provide support
for baremetal and containerized clouds, but should not be required.

Change-Id: I1f48290ed04444c5e829272d965951c209a9fe58
This commit is contained in:
Jill Rouleau 2018-10-02 16:00:55 -07:00
parent fb5f4ce14d
commit d230e9f563
1 changed files with 17 additions and 4 deletions

View File

@ -85,10 +85,23 @@ def run_module():
services_to_restart = {i: service_map[i] for i in service_names}
container_list = [j for i in service_names
for j in services_to_restart[i]['container_name']]
service_unit_list = [j for i in service_names
for j in services_to_restart[i]['systemd_unit']]
container_list = []
for name in service_names:
try:
for item in services_to_restart[name]['container_name']:
container_list.append(item)
except KeyError:
# be tolerant if only a systemd unit is defined for the service
pass
service_unit_list = []
for svc_name in service_names:
try:
for i in services_to_restart[svc_name]['systemd_unit']:
service_unit_list.append(i)
except KeyError:
# be tolerant if only a container name is defined for the service
pass
result = dict(
ansible_facts=dict(