Use dictionary for service group mappings

Change the 'nova_service_names' from a list to a dictionary mapping
of services, groups that install those services. This brings the
method into line with that used in the os_neutron role in order to
implement a more standardised method.

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.

Currently the reload of upstart/systemd scripts may not happen if
only one script changes as the task uses a loop with only one result
register. This patch implements handlers to reload upstart/systemd
scripts to ensure that this happens when any one of the scripts
change.

The handler to reload the services now only tries to restart the
service if the host is in the group for the service according to the
service group mapping. This allows us to ensure that handler
failures are no longer ignored and that no execution time is wasted
trying to restart services which do not exist on the host.

Finally:
- Common variables shared by each service's template files have
  been updated to use the service namespaced variables.
- Unused handlers have been removed.
- Unused variables have been removed.

Change-Id: I53fb0ab1cc5762e3559d4ee2635d4cca532df7e3
This commit is contained in:
Jesse Pretorius 2016-09-28 18:47:11 +01:00 committed by Jesse Pretorius (odyssey4me)
parent 2037030f12
commit 9a17ca682d
10 changed files with 96 additions and 189 deletions

View File

@ -189,7 +189,6 @@ nova_service_adminuri: "{{ nova_service_adminuri_proto }}://{{ internal_lb_vip_a
nova_service_adminurl: "{{ nova_service_adminuri }}/v2.1/%(tenant_id)s"
nova_service_internaluri: "{{ nova_service_internaluri_proto }}://{{ internal_lb_vip_address }}:{{ nova_service_port }}"
nova_service_internalurl: "{{ nova_service_internaluri }}/v2.1/%(tenant_id)s"
nova_program_name: nova-api-os-compute
## Nova cinder
nova_cross_az_attach: True
@ -201,7 +200,6 @@ nova_spice_html5proxy_base_uri: "{{ nova_spice_html5proxy_base_proto }}://{{ ext
nova_spice_html5proxy_base_url: "{{ nova_spice_html5proxy_base_uri }}/spice_auto.html"
nova_spice_console_keymap: en-us
nova_spice_console_agent_enabled: True
nova_spice_program_name: nova-spicehtml5proxy
nova_spicehtml5_git_repo: https://github.com/SPICE/spice-html5
nova_spicehtml5_git_install_branch: master
@ -213,7 +211,6 @@ nova_novncproxy_base_url: "{{ nova_novncproxy_base_uri }}/vnc_auto.html"
nova_novncproxy_vncserver_proxyclient_address: "{{ ansible_host }}"
nova_novncproxy_vncserver_listen: "{{ ansible_host }}"
nova_novncproxy_agent_enabled: True
nova_novncproxy_program_name: nova-novncproxy
nova_novncproxy_git_repo: https://github.com/kanaka/novnc
nova_novncproxy_git_install_branch: master
nova_novncproxy_vnc_keymap: en-us
@ -222,14 +219,9 @@ nova_novncproxy_vnc_keymap: en-us
nova_metadata_proxy_enabled: "{{ nova_network_services[nova_network_type]['metadata_proxy_enabled'] | bool }}"
nova_metadata_host: "{{ internal_lb_vip_address }}"
nova_metadata_port: 8775
nova_metadata_program_name: nova-api-metadata
## Nova cert
nova_cert_program_name: nova-cert
## Nova compute
nova_enable_instance_password: True
nova_compute_program_name: nova-compute
nova_force_config_drive: False
@ -242,12 +234,8 @@ nova_libvirt_inject_password: False
nova_libvirt_disk_cachemodes: '{{ nova_libvirt_images_rbd_pool is defined | ternary("network=writeback", "") }}'
nova_libvirt_hw_disk_discard: '{{ nova_libvirt_images_rbd_pool is defined | ternary("unmap", "ignore") }}'
## Nova conductor
nova_conductor_program_name: nova-conductor
## Nova console
nova_console_agent_enabled: True
nova_consoleauth_program_name: nova-consoleauth
nova_console_keymap: en-us
# Set the console type. Presently the only options are ["spice", "novnc"].
nova_console_type: spice
@ -325,7 +313,6 @@ nova_scheduler_default_filters: "RetryFilter,AvailabilityZoneFilter,RamFilter,Co
nova_scheduler_driver: filter_scheduler
nova_scheduler_available_filters: nova.scheduler.filters.all_filters
nova_scheduler_weight_classes: nova.scheduler.weights.all_weighers
nova_scheduler_program_name: nova-scheduler
# If you want to regenerate the nova users SSH keys, on each run, set this var to True
# Otherwise keys will be generated on the first run and not regenerated each run.
@ -372,17 +359,38 @@ nova_libvirtd_listen_tcp: 0
nova_libvirtd_auth_tcp: sasl
nova_libvirtd_debug_log_filters: "3:remote 4:event 3:json 3:rpc"
## Service Names
nova_service_names:
- "{{ nova_metadata_program_name }}"
- "{{ nova_cert_program_name }}"
- "{{ nova_conductor_program_name }}"
- "{{ nova_program_name }}"
- "{{ nova_scheduler_program_name }}"
- "{{ nova_compute_program_name }}"
- "{{ nova_spice_program_name }}"
- "{{ nova_consoleauth_program_name }}"
- "{{ nova_novncproxy_program_name }}"
## Service Name-Group Mapping
nova_services:
nova-api-metadata:
group: nova_api_metadata
service_name: nova-api-metadata
nova-api-os-compute:
group: nova_api_os_compute
service_name: nova-api-os-compute
nova-cert:
group: nova_cert
service_name: nova-cert
nova-compute:
group: nova_compute
service_name: nova-compute
nova-conductor:
group: nova_conductor
service_name: nova-conductor
nova-consoleauth:
group: nova_console
service_name: nova-consoleauth
nova-novncproxy:
group: nova_console
service_name: nova-novncproxy
condition: "{{ nova_console_type == 'novnc' }}"
nova-scheduler:
group: nova_scheduler
service_name: nova-scheduler
nova-spicehtml5proxy:
group: nova_console
service_name: nova-spicehtml5proxy
condition: "{{ nova_console_type == 'spice' }}"
nova_novnc_pip_packages:
- websockify

