Optimise role execution

In order to optimise the role execution and
to improve consistency, the following is done:

1. The services dict is filtered per host to
   prevent skipped tasks from spamming the
   logs and wasting execution time.
2. The service restart is implemented in a
   specific order to improve consistency. The
   order implemented is a wild guess as there
   is no upstream documentation about the
   'correct' order.
3. The service enable/start is consolidated
   into the handler to be more efficient.
4. A dynamic include is used instead of nesting
   includes for the init prep.

Change-Id: I91d20b980f1b1a63ff2d6ef30bcec7ef58a5571a
(cherry picked from commit f7de00cadd)
This commit is contained in:
Jesse Pretorius 2017-07-10 13:08:21 +01:00 committed by Jesse Pretorius (odyssey4me)
parent 300f15ee65
commit 87582ad580
8 changed files with 67 additions and 55 deletions

View File

@ -219,18 +219,22 @@ heat_services:
group: heat_api
service_name: heat-api
init_config_overrides: "{{ heat_api_init_overrides }}"
start_order: 2
heat-api-cfn:
group: heat_api_cfn
service_name: heat-api-cfn
init_config_overrides: "{{ heat_api_cfn_init_overrides }}"
start_order: 3
heat-api-cloudwatch:
group: heat_api_cloudwatch
service_name: heat-api-cloudwatch
init_config_overrides: "{{ heat_api_cloudwatch_init_overrides }}"
start_order: 3
heat-engine:
group: heat_engine
service_name: heat-engine
init_config_overrides: "{{ heat_engine_init_overrides }}"
start_order: 1
# Required secrets for the role
heat_required_secrets:

View File

@ -12,10 +12,11 @@
# 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 heat services
systemd:
name: "{{ item.value.service_name }}"
name: "{{ item.service_name }}"
enabled: yes
state: "restarted"
daemon_reload: yes
with_dict: "{{ heat_services }}"
when: inventory_hostname in groups[item.value.group]
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
with_items: "{{ filtered_heat_services }}"

View File

@ -1,27 +0,0 @@
---
# Copyright 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: heat_init_systemd.yml
when:
- ansible_service_mgr == 'systemd'
- name: Load service
service:
name: "{{ item.value.service_name }}"
enabled: "yes"
with_dict: "{{ heat_services }}"
when: inventory_hostname in groups[item.value.group]
notify:
- Restart heat services

View File

@ -15,54 +15,51 @@
- name: Create TEMP run dir
file:
path: "/var/run/{{ item.value.service_name }}"
path: "/var/run/{{ item.service_name }}"
state: directory
owner: "{{ heat_system_user_name }}"
group: "{{ heat_system_group_name }}"
mode: "02755"
with_dict: "{{ heat_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_heat_services }}"
- name: Create TEMP lock dir
file:
path: "/var/lock/{{ item.value.service_name }}"
path: "/var/lock/{{ item.service_name }}"
state: directory
owner: "{{ heat_system_user_name }}"
group: "{{ heat_system_group_name }}"
mode: "02755"
with_dict: "{{ heat_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_heat_services }}"
# TODO(mgariepy):
# Remove this in Pike as it only needed to handle upgrades
# from Newton->Newton and Newton->Ocata
- name: Cleanup old tmpfiles.d entry
file:
path: "/etc/tmpfiles.d/{{ item.value.service_name }}.conf"
path: "/etc/tmpfiles.d/{{ item.service_name }}.conf"
state: absent
with_dict: "{{ heat_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_heat_services }}"
- name: Create tmpfiles.d entry
template:
src: "heat-systemd-tmpfiles.j2"
dest: "/etc/tmpfiles.d/openstack-{{ item.value.service_name }}.conf"
dest: "/etc/tmpfiles.d/openstack-{{ item.service_name }}.conf"
mode: "0644"
owner: "root"
group: "root"
with_dict: "{{ heat_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_heat_services }}"
notify:
- Restart heat services
- name: Place the systemd init script
config_template:
src: "heat-systemd-init.j2"
dest: "/etc/systemd/system/{{ item.value.service_name }}.service"
dest: "/etc/systemd/system/{{ item.service_name }}.service"
mode: "0644"
owner: "root"
group: "root"
config_overrides: "{{ item.value.init_config_overrides }}"
config_overrides: "{{ item.init_config_overrides }}"
config_type: "ini"
with_dict: "{{ heat_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_heat_services }}"
notify:
- Restart heat services

View File

@ -44,22 +44,28 @@
tags:
- heat-config
- include: heat_init_common.yml
- include: "heat_init_{{ ansible_service_mgr }}.yml"
tags:
- heat-config
- include: heat_domain_setup.yml
when: inventory_hostname == groups['heat_all'][0]
static: no
when:
- "inventory_hostname == ansible_play_hosts[0]"
tags:
- heat-config
- include: heat_db_setup.yml
when: inventory_hostname == groups['heat_all'][0]
static: no
when:
- "inventory_hostname == ansible_play_hosts[0]"
tags:
- heat-config
- include: heat_service_setup.yml
when: inventory_hostname == groups['heat_all'][0]
static: no
when:
- "inventory_hostname == ansible_play_hosts[0]"
tags:
- heat-config

View File

@ -11,9 +11,9 @@ User={{ heat_system_user_name }}
Group={{ heat_system_group_name }}
{% if program_override is defined %}
ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/heat/{{ item.value.service_name }}.log
ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/heat/{{ item.service_name }}.log
{% else %}
ExecStart={{ heat_bin }}/{{ item.value.service_name }} {{ program_config_options|default('') }} --log-file=/var/log/heat/{{ item.value.service_name }}.log
ExecStart={{ heat_bin }}/{{ item.service_name }} {{ program_config_options|default('') }} --log-file=/var/log/heat/{{ 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/{{ item.value.service_name }} 2755 {{ heat_system_user_name }} {{ heat_system_group_name }}
D /var/run/{{ item.value.service_name }} 2755 {{ heat_system_user_name }} {{ heat_system_group_name }}
D /var/lock/{{ item.service_name }} 2755 {{ heat_system_user_name }} {{ heat_system_group_name }}
D /var/run/{{ item.service_name }} 2755 {{ heat_system_user_name }} {{ heat_system_group_name }}

31
vars/main.yml Normal file
View File

@ -0,0 +1,31 @@
---
# Copyright 2017, 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.
#
# 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_heat_services: |-
{% set services = [] %}
{% for key, value in heat_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') }}