Refactor services to magnum_services

This patch refactors the services into a dictionary
which should simply service management.

Change-Id: I3cd735209a0a40d7822377eeb1ca58c95bb51832
This commit is contained in:
Mohammed Naser 2018-02-12 16:29:11 -05:00
parent 4843ab093b
commit ad30f59319
9 changed files with 87 additions and 94 deletions

View File

@ -29,9 +29,6 @@ magnum_system_user_home: "/var/lib/{{ magnum_system_user_name }}"
magnum_log_directory: /var/log/magnum
magnum_etc_directory: /etc/magnum
magnum_api_program_name: magnum-api
magnum_conductor_program_name: magnum-conductor
magnum_service_name: magnum
magnum_service_user_name: magnum
magnum_service_type: container-infra
@ -131,3 +128,14 @@ magnum_cert_manager_type: x509keypair
magnum_api_init_config_overrides: {}
magnum_conductor_init_config_overrides: {}
magnum_services:
magnum-conductor:
group: magnum_all
service_name: magnum-conductor
init_config_overrides: "{{ magnum_conductor_init_config_overrides }}"
start_order: 1
magnum-api:
group: magnum_all
service_name: magnum-api
init_config_overrides: "{{ magnum_api_init_config_overrides }}"
start_order: 2

View File

@ -1,9 +1,23 @@
---
# handlers file for openstack-ansible-magnum
# Copyright 2015, Rackspace US, Inc.
# Copyright 2018, VEXXHOST, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Restart magnum services
service:
name: "{{ item }}"
state: restarted
with_items:
- "{{ magnum_api_program_name }}"
- "{{ magnum_conductor_program_name }}"
systemd:
name: "{{ item.service_name }}"
enabled: yes
state: "restarted"
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
with_items: "{{ filtered_magnum_services }}"

View File

@ -1,34 +0,0 @@
---
# Copyright 2016, Ian Cordasco
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- include: magnum_init_common.yml
vars:
program_name: "{{ magnum_api_program_name }}"
service_name: "{{ magnum_service_name }}"
system_user: "{{ magnum_system_user_name }}"
system_group: "{{ magnum_system_group_name }}"
service_home: "{{ magnum_system_user_home }}"
log_directory: "{{ magnum_log_directory }}"
init_config_overrides: "{{ magnum_api_init_config_overrides }}"
- include: magnum_init_common.yml
vars:
program_name: "{{ magnum_conductor_program_name }}"
service_name: "{{ magnum_service_name }}"
system_user: "{{ magnum_system_user_name }}"
system_group: "{{ magnum_system_group_name }}"
service_home: "{{ magnum_system_user_home }}"
log_directory: "{{ magnum_log_directory }}"
init_config_overrides: "{{ magnum_conductor_init_config_overrides }}"

View File

@ -1,27 +0,0 @@
---
# Copyright 2016, Rackspace US, Inc.
# Copyright 2016, Walmart Stores, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- include: magnum_init_systemd.yml
static: no
when:
- ansible_service_mgr == 'systemd'
- name: Load service
service:
name: "{{ program_name }}"
enabled: "yes"
notify:
- Restart magnum services

View File

@ -15,42 +15,42 @@
- name: Create TEMP run dir
file:
path: "/var/run/{{ program_name }}"
path: "/var/run/{{ item.service_name }}"
state: directory
owner: "{{ system_user }}"
group: "{{ system_group }}"
owner: "{{ magnum_system_user_name }}"
group: "{{ magnum_system_group_name }}"
mode: "02755"
with_items: "{{ filtered_magnum_services }}"
- name: Create TEMP lock dir
file:
path: "/var/lock/{{ program_name }}"
path: "/var/lock/{{ item.service_name }}"
state: directory
owner: "{{ system_user }}"
group: "{{ system_group }}"
owner: "{{ magnum_system_user_name }}"
group: "{{ magnum_system_group_name }}"
mode: "02755"
with_items: "{{ filtered_magnum_services }}"
- name: Create tempfile.d entry
template:
src: "magnum-systemd-tempfiles.j2"
dest: "/etc/tmpfiles.d/magnum.conf"
dest: "/etc/tmpfiles.d/openstack-{{ item.service_name }}.conf"
mode: "0644"
owner: "root"
group: "root"
with_items: "{{ filtered_magnum_services }}"
notify:
- Restart magnum services
- name: Place the systemd init script
config_template:
src: "magnum-systemd-init.j2"
dest: "/etc/systemd/system/{{ program_name }}.service"
dest: "/etc/systemd/system/{{ item.service_name }}.service"
mode: "0644"
owner: "root"
group: "root"
config_overrides: "{{ init_config_overrides }}"
config_overrides: "{{ item.init_config_overrides }}"
config_type: "ini"
register: systemd_init
- name: Reload the systemd daemon
systemd:
daemon_reload: true
when: systemd_init | changed
with_items: "{{ filtered_magnum_services }}"
notify:
- Restart magnum services

View File

@ -35,7 +35,7 @@
tags:
- magnum-config
- include: magnum_init.yml
- include: "magnum_init_{{ ansible_service_mgr }}.yml"
tags:
- magnum-config

View File

@ -8,13 +8,13 @@ After=network.target
[Service]
Type=simple
EnvironmentFile=/etc/environment
User={{ system_user }}
Group={{ system_group }}
User={{ magnum_system_user_name }}
Group={{ magnum_system_group_name }}
{% if program_override is defined %}
ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/magnum/{{ program_name }}.log
{% if item.program_override is defined %}
ExecStart={{ item.program_override }} {{ item.program_config_options|default('') }} --log-file=/var/log/magnum/{{ item.service_name }}.log
{% else %}
ExecStart={{ magnum_bin }}/{{ program_name }} {{ program_config_options|default('') }} --log-file=/var/log/magnum/{{ program_name }}.log
ExecStart={{ magnum_bin }}/{{ item.service_name }} {{ item.program_config_options|default('') }} --log-file=/var/log/magnum/{{ item.service_name }}.log
{% endif %}
# Give a reasonable amount of time for the server to start up/shut down

View File

@ -1,4 +1,4 @@
# {{ ansible_managed }}
D /var/lock/{{ program_name }} 2755 {{ system_user }} {{ system_group }}
D /var/run/{{ program_name }} 2755 {{ system_user }} {{ system_group }}
D /var/lock/{{ item.service_name }} 2755 {{ magnum_system_user_name }} {{ magnum_system_group_name }}
D /var/run/{{ item.service_name }} 2755 {{ magnum_system_user_name }} {{ magnum_system_group_name }}

32
vars/main.yml Normal file
View File

@ -0,0 +1,32 @@
---
# Copyright 2017, Rackspace US, Inc.
# Copyright 2018, VEXXHOST, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Compile a list of the services on a host based on whether
# the host is in the host group and the service is enabled.
# The service list is provided in the defined start order.
#
filtered_magnum_services: |-
{% set services = [] %}
{% for key, value in magnum_services.items() %}
{% if (value['group'] in group_names) and
(('condition' not in value) or
('condition' in value and value['condition'])) %}
{% set _ = value.update({'service_key': key}) %}
{% set _ = services.append(value) %}
{% endif %}
{% endfor %}
{{ services | sort(attribute='start_order') }}