77 lines
2.2 KiB
YAML
77 lines
2.2 KiB
YAML
- block:
|
|
|
|
- name: Create service configuration directory for {{ service_user_name }}
|
|
file:
|
|
path: "{{ service_home }}/.config/{{ service_user_name }}"
|
|
state: directory
|
|
mode: 0755
|
|
|
|
- name: Check if service configuration exists
|
|
become: no
|
|
delegate_to: localhost
|
|
stat:
|
|
path: "{{ local_service_home }}/.config/{{ service_user_name }}"
|
|
register: local_service_path
|
|
|
|
- name: Synchronise service configuration
|
|
copy:
|
|
src: "{{ local_service_home }}/.config/{{ service_user_name }}"
|
|
dest: "{{ service_home }}/.config"
|
|
directory_mode: 0755
|
|
mode: 0644
|
|
register: service_synchronise
|
|
when:
|
|
local_service_path.stat.exists
|
|
|
|
- name: Configure {{ service_user_name }} SystemD service
|
|
template:
|
|
src: "{{ item }}"
|
|
dest: /{{ service_home }}/.config/systemd/user/{{ item | basename | regex_replace('\.j2','') }}
|
|
mode: 0644
|
|
with_fileglob:
|
|
- "{{ local_service_home }}/.config/systemd/user/*.j2"
|
|
register: systemd_pod_service_files
|
|
|
|
- name: SystemD user daemon reload
|
|
systemd:
|
|
daemon_reload: true
|
|
scope: user
|
|
when:
|
|
systemd_pod_service_files is changed
|
|
|
|
- name: Reset service_changed variable
|
|
set_fact:
|
|
service_changed: false
|
|
|
|
- include_tasks: "{{ item }}"
|
|
with_first_found:
|
|
- files:
|
|
- "service.d/{{ service_name }}.yml"
|
|
skip: true
|
|
|
|
- name: Enable the {{ service_name }} service
|
|
systemd:
|
|
name: "pod-{{ service_name }}.service"
|
|
enabled: yes
|
|
scope: user
|
|
|
|
- name: Start the {{ service_name }} service
|
|
systemd:
|
|
name: "pod-{{ service_name }}.service"
|
|
state: started
|
|
scope: user
|
|
register: systemd_pod_service_start
|
|
|
|
- name: Restart the {{ service_name }} service
|
|
systemd:
|
|
name: "pod-{{ service_name }}.service"
|
|
state: restarted
|
|
scope: user
|
|
when:
|
|
(service_synchronise is changed or
|
|
service_changed is true or
|
|
systemd_pod_service_files is changed) and
|
|
systemd_pod_service_start is not changed
|
|
|
|
become_user: "{{ service_user_name }}"
|