diff options
Diffstat (limited to 'roles/systemd_depend_mount')
-rw-r--r-- | roles/systemd_depend_mount/defaults/main.yml | 2 | ||||
-rw-r--r-- | roles/systemd_depend_mount/handlers/main.yml | 13 | ||||
-rw-r--r-- | roles/systemd_depend_mount/tasks/main.yml | 28 | ||||
-rw-r--r-- | roles/systemd_depend_mount/templates/override.conf.j2 | 4 |
4 files changed, 47 insertions, 0 deletions
diff --git a/roles/systemd_depend_mount/defaults/main.yml b/roles/systemd_depend_mount/defaults/main.yml new file mode 100644 index 0000000..4d1b819 --- /dev/null +++ b/roles/systemd_depend_mount/defaults/main.yml @@ -0,0 +1,2 @@ +#systemd_depend_mount_dir: +systemd_depend_mount_services: [] diff --git a/roles/systemd_depend_mount/handlers/main.yml b/roles/systemd_depend_mount/handlers/main.yml new file mode 100644 index 0000000..81bae32 --- /dev/null +++ b/roles/systemd_depend_mount/handlers/main.yml @@ -0,0 +1,13 @@ +- name: Reload systemd daemon + become: true + ansible.builtin.systemd_service: + daemon_reload: true + listen: systemd_depend_mount_restart + +- name: Restart systemd services + become: true + ansible.builtin.systemd_service: + name: '{{ item }}' + state: restarted + listen: systemd_depend_mount_restart + loop: "{{ systemd_depend_mount_result.results | selectattr('changed', 'equalto', true) | map(attribute='service') | list }}" diff --git a/roles/systemd_depend_mount/tasks/main.yml b/roles/systemd_depend_mount/tasks/main.yml new file mode 100644 index 0000000..d759b00 --- /dev/null +++ b/roles/systemd_depend_mount/tasks/main.yml @@ -0,0 +1,28 @@ +- name: Create override directory + become: true + ansible.builtin.file: + path: '/etc/systemd/system/{{ service }}.service.d' + state: directory + owner: root + group: root + mode: '755' + loop: '{{ systemd_depend_mount_services }}' + loop_control: + loop_var: service + +- name: Create service override + become: true + ansible.builtin.template: + src: override.conf.j2 + dest: '/etc/systemd/system/{{ service }}.service.d/depend_mount_{{ systemd_depend_mount_dir | regex_replace("/", "_") }}.conf' + owner: root + group: root + mode: '644' + register: systemd_depend_mount_result + notify: systemd_depend_mount_restart + loop: '{{ systemd_depend_mount_services }}' + loop_control: + loop_var: service + +- name: Restart systemd services if necessary + ansible.builtin.meta: flush_handlers diff --git a/roles/systemd_depend_mount/templates/override.conf.j2 b/roles/systemd_depend_mount/templates/override.conf.j2 new file mode 100644 index 0000000..797cd67 --- /dev/null +++ b/roles/systemd_depend_mount/templates/override.conf.j2 @@ -0,0 +1,4 @@ +{{ ansible_managed | comment }} + +[Unit] +RequiresMountsFor={{ systemd_depend_mount_dir }} |