View File

@ -1,5 +1,5 @@
---
# Copyright 2014, Rackspace US, Inc.
# Copyright 2015, 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.
@ -19,10 +19,23 @@
state: "restarted"
pattern: "libvirt-bin"
- name: Reload systemd daemon
command: "systemctl daemon-reload"
notify:
- Restart nova services
- name: Reload upstart init scripts
shell: |
initctl reload-configuration
notify:
- Restart nova services
- name: Restart nova services
service:
name: "{{ item }}"
state: restarted
pattern: "{{ item }}"
with_items: "{{ nova_service_names }}"
failed_when: false
name: "{{ item.value.service_name }}"
state: "restarted"
pattern: "{{ item.value.service_name }}"
with_dict: "{{ nova_services }}"
when:
- inventory_hostname in groups[item.value.group]
- "{{ item.value.condition | default(true) }}"

View File

@ -54,7 +54,7 @@
- include: nova_pre_install.yml
- include: nova_install.yml
- include: nova_post_install.yml
- include: nova_init.yml
- include: nova_init_common.yml
- include: nova_db_setup.yml
when: inventory_hostname == groups['nova_api_os_compute'][0]

View File

@ -1,101 +0,0 @@
---
# Copyright 2014, 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: nova_init_common.yml
vars:
program_name: "{{ nova_metadata_program_name }}"
service_name: "{{ nova_service_name }}"
system_user: "{{ nova_system_user_name }}"
system_group: "{{ nova_system_group_name }}"
service_home: "{{ nova_system_home_folder }}"
when: inventory_hostname in groups['nova_api_metadata']
- include: nova_init_common.yml
vars:
program_name: "{{ nova_cert_program_name }}"
service_name: "{{ nova_service_name }}"
system_user: "{{ nova_system_user_name }}"
system_group: "{{ nova_system_group_name }}"
service_home: "{{ nova_system_home_folder }}"
when: inventory_hostname in groups['nova_cert']
- include: nova_init_common.yml
vars:
program_name: "{{ nova_conductor_program_name }}"
service_name: "{{ nova_service_name }}"
system_user: "{{ nova_system_user_name }}"
system_group: "{{ nova_system_group_name }}"
service_home: "{{ nova_system_home_folder }}"
when: inventory_hostname in groups['nova_conductor']
- include: nova_init_common.yml
vars:
program_name: "{{ nova_program_name }}"
service_name: "{{ nova_service_name }}"
system_user: "{{ nova_system_user_name }}"
system_group: "{{ nova_system_group_name }}"
service_home: "{{ nova_system_home_folder }}"
when: inventory_hostname in groups['nova_api_os_compute']
- include: nova_init_common.yml
vars:
program_name: "{{ nova_scheduler_program_name }}"
service_name: "{{ nova_service_name }}"
system_user: "{{ nova_system_user_name }}"
system_group: "{{ nova_system_group_name }}"
service_home: "{{ nova_system_home_folder }}"
when: inventory_hostname in groups['nova_scheduler']
- include: nova_init_common.yml
vars:
program_name: "{{ nova_compute_program_name }}"
service_name: "{{ nova_service_name }}"
system_user: "{{ nova_system_user_name }}"
system_group: "{{ nova_system_group_name }}"
service_home: "{{ nova_system_home_folder }}"
when: inventory_hostname in groups['nova_compute']
# Upstart init script for spice console.
- include: nova_init_common.yml
vars:
program_name: "{{ nova_spice_program_name }}"
service_name: "{{ nova_service_name }}"
system_user: "{{ nova_system_user_name }}"
system_group: "{{ nova_system_group_name }}"
service_home: "{{ nova_system_home_folder }}"
when:
- inventory_hostname in groups ['nova_console']
- nova_console_type == "spice"
# Upstart init script for novnc console.
- include: nova_init_common.yml
vars:
program_name: "{{ nova_novncproxy_program_name }}"
service_name: "{{ nova_service_name }}"
system_user: "{{ nova_system_user_name }}"
system_group: "{{ nova_system_group_name }}"
service_home: "{{ nova_system_home_folder }}"
when:
- inventory_hostname in groups ['nova_console']
- nova_console_type == "novnc"
- include: nova_init_common.yml
vars:
program_name: "{{ nova_consoleauth_program_name }}"
service_name: "{{ nova_service_name }}"
system_user: "{{ nova_system_user_name }}"
system_group: "{{ nova_system_group_name }}"
service_home: "{{ nova_system_home_folder }}"
when: inventory_hostname in groups['nova_console']

