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

80 lines
2.5 KiB
YAML

---
- name: "set the user variables"
ansible.builtin.import_role:
name: "services/include"
vars_from: "user"
- name: "set the version variables"
ansible.builtin.import_role:
name: "services/deploy/include"
vars_from: "versions"
- block:
- name: "configure nginx"
ansible.builtin.copy:
src: "./config/nginx.conf"
dest: "{{ services_service_user_home }}/.config/{{ services_service_user_name }}/nginx.conf"
mode: 0644
register: services_deploy_cloud_config_files
- name: "configure nextcloud secrets"
ansible.builtin.template:
src: "./nextcloud/{{ item }}.j2"
dest: "{{ services_service_user_home }}/.config/{{ services_service_user_name }}/{{ item }}"
mode: 0600
loop:
- "admin.password"
- "admin.user"
- "database.name"
- "database.password"
- "database.user"
register: services_deploy_cloud_nextcloud_files
- name: "configure systemd service"
ansible.builtin.template:
src: "./systemd/{{ item }}.j2"
dest: "{{ services_service_user_home }}/.config/systemd/user/{{ item }}"
mode: 0600
loop:
- "pod-cloud.service"
- "container-cloud-nginx.service"
- "container-cloud-chown.service"
- "container-cloud-nextcloud.service"
- "container-cloud-cron.service"
register: services_deploy_cloud_systemd_files
- name: "systemd user daemon reload"
ansible.builtin.systemd:
daemon_reload: true
scope: "user"
when:
services_deploy_cloud_systemd_files.changed
- name: "get uid"
ansible.builtin.getent:
database: "passwd"
key: "{{ services_service_user_name }}"
- name: "get service status"
ansible.builtin.command: >-
systemctl --user show --property ActiveState --value
{{ services_service_user_name }}.service
environment:
XDG_RUNTIME_DIR: "/run/user/{{ getent_passwd[services_service_user_name].1 }}"
changed_when: false
register: services_deploy_cloud_service_active_state
- name: "restart the service"
ansible.builtin.systemd:
name: "pod-{{ services_service_name }}.service"
state: "restarted"
scope: "user"
when:
(services_deploy_cloud_config_files.changed or
services_deploy_cloud_nextcloud_files.changed or
services_deploy_cloud_systemd_files.changed) and
services_deploy_cloud_service_active_state.stdout == "active"
become_user: "{{ services_service_user_name }}"