ansible-role-systemd_service/tasks/main.yml
Dmitriy Rabotyagov b763b73ffc Fix linters and metadata
With update of ansible-lint to version >=6.0.0 a lot of new
linters were added, that enabled by default. In order to comply
with linter rules we're applying changes to the role.

With that we also update metdata to reflect current state.

Change-Id: I4aab8ba621228d3fbf79b1da8227be41f3258b5f
2023-07-12 11:58:33 +00:00

169 lines
5.2 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.
- name: Pull systemd version
command: "systemctl --version"
changed_when: false
register: get_systemd_version
check_mode: no
tags:
# Avoid ANSIBLE0006 lint issue: systemctl used in place of systemd module
- skip_ansible_lint
- always
- name: Set systemd version
set_fact:
systemd_version: "{{ get_systemd_version.stdout_lines[0].split()[-1] }}"
tags:
- always
- name: Create TEMP run dir
file:
path: "{{ item.systemd_run_dir | default(systemd_run_dir) }}/{{ item.systemd_slice_name | default(systemd_slice_name) | replace(' ', '_') }}"
state: directory
owner: "{{ item.systemd_user_name | default(systemd_user_name) }}"
group: "{{ item.systemd_group_name | default(systemd_group_name) }}"
mode: "02755"
with_items: "{{ systemd_services }}"
tags:
- systemd-service
- name: Create TEMP service lock dir
file:
path: "{{ item.systemd_lock_dir | default(systemd_lock_dir) }}/{{ item.systemd_slice_name | default(systemd_slice_name) | replace(' ', '_') }}"
state: directory
owner: "{{ item.systemd_user_name | default(systemd_user_name) }}"
group: "{{ item.systemd_group_name | default(systemd_group_name) }}"
mode: "02755"
with_items: "{{ systemd_services }}"
tags:
- systemd-service
- name: Create service.d overrides dir
file:
path: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.service.d"
state: directory
owner: "{{ item.systemd_user_name | default(systemd_user_name) }}"
group: "{{ item.systemd_group_name | default(systemd_group_name) }}"
mode: "02755"
when: "'systemd_overrides' in item"
with_items: "{{ systemd_services }}"
tags:
- systemd-service
- name: Create tmpfiles.d entry
template:
src: "systemd-tmpfiles.j2"
dest: "/etc/tmpfiles.d/{{ item.systemd_tempd_prefix | default(systemd_tempd_prefix) }}-{{ item.service_name | replace(' ', '_') }}.conf"
mode: "0644"
owner: "root"
group: "root"
with_items: "{{ systemd_services }}"
tags:
- systemd-service
- name: Place the systemd service
openstack.config_template.config_template:
src: "systemd-service.j2"
dest: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.service"
mode: "0644"
owner: "root"
group: "root"
config_overrides: "{{ item.config_overrides | default(systemd_service_config_overrides) }}"
config_type: "ini"
with_items: "{{ systemd_services }}"
when: not (item.systemd_overrides_only | default(False) | bool)
notify:
- systemd service changed
register: systemd_services_result
tags:
- systemd-service
- name: Place the systemd override
template:
src: "systemd-service-overrides.j2"
dest: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.service.d/override.conf"
mode: "0644"
owner: "root"
group: "root"
with_items: "{{ systemd_services }}"
when: "'systemd_overrides' in item"
notify:
- systemd service changed
register: systemd_override_result
tags:
- systemd-service
- name: Place the systemd timer
template:
src: "systemd-timer.j2"
dest: "/etc/systemd/system/{{ item.service_name | replace(' ', '_') }}.timer"
mode: "0644"
owner: "root"
group: "root"
when:
- item.timer is defined
with_items: "{{ systemd_services }}"
notify:
- systemd service changed
register: systemd_timer_result
tags:
- systemd-service
- name: Place the systemd socket
template:
src: "systemd-socket.j2"
dest: "/etc/systemd/system/{{ item.1.socket_name | replace(' ', '_') }}.socket"
mode: "0644"
owner: "root"
group: "root"
loop: "{{ systemd_services | subelements('sockets', skip_missing=True) }}"
notify:
- systemd socket changed
- systemd service changed
register: systemd_socket
tags:
- systemd-service
- name: Reload systemd on unit change
systemd:
daemon_reload: yes
when:
- (systemd_services_result is changed) or
(systemd_timer_result is changed) or
(systemd_override_result is changed ) or
(systemd_socket.results | selectattr('changed', 'true') | length > 0)
- name: Including systemd_load tasks
include_tasks: systemd_load.yml
loop: "{{ systemd_services }}"
loop_control:
loop_var: service
args:
apply:
tags:
- systemd-service
tags:
- systemd-service
- name: Load socket
systemd:
name: "{{ item.socket_name | replace(' ', '_') }}.socket"
enabled: "{{ item.enabled | default(systemd_service_enabled) }}"
state: "{{ item.state | default(omit) }}"
loop: "{{ systemd_services | selectattr('sockets', 'defined') | map(attribute='sockets') | flatten(1) }}"
tags:
- systemd-service