View File

@ -5,7 +5,7 @@
# 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
# 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,
@ -14,24 +14,16 @@
# limitations under the License.
- include: nova_init_upstart.yml
static: no
when: pid1_name == "init"
tags:
- upstart-init
- nova-init
- include: nova_init_systemd.yml
static: no
when: pid1_name == "systemd"
tags:
- systemd-init
- nova-init
- name: Load service
service:
name: "{{ program_name }}"
name: "{{ item.value.service_name }}"
enabled: "yes"
with_dict: "{{ nova_services }}"
when: inventory_hostname in groups[item.value.group]
notify:
- Restart nova services
tags:
- nova-init

View File

@ -15,19 +15,23 @@
- name: Create TEMP run dir
file:
path: "/var/run/{{ program_name }}"
path: "/var/run/{{ item.value.service_name }}"
state: directory
owner: "{{ system_user }}"
group: "{{ system_group }}"
owner: "{{ nova_system_user_name }}"
group: "{{ nova_system_group_name }}"
mode: "02755"
with_dict: "{{ nova_services }}"
when: inventory_hostname in groups[item.value.group]
- name: Create TEMP lock dir
file:
path: "/var/lock/{{ program_name }}"
path: "/var/lock/{{ item.value.service_name }}"
state: directory
owner: "{{ system_user }}"
group: "{{ system_group }}"
owner: "{{ nova_system_user_name }}"
group: "{{ nova_system_group_name }}"
mode: "02755"
with_dict: "{{ nova_services }}"
when: inventory_hostname in groups[item.value.group]
- name: Create tempfile.d entry
template:
@ -36,18 +40,17 @@
mode: "0644"
owner: "root"
group: "root"
with_dict: "{{ nova_services }}"
when: inventory_hostname in groups[item.value.group]
- name: Place the systemd init script
template:
src: "nova-systemd-init.j2"
dest: "/etc/systemd/system/{{ program_name }}.service"
dest: "/etc/systemd/system/{{ item.value.service_name }}.service"
mode: "0644"
owner: "root"
group: "root"
register: systemd_init
- name: Reload the systemd daemon
command: "systemctl daemon-reload"
when: systemd_init | changed
with_dict: "{{ nova_services }}"
when: inventory_hostname in groups[item.value.group]
notify:
- Restart nova services
- Reload systemd daemon

