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) }}