Use dictionary for service group mappings

Change the 'cinder_service_names' from a list to a dictionary mapping of
services, groups that install those services, and any additional
conditions around their installations. The init tasks have been updated
to run once and loop through this mapping rather than being
included multiple times and re-run against each host. This may
potentially reduce role run times.

Common variables shared by each service's template files have also been
updated to use the service namespaced variables.

Change-Id: Ifeb890cc733921a6f882e4d9cdb778e22c82e9c5
This commit is contained in:
Jimmy McCrory 2016-09-26 12:29:30 -07:00 committed by Jimmy McCrory
parent a2212b7d1d
commit c84f90a298
10 changed files with 63 additions and 96 deletions

View File

@ -248,10 +248,15 @@ cinder_pip_packages:
# Service Names
cinder_service_names:
- cinder-api
- cinder-scheduler
- cinder-volume
- cinder-backup
cinder-api:
group: cinder_api
cinder-scheduler:
group: cinder_scheduler
cinder-volume:
group: cinder_volume
cinder-backup:
group: cinder_backup
condition: "{{ cinder_service_backup_program_enabled | bool }}"
# This variable is used by the repo_build process to determine
# which host group to check for members of before building the

View File

@ -15,10 +15,10 @@
- name: Restart cinder services
service:
name: "{{ item }}"
name: "{{ item.key }}"
state: restarted
pattern: "{{ item }}"
with_items: "{{ cinder_service_names }}"
pattern: "{{ item.key }}"
with_dict: "{{ cinder_service_names }}"
failed_when: false
- name: Ensure tgt service restarted

View File

@ -1,55 +0,0 @@
---
# Copyright 2014-2016, Rackspace US, 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: cinder_init_common.yml
vars:
program_name: "{{ cinder_service_program_name }}"
service_name: "{{ cinder_service_name }}"
system_user: "{{ cinder_system_user_name }}"
system_group: "{{ cinder_system_group_name }}"
service_home: "{{ cinder_system_home_folder }}"
when: >
inventory_hostname in groups['cinder_api']
- include: cinder_init_common.yml
vars:
program_name: "{{ cinder_service_scheduler_program_name }}"
service_name: "{{ cinder_service_name }}"
system_user: "{{ cinder_system_user_name }}"
system_group: "{{ cinder_system_group_name }}"
service_home: "{{ cinder_system_home_folder }}"
when: >
inventory_hostname in groups['cinder_scheduler']
- include: cinder_init_common.yml
vars:
program_name: "{{ cinder_service_volume_program_name }}"
service_name: "{{ cinder_service_name }}"
system_user: "{{ cinder_system_user_name }}"
system_group: "{{ cinder_system_group_name }}"
service_home: "{{ cinder_system_home_folder }}"
when: >
inventory_hostname in groups['cinder_volume']
- include: cinder_init_common.yml
vars:
program_name: "{{ cinder_service_backup_program_name }}"
service_name: "{{ cinder_service_name }}"
system_user: "{{ cinder_system_user_name }}"
system_group: "{{ cinder_system_group_name }}"
service_home: "{{ cinder_system_home_folder }}"
when: >
inventory_hostname in groups['cinder_backup'] and
cinder_service_backup_program_enabled == true

View File

@ -24,7 +24,11 @@
- name: Load service
service:
name: "{{ program_name }}"
name: "{{ item.key }}"
enabled: "yes"
with_dict: "{{ cinder_service_names }}"
when:
- inventory_hostname in groups[item.value.group]
- "{{ item.value.condition | default(true) }}"
notify:
- Restart cinder services

View File

@ -16,19 +16,27 @@
- name: Create TEMP run dir
file:
path: "/var/run/{{ program_name }}"
path: "/var/run/{{ item.key }}"
state: directory
owner: "{{ system_user }}"
group: "{{ system_group }}"
owner: "{{ cinder_system_user_name }}"
group: "{{ cinder_system_group_name }}"
mode: "02755"
with_dict: "{{ cinder_service_names }}"
when:
- inventory_hostname in groups[item.value.group]
- "{{ item.value.condition | default(true) }}"
- name: Create TEMP lock dir
file:
path: "/var/lock/{{ program_name }}"
path: "/var/lock/{{ item.key }}"
state: directory
owner: "{{ system_user }}"
group: "{{ system_group }}"
owner: "{{ cinder_system_user_name }}"
group: "{{ cinder_system_group_name }}"
mode: "02755"
with_dict: "{{ cinder_service_names }}"
when:
- inventory_hostname in groups[item.value.group]
- "{{ item.value.condition | default(true) }}"
- name: Create tempfile.d entry
template:
@ -37,15 +45,23 @@
mode: "0644"
owner: "root"
group: "root"
with_dict: "{{ cinder_service_names }}"
when:
- inventory_hostname in groups[item.value.group]
- "{{ item.value.condition | default(true) }}"
- name: Place the systemd init script
template:
src: "cinder-systemd-init.j2"
dest: "/etc/systemd/system/{{ program_name }}.service"
dest: "/etc/systemd/system/{{ item.key }}.service"
mode: "0644"
owner: "root"
group: "root"
register: systemd_init
with_dict: "{{ cinder_service_names }}"
when:
- inventory_hostname in groups[item.value.group]
- "{{ item.value.condition | default(true) }}"
- name: Reload the systemd daemon
command: "systemctl daemon-reload"