View File

@ -1,5 +1,5 @@
---
# Copyright 2014, Rackspace US, Inc.
# Copyright 2015, 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.
@ -16,21 +16,11 @@
- name: Place the init script
template:
src: "nova-upstart-init.j2"
dest: "/etc/init/{{ program_name }}.conf"
dest: "/etc/init/{{ item.value.service_name }}.conf"
mode: "0644"
owner: "root"
group: "root"
with_dict: "{{ nova_services }}"
when: inventory_hostname in groups[item.value.group]
notify:
- Restart nova services
tags:
- upstart-init
- nova-init
- name: Reload init scripts
shell: |
initctl reload-configuration
notify:
- Restart nova services
tags:
- upstart-init
- nova-init
- Reload upstart init scripts

View File

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

View File

@ -1,6 +1,7 @@
# {{ ansible_managed }}
description "{{ program_name }}"
description "{{ item.value.service_name }}"
author "Kevin Carter <kevin.carter@rackspace.com>"
start on runlevel [2345]
@ -10,18 +11,18 @@ respawn
respawn limit 10 5
# Set the RUNBIN environment variable
env RUNBIN="{{ nova_bin }}/{{ program_name }}"
env RUNBIN="{{ nova_bin }}/{{ item.value.service_name }}"
# Change directory to service users home
chdir "{{ service_home }}"
chdir "{{ nova_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.value.service_name }}"
chown {{ nova_system_user_name }}:{{ nova_system_group_name }} "/var/run/{{ item.value.service_name }}"
mkdir -p "/var/lock/{{ program_name }}"
chown {{ system_user }}:{{ system_group }} "/var/lock/{{ program_name }}"
mkdir -p "/var/lock/{{ item.value.service_name }}"
chown {{ nova_system_user_name }}:{{ nova_system_group_name }} "/var/lock/{{ item.value.service_name }}"
. {{ nova_bin }}/activate
@ -29,14 +30,15 @@ end script
# Post stop actions
post-stop script
rm "/var/run/{{ program_name }}/{{ program_name }}.pid"
rm "/var/run/{{ item.value.service_name }}/{{ item.value.service_name }}.pid"
end script
# Run the start up job
exec start-stop-daemon --start \
--chuid {{ system_user }} \
--chuid {{ nova_system_user_name }} \
--make-pidfile \
--pidfile /var/run/{{ program_name }}/{{ program_name }}.pid \
--pidfile /var/run/{{ item.value.service_name }}/{{ item.value.service_name }}.pid \
--exec "{{ program_override|default('$RUNBIN') }}" \
-- {{ program_config_options|default('') }} \
--log-file=/var/log/nova/{{ program_name }}.log
--log-file=/var/log/{{ nova_service_name }}/{{ item.value.service_name }}.log