Standardize services list and package installation

This patch standardizes the package installation to pass a list rather
than "with_items".

Additionally, we can utilize a filtered_services list to ensure we only
attempt tasks against the relevant hosts rather than running through
tasks that would be skipped.

Change-Id: I2c5ad3c2773b890bf6689b8ff87871a4af2021a8
This commit is contained in:
Andy McCrae 2017-08-10 16:32:42 +01:00 committed by Mohammed Naser
parent b4bed542ba
commit 8dbed05af4
6 changed files with 44 additions and 38 deletions

View File

@ -22,12 +22,11 @@
- name: Stop services
service:
name: "{{ item.value.service_name }}"
name: "{{ item.service_name }}"
enabled: yes
state: "stopped"
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
with_dict: "{{ aodh_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_aodh_services }}"
register: _stop
until: _stop | success
retries: 5
@ -52,12 +51,11 @@
- name: Start services
service:
name: "{{ item.value.service_name }}"
name: "{{ item.service_name }}"
enabled: yes
state: "started"
daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}"
with_dict: "{{ aodh_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_aodh_services }}"
register: _start
until: _start | success
retries: 5

View File

@ -15,56 +15,42 @@
- name: Create TEMP run dir
file:
path: "/var/run/{{ item.value.service_name }}"
path: "/var/run/{{ item.service_name }}"
state: directory
owner: "{{ aodh_system_user_name }}"
group: "{{ aodh_system_group_name }}"
mode: "02755"
with_dict: "{{ aodh_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_aodh_services }}"
- name: Create TEMP lock dir
file:
path: "/var/lock/{{ item.value.service_name }}"
path: "/var/lock/{{ item.service_name }}"
state: directory
owner: "{{ aodh_system_user_name }}"
group: "{{ aodh_system_group_name }}"
mode: "02755"
with_dict: "{{ aodh_services }}"
when: inventory_hostname in groups[item.value.group]
# 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"
state: absent
with_dict: "{{ aodh_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_aodh_services }}"
- name: Create tmpfiles.d entry
template:
src: "aodh-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: "{{ aodh_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_aodh_services }}"
notify:
- Restart aodh services
- name: Place the systemd init script
config_template:
src: "aodh-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: "{{ aodh_services }}"
when: inventory_hostname in groups[item.value.group]
with_items: "{{ filtered_aodh_services }}"
notify:
- Restart aodh services

View File

@ -15,7 +15,7 @@
- name: Install distro packages
package:
name: "{{ item }}"
name: "{{ aodh_distro_packages }}"
state: "{{ aodh_package_state }}"
update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}"
cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}"
@ -23,11 +23,10 @@
until: install_packages|success
retries: 5
delay: 2
with_items: "{{ aodh_distro_packages }}"
- name: Install distro packages for testing
package:
name: "{{ item }}"
name: "{{ aodh_test_distro_packages }}"
state: "{{ aodh_package_state }}"
update_cache: "{{ (ansible_pkg_mgr in ['apt', 'zypper']) | ternary('yes', omit) }}"
cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}"
@ -35,7 +34,6 @@
until: install_packages|success
retries: 5
delay: 2
with_items: "{{ aodh_test_distro_packages }}"
when: install_test_packages|bool
- name: Create developer mode constraint file

View File

@ -10,10 +10,10 @@ Type=simple
User={{ aodh_system_user_name }}
Group={{ aodh_system_group_name }}
{% if program_override is defined %}
ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/aodh/{{ item.value.service_name }}.log
{% if item.program_override is defined %}
ExecStart={{ item.program_override }} {{ item.program_config_options|default('') }} --log-file=/var/log/aodh/{{ item.service_name }}.log
{% else %}
ExecStart={{ aodh_bin }}/{{ item.value.service_name }} {{ program_config_options|default('') }} --log-file=/var/log/aodh/{{ item.value.service_name }}.log
ExecStart={{ aodh_bin }}/{{ item.service_name }} {{ item.program_config_options|default('') }} --log-file=/var/log/aodh/{{ 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 {{ aodh_system_user_name }} {{ aodh_system_group_name }}
D /var/run/{{ item.value.service_name }} 2755 {{ aodh_system_user_name }} {{ aodh_system_group_name }}
D /var/lock/{{ item.service_name }} 2755 {{ aodh_system_user_name }} {{ aodh_system_group_name }}
D /var/run/{{ item.service_name }} 2755 {{ aodh_system_user_name }} {{ aodh_system_group_name }}

24
vars/main.yml Normal file
View File

@ -0,0 +1,24 @@
---
# 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.
filtered_aodh_services: |-
{% set services = [] %}
{% for key, value in aodh_services.items() %}
{% if (value['group'] in group_names) %}
{% set _ = value.update({'service_key': key}) %}
{% set _ = services.append(value) %}
{% endif %}
{% endfor %}
{{ services }}