Add fact module, tasks, example playbook, and service mapping file (#1)

* Add fact module, tasks, example playbook, and service mapping file for supporting service restarts

* Improve service restart tasks and module

Support user-defined custom service maps, processing of service lists,
improved exception handling in get_docker_containers.  Moved default
service map to vars.

* Cleanup variables

Move mapping file to a variable, condense extraneous steps to combine default
and user maps into an in-task step, some better var naming
This commit is contained in:
Jill R 2018-06-11 12:08:02 -07:00 committed by Sam Doran
parent bea9ec05dd
commit c41f797608
6 changed files with 505 additions and 0 deletions

View File

@ -0,0 +1,191 @@
---
aodh:
systemd_unit:
- openstack-aodh-evaluator
- openstack-aodh-listener
- openstack-aodh-notifier
container_name:
- aodh_api
- aodh_evaluator
- aodh_listener
- aodh_notifier
vhost:
- aodh
- aodh_wsgi
barbican:
systemd_unit:
- openstack-barbican-api
vhost: ""
ceilometer:
ceilometer-agent:
systemd_unit:
- openstack-ceilometer-central
- openstack-ceilometer-compute
- openstack-ceilometer-polling
- openstack-ceilometer-ipmi ???
- openstack-ceilometer-notification
container_name:
- ceilometer_agent_central
- ceilometer_agent_notification
cinder:
systemd_unit:
- openstack-cinder-api
- openstack-cinder-scheduler
- openstack-cinder-volume
container_name:
- cinder_api
- cinder_api_cron
- cinder_scheduler
- cinder_volume
vhost: ""
congress:
systemd_unit:
- openstack-congress-server
container_name:
vhost: ""
type: ""
glance:
systemd_unit:
- openstack-glance-api
container_name:
- glance_api
vhost: ""
gnocchi:
systemd_unit:
- openstack-gnocchi-api
container_name:
- gnocchi_api
- gnocchi_metricd
- gnocchi_statsd
vhost:
- gnocchi
haproxy:
systemd_unit:
- haproxy
container_name:
- haproxy
heat:
systemd_unit:
- openstack-heat-api
- openstack-heat-engine
- openstack-heat-api-cfn
container_name:
- heat_api
- heat_api_cfn
- heat_api_cron
- heat_engine
vhost:
- heat_api_wsgi
horizon:
systemd_unit: ""
container_name:
vhost:
- horizon_vhost
ironic:
systemd_unit:
- openstack-ironic-api
- openstack-ironic-conductor
container_name:
vhost:
- ironic
keepalived:
systemd_unit:
- keepalived
container_name:
- keepalived
keystone:
systemd_unit: ""
container_name:
vhost:
- keystone_wsgi
manila:
systemd_unit:
- openstack-manila-scheduler
- openstack-manila-share
container_name:
vhost: ""
mistral:
systemd_unit:
- openstack-mistral-api
- openstack-mistral-engine
- openstack-mistral-event-engine
- openstack-mistral-executor
container_name:
vhost:
- mistral
memcached:
systemd_unit:
- memcached
container_name:
- memcached
mysql:
systemd_unit: mariadb
container_name:
- mysql
neutron:
TODO
nova: TODO compute v controller
nova-controller:
systemd_unit:
- openstack-nova-api
- openstack-nova-conductor
- openstack-nova-consoleauth
- openstack-nova-scheduler
- openstack-nova-novncproxy
container_name:
vhost:
- nova
- placement_wsgi
nova-compute:
systemd_unit:
- openstack-nova-compute
- libvirtd
container_name:
vhost: ""
octavia:
openvswitch:
systemd_unit:
- openvswitch
- ovs-vswitchd
container_name:
- ""
rabbitmq:
systemd_unit:
- rabbitmq-server
container_name:
- rabbitmq
redis:
systemd_unit:
- redis
container_name:
- redis
swift:
systemd_unit:
- ""
container_name:
- swift_account_auditor
- swift_account_reaper
- swift_account_replicator
- swift_account_server
- swift_container_auditor
- swift_container_replicator
- swift_container_server
- swift_container_updater
- swift_object_auditor
- swift_object_expirer
- swift_object_replicator
- swift_object_server
- swift_object_updater
- swift_proxy
- swift_rsync
tripleo-ui:
systemd_unit:
container_name:
vhost:
- tripleo-ui
zaqar:
systemd_unit: ""
container_name:
vhost:
- zaqar_wsgi

View File

@ -0,0 +1,98 @@
#!/usr/bin/env python
import docker
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
ANSIBLE_METADATA = {
'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'
}
def get_docker_containers(module, container_list):
from requests.exceptions import ConnectionError
if len(container_list) == 0:
pass
client = docker.from_env()
try:
containers = client.containers.list()
docker_list = [{'container_name': i.attrs['Name'].strip('/')} for i
in containers if i.attrs['Name'].strip('/') in
container_list]
return docker_list
except docker.errors.APIError as e:
module.fail_json(
msg='Error listing containers: {}'.format(to_native(e)))
except ConnectionError as e:
module.fail_json(
msg='Error connecting to Docker: {}'.format(to_native(e))
)
def get_systemd_services(module, service_unit_list):
if len(service_unit_list) == 0:
pass
systemctl_path = \
module.get_bin_path("systemctl",
opt_dirs=["/usr/bin", "/usr/local/bin"])
if systemctl_path is None:
return None
systemd_list = []
for i in service_unit_list:
rc, stdout, stderr = \
module.run_command("{} is-enabled {}".format(systemctl_path, i),
use_unsafe_shell=True)
if stdout == "enabled\n":
state_val = "enabled"
else:
state_val = "disabled"
systemd_list.append({"name": i, "state": state_val})
return systemd_list
def run_module():
module_args = dict(operations_service_map=dict(type=dict, required=True),
operations_service_names=dict(type=list, required=True),
)
module = AnsibleModule(
argument_spec=module_args,
supports_check_mode=True
)
service_map = module.params.get('operations_service_map')
service_names = module.params.get('operations_service_names')
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']]
result = dict(
ansible_facts=dict(
docker_containers=get_docker_containers(module, container_list),
systemd_services=get_systemd_services(module, service_unit_list),
)
)
if module.check_mode:
return result
module.exit_json(**result)
def main():
run_module()
if __name__ == "__main__":
main()

View File

@ -7,3 +7,8 @@
import_role:
name: openstack-ops
tasks_from: restart_service.yml
vars:
operations_service_names:
- 'cinder'
- 'swift'
operations_custom_service_map: "{{ lookup('file', 'user_defined_mapping.yaml') | from_yaml }}"

View File

@ -0,0 +1,18 @@
- name: Gather container list
service_mgmt_facts:
operations_service_names: "{{ operations_service_names }}"
operations_service_map: "{{ operations_default_service_map|combine(operations_custom_service_map) }}"
- name: Restart containerized OpenStack services
docker_container:
name: "{{ item['container_name'] }}"
state: started
restart: yes
loop: "{{ docker_containers }}"
- name: Restart OpenStack services
service:
name: "{{ item['name'] }}"
state: restarted
loop: "{{ systemd_services }}"
when: item['state'] == "enabled"

2
vars/main.yml Normal file
View File

@ -0,0 +1,2 @@
include: tripleo-service-mapping.yaml
operations_custom_service_map: {}

View File

@ -0,0 +1,191 @@
operations_default_service_map:
aodh:
systemd_unit:
- openstack-aodh-evaluator
- openstack-aodh-listener
- openstack-aodh-notifier
container_name:
- aodh_api
- aodh_evaluator
- aodh_listener
- aodh_notifier
vhost:
- aodh
- aodh_wsgi
barbican:
systemd_unit:
- openstack-barbican-api
vhost: ""
ceilometer:
ceilometer-agent:
systemd_unit:
- openstack-ceilometer-central
- openstack-ceilometer-compute
- openstack-ceilometer-polling
- openstack-ceilometer-ipmi ???
- openstack-ceilometer-notification
container_name:
- ceilometer_agent_central
- ceilometer_agent_notification
cinder:
systemd_unit:
- openstack-cinder-api
- openstack-cinder-scheduler
- openstack-cinder-volume
container_name:
- cinder_api
- cinder_api_cron
- cinder_scheduler
- cinder_volume
vhost: ""
congress:
systemd_unit:
- openstack-congress-server
container_name:
vhost: ""
type: ""
glance:
systemd_unit:
- openstack-glance-api
container_name:
- glance_api
vhost: ""
gnocchi:
systemd_unit:
- openstack-gnocchi-api
container_name:
- gnocchi_api
- gnocchi_metricd
- gnocchi_statsd
vhost:
- gnocchi
haproxy:
systemd_unit:
- haproxy
container_name:
- haproxy
heat:
systemd_unit:
- openstack-heat-api
- openstack-heat-engine
- openstack-heat-api-cfn
container_name:
- heat_api
- heat_api_cfn
- heat_api_cron
- heat_engine
vhost:
- heat_api_wsgi
horizon:
systemd_unit: ""
container_name:
vhost:
- horizon_vhost
ironic:
systemd_unit:
- openstack-ironic-api
- openstack-ironic-conductor
container_name:
vhost:
- ironic
keepalived:
systemd_unit:
- keepalived
container_name:
- keepalived
keystone:
systemd_unit: ""
container_name:
vhost:
- keystone_wsgi
manila:
systemd_unit:
- openstack-manila-scheduler
- openstack-manila-share
container_name:
vhost: ""
mistral:
systemd_unit:
- openstack-mistral-api
- openstack-mistral-engine
- openstack-mistral-event-engine
- openstack-mistral-executor
container_name:
vhost:
- mistral
memcached:
systemd_unit:
- memcached
container_name:
- memcached
mysql:
systemd_unit: mariadb
container_name:
- mysql
neutron:
TODO
nova: TODO compute v controller
nova-controller:
systemd_unit:
- openstack-nova-api
- openstack-nova-conductor
- openstack-nova-consoleauth
- openstack-nova-scheduler
- openstack-nova-novncproxy
container_name:
vhost:
- nova
- placement_wsgi
nova-compute:
systemd_unit:
- openstack-nova-compute
- libvirtd
container_name:
vhost: ""
octavia:
openvswitch:
systemd_unit:
- openvswitch
- ovs-vswitchd
container_name:
- ""
rabbitmq:
systemd_unit:
- rabbitmq-server
container_name:
- rabbitmq
redis:
systemd_unit:
- redis
container_name:
- redis
swift:
systemd_unit:
- ""
container_name:
- swift_account_auditor
- swift_account_reaper
- swift_account_replicator
- swift_account_server
- swift_container_auditor
- swift_container_replicator
- swift_container_server
- swift_container_updater
- swift_object_auditor
- swift_object_expirer
- swift_object_replicator
- swift_object_server
- swift_object_updater
- swift_proxy
- swift_rsync
tripleo-ui:
systemd_unit:
container_name:
vhost:
- tripleo-ui
zaqar:
systemd_unit: ""
container_name:
vhost:
- zaqar_wsgi