Skip to content

Commit

Permalink
Fix global lock path usage
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cloudnull committed Dec 27, 2018
1 parent f79988e commit 86ad639
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions defaults/main.yml
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions tasks/main.yml
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions 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) }}

0 comments on commit 86ad639

Please sign in to comment.