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

82 lines
2.6 KiB
YAML
Raw Normal View History

2022-12-18 23:43:40 +01:00
---
2022-12-16 23:57:38 +01:00
- name: "set the user variables"
ansible.builtin.import_role:
2022-12-18 19:36:21 +01:00
name: "services/include"
2022-12-16 23:57:38 +01:00
vars_from: "user"
- block:
- name: "{{ services_service_name }} : configure hosts file"
ansible.builtin.template:
src: "hosts"
dest: "{{ services_service_user_home }}/.config/service/hosts"
mode: 0644
register: services_deploy_cloud_hosts_file
2022-12-16 23:57:38 +01:00
- name: "configure nginx"
ansible.builtin.copy:
src: "./config/nginx.conf"
dest: "{{ services_service_user_home }}/.config/service/nginx.conf"
2022-12-16 23:57:38 +01:00
mode: 0644
register: services_deploy_cloud_config_files
- name: "configure nextcloud secrets"
ansible.builtin.template:
2023-07-08 10:04:37 +02:00
src: "./nextcloud/{{ item }}"
dest: "{{ services_service_user_home }}/.config/service/{{ item }}"
2022-12-16 23:57:38 +01:00
mode: 0600
loop:
- "database.name"
- "database.password"
- "database.user"
register: services_deploy_cloud_nextcloud_files
- name: "configure systemd service"
ansible.builtin.template:
2023-07-08 10:04:37 +02:00
src: "./systemd/{{ item }}"
2022-12-16 23:57:38 +01:00
dest: "{{ services_service_user_home }}/.config/systemd/user/{{ item }}"
mode: 0600
2022-12-16 23:57:38 +01:00
loop:
- "pod-cloud.service"
- "container-cloud-nginx.service"
- "container-cloud-redis.service"
2023-04-08 09:24:47 +02:00
- "container-cloud-chown.service"
2022-12-16 23:57:38 +01:00
- "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 }}"
2022-12-16 23:57:38 +01:00
- 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_cloud_service_active_state
2022-12-16 23:57:38 +01:00
- name: "restart the service"
ansible.builtin.systemd:
name: "pod-{{ services_service_name }}.service"
state: "restarted"
scope: "user"
2022-12-16 23:57:38 +01:00
when:
(services_deploy_cloud_hosts_file.changed or
services_deploy_cloud_config_files.changed or
2022-12-16 23:57:38 +01:00
services_deploy_cloud_nextcloud_files.changed or
services_deploy_cloud_systemd_files.changed) and
services_deploy_cloud_service_active_state.stdout == "active"
2022-12-16 23:57:38 +01:00
become_user: "{{ services_service_user_name }}"