ansible-edda/playbooks/tasks/services/deploy/service/03-pod.yml

79 lines
2.3 KiB
YAML
Raw Normal View History

- block:
- name: Create configuration directory for user {{ service_user_name }}
file:
path: "{{ service_home }}/.config"
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
- include_tasks: "{{ item }}"
with_first_found:
- files:
- "03-pod.d/{{ service_name }}.yml"
skip: true
- name: Create systemd directory for user {{ service_user_name }}
file:
path: "{{ service_home }}/.config/systemd"
state: directory
mode: 0755
- name: Create systemd service directory for user {{ service_user_name }}
file:
path: "{{ service_home }}/.config/systemd/user"
state: directory
mode: 0755
- name: Configure {{ service_user_name }} 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: Enable the {{ service_name }} service
systemd:
name: "pod-{{ service_name }}.service"
enabled: yes
state: started
scope: user
register: systemd_pod_service_enable
- 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_enable is not changed
become_user: "{{ service_user_name }}"