ansible-edda/playbooks/roles/services/deploy/pod/tasks/main.yml

99 lines
4.2 KiB
YAML

---
- block:
- name: "{{ services_service_name }} : configure pod"
ansible.builtin.template:
src: "./pod.service"
dest: "\
{{ services_service_user_home }}/.config/systemd/user/\
pod-{{ services_service_name }}.service"
mode: 0600
vars:
services_deploy_pod_pod_wants: "\
{{ [( 'pod-' ~ services_service_name ~ '-')] |
product(services_deploy_pod.wants) | map('join') |
product(['.service']) | map('join') }}"
register: services_deploy_pod_pod_file
- name: "{{ services_service_name }} : configure oneshot containers"
ansible.builtin.template:
src: "./oneshot.service"
dest: "\
{{ services_service_user_home }}/.config/systemd/user/\
pod-{{ services_service_name }}-{{ item }}.service"
mode: 0600
vars:
services_deploy_pod_oneshot: "{{ services_deploy_pod.oneshot[item] }}"
services_deploy_pod_oneshot_after: "\
{{ [( 'pod-' ~ services_service_name )] |
union([( 'pod-' ~ services_service_name ~ '-')] |
product(services_deploy_pod_oneshot.after | default([])) | map('join')) |
product(['.service']) | map('join') }}"
services_deploy_pod_oneshot_before: "\
{{ [( 'pod-' ~ services_service_name ~ '-')] |
product(services_deploy_pod_oneshot.before | default([])) | map('join') |
product(['.service']) | map('join') }}"
loop: "{{ (services_deploy_pod.oneshot | default({})).keys() }}"
register: services_deploy_pod_oneshot_files
- name: "{{ services_service_name }} : configure daemon containers"
ansible.builtin.template:
src: "./container.service"
dest: "\
{{ services_service_user_home }}/.config/systemd/user/\
pod-{{ services_service_name }}-{{ item }}.service"
mode: 0600
vars:
services_deploy_pod_container: "{{ services_deploy_pod.containers[item] }}"
services_deploy_pod_container_binds_to: "\
{{ [( 'pod-' ~ services_service_name )] |
union([( 'pod-' ~ services_service_name ~ '-')] |
product(services_deploy_pod_container.binds_to | default([])) | map('join')) |
product(['.service']) | map('join') }}"
services_deploy_pod_container_requires: "\
{{ [( 'pod-' ~ services_service_name ~ '-')] |
product(services_deploy_pod_container.requires | default([])) | map('join') |
product(['.service']) | map('join') }}"
services_deploy_pod_container_wants: "\
{{ [( 'pod-' ~ services_service_name ~ '-')] |
product(services_deploy_pod_container.wants | default([])) | map('join') |
product(['.service']) | map('join') }}"
loop: "{{ services_deploy_pod.containers.keys() }}"
register: services_deploy_pod_container_files
- name: "{{ services_service_name }} : systemd user daemon reload"
ansible.builtin.systemd:
daemon_reload: true
scope: "user"
when:
services_deploy_pod_pod_file.changed or
services_deploy_pod_container_files.changed
- name: "{{ services_service_name }} : get uid"
ansible.builtin.getent:
database: "passwd"
key: "{{ services_service_user_name }}"
- name: "{{ services_service_name }} : get service status"
ansible.builtin.command: >-
systemctl --user show --property ActiveState --value
pod-{{ services_service_name }}.service
environment:
XDG_RUNTIME_DIR: "/run/user/{{ getent_passwd[services_service_user_name].1 }}"
changed_when: false
register: services_deploy_pod_service_active_state
- name: "{{ services_service_name }} : restart the service"
ansible.builtin.systemd:
name: "pod-{{ services_service_name }}.service"
state: "restarted"
scope: "user"
when:
(services_deploy_pod_needs_restart or
services_deploy_pod_pod_file.changed or
services_deploy_pod_oneshot_files.changed or
services_deploy_pod_container_files.changed) and
services_deploy_pod_service_active_state.stdout == "active"
become_user: "{{ services_service_user_name }}"