openstack-ansible/playbooks/common-tasks/restart-service.yml
Mohammed Naser 270955fe0c nspawn: fix restart-service.yml service list filtering
The service list filtering is supposed to look for all services
that are prefixed with 'service_name', however, we are not doing
that in the regex.

When using nspawn and restarting a service such as 'nova', it matches
the systemd-nspawn service for the container and attempts to reload
it which fails.

This fixes it by forcing it to check for services *prefixed* with
that variable.

Change-Id: Ib1a3975f2722127eada2dd957300fd306abbe6d9
2019-02-01 14:57:02 -05:00

48 lines
1.7 KiB
YAML

---
# 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.
# This is a generic task set which can be used to execute
# a service action on target hosts for any services. This
# is useful for executing a SIGHUP (reload) to load up any
# configuration changes or to restart services as required.
#
# Inputs:
# - service_name: Any service found matching this prefix will be acted on.
# - service_action: The action to execute [stop, start, restart, reload].
- name: Gather service list
shell: "systemctl list-unit-files --state=enabled --type=service | awk '/^{{ service_name }}.* enabled$/ {print $1}'"
args:
executable: "/bin/bash"
register: _enabled_services
changed_when: false
tags:
- skip_ansible_lint
- name: Execute service action
service:
name: "{{ service_file }}"
state: "{{ service_action }}"
with_items: "{{ (_enabled_services.stdout_lines | difference(service_negate | default([]))) | list }}"
loop_control:
loop_var: service_file
- name: Disable the service restart requirement
ini_file:
dest: "/etc/ansible/facts.d/openstack_ansible.fact"
section: "{{ service_fact | default(service_name) }}"
option: need_service_restart
value: False