2022-09-26 23:10:48 +02:00
|
|
|
- block:
|
2022-10-30 21:08:41 +01:00
|
|
|
|
2022-09-26 23:10:48 +02:00
|
|
|
- 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
|
|
|
|
|
2022-10-30 21:08:41 +01:00
|
|
|
- name: Configure {{ service_user_name }} SystemD service
|
2022-09-26 23:10:48 +02:00
|
|
|
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
|
|
|
|
|
2022-10-30 21:20:45 +01:00
|
|
|
- name: Reset service_changed variable
|
|
|
|
set_fact:
|
|
|
|
service_changed: false
|
|
|
|
|
2022-10-30 19:46:24 +01:00
|
|
|
- include_tasks: "{{ item }}"
|
|
|
|
with_first_found:
|
|
|
|
- files:
|
2022-10-30 21:08:41 +01:00
|
|
|
- "service.d/{{ service_name }}.yml"
|
2022-10-30 19:46:24 +01:00
|
|
|
skip: true
|
|
|
|
|
2022-09-26 23:10:48 +02:00
|
|
|
- name: Enable the {{ service_name }} service
|
|
|
|
systemd:
|
|
|
|
name: "pod-{{ service_name }}.service"
|
|
|
|
enabled: yes
|
2022-11-03 01:06:40 +01:00
|
|
|
scope: user
|
|
|
|
|
|
|
|
- name: Start the {{ service_name }} service
|
|
|
|
systemd:
|
|
|
|
name: "pod-{{ service_name }}.service"
|
2022-09-26 23:10:48 +02:00
|
|
|
state: started
|
|
|
|
scope: user
|
2022-11-03 01:06:40 +01:00
|
|
|
register: systemd_pod_service_start
|
2022-09-26 23:10:48 +02:00
|
|
|
|
|
|
|
- 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
|
2022-11-03 01:06:40 +01:00
|
|
|
systemd_pod_service_start is not changed
|
2022-09-26 23:10:48 +02:00
|
|
|
|
|
|
|
become_user: "{{ service_user_name }}"
|