Use dictionary for service group mappings

Change the 'cloudkitty_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: Ieb96fac62906ac9eb387edb450df0c0ca9c0ccb2
This commit is contained in:
Jesse Pretorius
2016年09月28日 17:35:34 +01:00
parent 64ad9e0cad
commit dba2e47fc1

View File

@@ -1,34 +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:cloudkitty_init_common.yml
vars:
program_name:"{{ cloudkitty_service_program_name }}"
service_name:"{{ cloudkitty_service_name }}"
system_user:"{{ cloudkitty_system_user_name }}"
system_group:"{{ cloudkitty_system_group_name }}"
service_home:"{{ cloudkitty_system_home_folder }}"
when:>
inventory_hostname in groups['cloudkitty_api']
- include:cloudkitty_init_common.yml
vars:
program_name:"{{ cloudkitty_service_processor_program_name }}"
service_name:"{{ cloudkitty_service_name }}"
system_user:"{{ cloudkitty_system_user_name }}"
system_group:"{{ cloudkitty_system_group_name }}"
service_home:"{{ cloudkitty_system_home_folder }}"
when:>
inventory_hostname in groups['cloudkitty_api']

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,
@@ -23,7 +23,9 @@
- name:Load service
service:
name:"{{ program_name }}"
name:"{{ item.value.service_name }}"
enabled:"yes"
with_dict:"{{ cloudkitty_services }}"
when:inventory_hostname in groups[item.value.group]
notify:
- Restart cloudkitty services

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:"{{ cloudkitty_system_user_name }}"
group:"{{ cloudkitty_system_group_name }}"
mode:"02755"
with_dict:"{{ cloudkitty_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:"{{ cloudkitty_system_user_name }}"
group:"{{ cloudkitty_system_group_name }}"
mode:"02755"
with_dict:"{{ cloudkitty_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:"{{ cloudkitty_services }}"
when:inventory_hostname in groups[item.value.group]
- name:Place the systemd init script
template:
src:"cloudkitty-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:"{{ cloudkitty_services }}"
when:inventory_hostname in groups[item.value.group]
notify:
- Restart cloudkitty services
- Reload systemd daemon

View File

@@ -1,5 +1,5 @@
---
# Copyright 2016, 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,31 +16,11 @@
- name:Place the init script
template:
src:"cloudkitty-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:"{{ cloudkitty_services }}"
when:inventory_hostname in groups[item.value.group]
notify:
- Restart cloudkitty services
tags:
- upstart-init
- cloudkitty-init
- name:Reload init scripts
shell:|
initctl reload-configuration
notify:
- Restart cloudkitty services
tags:
- upstart-init
- cloudkitty-init
- name:Load service
service:
name:"{{ program_name }}"
enabled:"yes"
notify:
- Restart cloudkitty services
tags:
- upstart-init
- cloudkitty-init
- Reload upstart init scripts

View File

@@ -31,7 +31,7 @@
shell:"{{ cloudkitty_system_shell }}"
system:"yes"
createhome:"yes"
home:"/var/lib/{{ cloudkitty_system_user_name }}"
home:"{{ cloudkitty_system_home_folder }}"
tags:
- cloudkitty-user

View File

@@ -48,7 +48,7 @@
- include:cloudkitty_db_setup.yml
when:inventory_hostname == groups['cloudkitty_all'][0]
- include:cloudkitty_init.yml
- include:cloudkitty_init_common.yml
- name:Flush handlers
meta:flush_handlers
Reference in New Issue
openstack/openstack-ansible-os_cloudkitty
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.

The note is not visible to the blocked user.