ansible-edda/playbooks/tasks/services/c-deploy/service-deploy/service.yml

71 lines
2.0 KiB
YAML
Raw Normal View History

- block:
- 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
2022-10-30 21:20:45 +01:00
- 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 }}"