View File

@ -16,11 +16,15 @@
- name: Place the init script
template:
src: "cinder-upstart-init.j2"
dest: "/etc/init/{{ program_name }}.conf"
dest: "/etc/init/{{ item.key }}.conf"
mode: "0644"
owner: "root"
group: "root"
register: upstart_init
with_dict: "{{ cinder_service_names }}"
when:
- inventory_hostname in groups[item.value.group]
- "{{ item.value.condition | default(true) }}"
notify:
- Restart cinder services
@ -31,10 +35,3 @@
register: upstart_init
notify:
- Restart cinder services
- name: Load service
service:
name: "{{ program_name }}"
enabled: "yes"
notify:
- Restart cinder services

View File

@ -66,7 +66,7 @@
tags:
- cinder-install
- include: cinder_init.yml
- include: cinder_init_common.yml
tags:
- cinder-install

View File

@ -7,13 +7,13 @@ After=network.target
[Service]
Type=simple
User={{ system_user }}
Group={{ system_group }}
User={{ cinder_system_user_name }}
Group={{ cinder_system_group_name }}
{% if program_override is defined %}
ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/cinder/{{ program_name }}.log
ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/cinder/{{ item.key }}.log
{% else %}
ExecStart={{ cinder_bin }}/{{ program_name }} {{ program_config_options|default('') }} --log-file=/var/log/cinder/{{ program_name }}.log
ExecStart={{ cinder_bin }}/{{ item.key }} {{ program_config_options|default('') }} --log-file=/var/log/cinder/{{ item.key }}.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.key }} 2755 {{ cinder_system_user_name }} {{ cinder_system_group_name }}
D /var/run/{{ item.key }} 2755 {{ cinder_system_user_name }} {{ cinder_system_group_name }}

View File

@ -1,6 +1,6 @@
# {{ ansible_managed }}
description "{{ program_name }}"
description "{{ item.key }}"
author "Kevin Carter <kevin.carter@rackspace.com>"
start on runlevel [2345]
@ -10,18 +10,18 @@ respawn
respawn limit 10 5
# Set the RUNBIN environment variable
env RUNBIN="{{ cinder_bin }}/{{ program_name }}"
env RUNBIN="{{ cinder_bin }}/{{ item.key }}"
# Change directory to service users home
chdir "{{ service_home }}"
chdir "{{ cinder_system_home_folder }}"
# Pre start actions
pre-start script
mkdir -p "/var/run/{{ program_name }}"
chown {{ system_user }}:{{ system_group }} "/var/run/{{ program_name }}"
mkdir -p "/var/run/{{ item.key }}"
chown {{ cinder_system_user_name }}:{{ cinder_system_group_name }} "/var/run/{{ item.key }}"
mkdir -p "/var/lock/{{ program_name }}"
chown {{ system_user }}:{{ system_group }} "/var/lock/{{ program_name }}"
mkdir -p "/var/lock/{{ item.key }}"
chown {{ cinder_system_user_name }}:{{ cinder_system_group_name }} "/var/lock/{{ item.key }}"
. {{ cinder_bin }}/activate
@ -29,14 +29,14 @@ end script
# Post stop actions
post-stop script
rm "/var/run/{{ program_name }}/{{ program_name }}.pid"
rm "/var/run/{{ item.key }}/{{ item.key }}.pid"
end script
# Run the start up job
exec start-stop-daemon --start \
--chuid {{ system_user }} \
--chuid {{ cinder_system_user_name }} \
--make-pidfile \
--pidfile /var/run/{{ program_name }}/{{ program_name }}.pid \
--pidfile /var/run/{{ item.key }}/{{ item.key }}.pid \
--exec "{{ program_override|default('$RUNBIN') }}" \
-- {{ program_config_options|default('') }} \
--log-file=/var/log/cinder/{{ program_name }}.log
--log-file=/var/log/cinder/{{ item.key }}.log