From 86ad639f4171b0c01bba030ebc3fd96ec020aa45 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Mon, 26 Nov 2018 11:38:13 -0600 Subject: [PATCH] Fix global lock path usage The option `systemd_lock_path` is intended to be set globally and locally however the global implementation has never been implemented. * The global option will ensure the run and lock path is setup for all services within the `systemd_services` array. * The local option provices a way to override a global lock path based on specific service needs. Change-Id: I373b8905c01ff666b5705bd3bb3c76c3e74a64ab --- defaults/main.yml | 5 +++++ tasks/main.yml | 5 +++-- templates/systemd-tmpfiles.j2 | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index c243bba..e5d0fc9 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -62,6 +62,11 @@ systemd_service_config_overrides: {} # https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type= systemd_default_service_type: simple +# Global lock path used for system services. +# This is an optional variable and will have no effect if undefined. +# This option can also be defined for specific service entries under "systemd_services". +# systemd_lock_path: "/var/lock/service1" + # The systemd services dictionary is a set of services that will be created. The dictionary # can contain the following options: # `service_name` -- (required) used to define the name of the service. This is typically the name of the executable. diff --git a/tasks/main.yml b/tasks/main.yml index 705e792..27f2c18 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -52,13 +52,14 @@ - name: Create TEMP defined lock dir file: - path: "{{ item.systemd_lock_path }}" + path: "{{ item.systemd_lock_path | default(systemd_lock_path) }}" state: directory owner: "{{ item.systemd_user_name | default(systemd_user_name) }}" group: "{{ item.systemd_group_name | default(systemd_group_name) }}" mode: "02755" when: - - item.systemd_lock_path is defined + - (item.systemd_lock_path is defined) or + (systemd_lock_path is defined) with_items: "{{ systemd_services }}" tags: - systemd-service diff --git a/templates/systemd-tmpfiles.j2 b/templates/systemd-tmpfiles.j2 index c8388ba..cebb645 100644 --- a/templates/systemd-tmpfiles.j2 +++ b/templates/systemd-tmpfiles.j2 @@ -1,7 +1,8 @@ # {{ ansible_managed }} -{% if item.systemd_lock_path is defined %} -D {{ item.systemd_lock_path }} 2755 {{ item.systemd_user_name | default(systemd_user_name) }} {{ item.systemd_group_name | default(systemd_group_name) }} +{% if (item.systemd_lock_path is defined) or (systemd_lock_path is defined) %} +D {{ item.systemd_lock_path | default(systemd_lock_path) }} 2755 {{ item.systemd_user_name | default(systemd_user_name) }} {{ item.systemd_group_name | default(systemd_group_name) }} +D {{ (item.systemd_lock_path | default(systemd_lock_path)) | replace('lock', 'run') }} 2755 {{ item.systemd_user_name | default(systemd_user_name) }} {{ item.systemd_group_name | default(systemd_group_name) }} {% endif %} D /var/lock/{{ item.service_name | replace(' ', '_') }} 2755 {{ item.systemd_user_name | default(systemd_user_name) }} {{ item.systemd_group_name | default(systemd_group_name) }} D /var/run/{{ item.service_name | replace(' ', '_') }} 2755 {{ item.systemd_user_name | default(systemd_user_name) }} {{ item.systemd_group_name | default(systemd_group_name) }}