80 lines
2.7 KiB
YAML
80 lines
2.7 KiB
YAML
---
|
|
- name: "set the user variables"
|
|
ansible.builtin.import_role:
|
|
name: "services/include"
|
|
vars_from: "user"
|
|
|
|
- name: "stat the pgadmin password file"
|
|
ansible.builtin.stat:
|
|
path: "{{ services_service_user_home }}/.config/service/pgadmin.password"
|
|
register: services_deploy_database_pgadmin_password_file_stat
|
|
|
|
- name: "configure pgadmin password"
|
|
ansible.builtin.template:
|
|
src: "./pgadmin/pgadmin.password"
|
|
dest: "{{ services_service_user_home }}/.config/service/pgadmin.password"
|
|
mode: 0600
|
|
# Being root allows ansible to read the file, determine the diff, and preserve the uid:gid.
|
|
become_user: "\
|
|
{% if services_deploy_database_pgadmin_password_file_stat.stat.exists %}\
|
|
root\
|
|
{% else %}\
|
|
{{ services_service_user_name }}\
|
|
{% endif %}"
|
|
register: services_deploy_database_pgadmin_password_file
|
|
|
|
- block:
|
|
|
|
- name: "configure postgres password"
|
|
ansible.builtin.template:
|
|
src: "./postgres/database.password"
|
|
dest: "{{ services_service_user_home }}/.config/service/database.password"
|
|
mode: 0600
|
|
register: services_deploy_database_postgres_password_file
|
|
|
|
- name: "configure systemd service"
|
|
ansible.builtin.template:
|
|
src: "./systemd/{{ item }}"
|
|
dest: "{{ services_service_user_home }}/.config/systemd/user/{{ item }}"
|
|
mode: 0600
|
|
loop:
|
|
- "pod-database.service"
|
|
- "container-database-postgres.service"
|
|
- "container-database-pgadmin-chown.service"
|
|
- "container-database-pgadmin.service"
|
|
register: services_deploy_database_systemd_files
|
|
|
|
- name: "systemd user daemon reload"
|
|
ansible.builtin.systemd:
|
|
daemon_reload: true
|
|
scope: "user"
|
|
when:
|
|
services_deploy_database_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
|
|
pod-{{ services_service_name }}.service
|
|
environment:
|
|
XDG_RUNTIME_DIR: "/run/user/{{ getent_passwd[services_service_user_name].1 }}"
|
|
changed_when: false
|
|
register: services_deploy_database_service_active_state
|
|
|
|
- name: "restart the service"
|
|
ansible.builtin.systemd:
|
|
name: "pod-{{ services_service_name }}.service"
|
|
state: "restarted"
|
|
scope: "user"
|
|
when:
|
|
(services_deploy_database_postgres_password_file.changed or
|
|
services_deploy_database_pgadmin_password_file.changed or
|
|
services_deploy_database_systemd_files.changed) and
|
|
services_deploy_database_service_active_state.stdout == "active"
|
|
|
|
become_user: "{{ services_service_user_name }}"
|