Merge "Add option to create systemd native service overrides"

This commit is contained in:
Zuul 2021-01-14 10:29:02 +00:00 committed by Gerrit Code Review
commit 6937a0a67a
4 changed files with 63 additions and 0 deletions

View File

@ -110,6 +110,10 @@ systemd_environment: {}
# `environment_file` -- (optional) set additional environment settings through a given file. this option is a string.
# `dynamic_user` -- (optional) Dynamically set a UNIX user and group when the unit is started; only works if systemd >= 235.
# `state_directory` -- (optional) Relative path the state directory; only works if systemd >= 235.
# `systemd_overrides` -- (optional) Dictionary that may contain custom structure in config_overrides format that
# will be used to generate systemd overrides in /etc/systemd/system/service_name.service.d/overrides.conf
# `systemd_overrides_only` -- (optional) Boolean variable, when True no service_name.service will be generated and role
# will place only overrides for the existing service.
# Under the service dictionary the "sockets" key can be added, which may contain list of the sockets
# for the given service_name. Each socket in the lsit may have following structure:
@ -215,4 +219,14 @@ systemd_environment: {}
# state: "started"
# cron_minute: 30
# cron_hour: 1
#
# - service_name: ExistingService
# config_overrides: {}
# systemd_overrides_only: True
# systemd_overrides: # This is used for adjusting existing services with arbitratry options
# Unit:
# Wants:
# - ServiceZ
# - ServiceY
# restart_changed: no
systemd_services: []

View File

@ -0,0 +1,9 @@
---
features:
- |
Added `systemd_overrides` and `systemd_overrides_only` keys to the
`systemd_services` dictionary. With help of the `systemd_overrides`
you can define systemd native overrides, which will be placed in
/etc/systemd/system/service_name.service.d/overrides.
`systemd_overrides_only` shows that no service_name.service should not
be created and create only overrides.

View File

@ -64,6 +64,18 @@
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"
@ -85,12 +97,27 @@
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
tags:
- systemd-service
- name: Place the systemd timer
template:
src: "systemd-timer.j2"

View File

@ -0,0 +1,13 @@
{% for section, params in item.systemd_overrides.items() %}
[{{ section }}]
{% for key, value in params.items() %}
{% if value is iterable and (var is not string and var is not mapping) %}
{% for i in value %}
{{ key }} = {{ i }}
{% endfor %}
{% else %}
{{ key }} = {{ value }}
{% endif %}
{% endfor %}
{% endfor %}