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

108 lines
4.2 KiB
YAML
Raw Normal View History

2022-12-18 23:43:40 +01:00
---
2023-07-17 22:31:05 +02:00
- name: "{{ services_service_name }} : set the user variables"
2022-12-16 21:49:50 +01:00
ansible.builtin.import_role:
2022-12-18 19:36:21 +01:00
name: "services/include"
2022-12-16 21:49:50 +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_rproxy_hosts_file
2023-07-17 22:31:05 +02:00
- name: "{{ services_service_name }} : create nginx conf.d"
2022-12-16 21:49:50 +01:00
ansible.builtin.file:
path: "{{ services_service_user_home }}/.config/service/nginx-conf.d"
2022-12-16 21:49:50 +01:00
state: "directory"
mode: 0755
2023-07-17 22:31:05 +02:00
- name: "{{ services_service_name }} : generic nginx reverse proxy configuration"
2022-12-16 21:49:50 +01:00
ansible.builtin.copy:
2023-07-17 22:31:05 +02:00
src: "./config/nginx.conf"
dest: "{{ services_service_user_home }}/.config/service/nginx.conf"
2022-12-16 21:49:50 +01:00
mode: 0644
2023-07-17 22:31:05 +02:00
register: services_deploy_rproxy_generic_config
- name: "{{ services_service_name }} : stream nginx reverse proxy configuration"
2023-08-17 17:09:30 +02:00
ansible.builtin.template:
2023-07-17 22:31:05 +02:00
src: "{{ services_deploy_rproxy_nginx_stream_config }}"
dest: "{{ services_service_user_home }}/.config/service/stream.conf"
2023-07-17 22:31:05 +02:00
mode: 0644
register: services_deploy_rproxy_stream_config
- name: "{{ services_service_name }} : subdomain nginx reverse proxy configuration"
2023-08-17 17:09:30 +02:00
ansible.builtin.template:
2023-07-17 22:31:05 +02:00
src: "{{ item }}"
dest: "{{ services_service_user_home }}/.config/service/nginx-conf.d/{{ item | basename }}"
2023-07-17 22:31:05 +02:00
mode: 0644
loop: "{{ services_deploy_rproxy_nginx_subdomain_config_files }}"
register: services_deploy_rproxy_subdomain_config_files
2022-12-16 21:49:50 +01:00
2023-11-10 11:19:08 +01:00
- name: "{{ services_service_name }} : certbot crontab"
ansible.builtin.copy:
src: "./crontabs/root"
dest: "{{ services_service_user_home }}/.config/service/crontabs-root"
mode: 0600
register: services_deploy_rproxy_crontabs_root
2023-07-17 22:31:05 +02:00
- name: "{{ services_service_name }} : configure systemd service"
2022-12-16 21:49:50 +01:00
ansible.builtin.template:
2023-07-08 10:04:37 +02:00
src: "./systemd/{{ item }}"
2023-07-17 22:31:05 +02:00
dest: "\
{{ services_service_user_home }}/.config/systemd/user/\
{{ item | replace('rproxy', services_service_name) }}"
mode: 0600
2022-12-16 21:49:50 +01:00
loop:
- "pod-rproxy.service"
- "container-rproxy-nginx.service"
- "container-rproxy-certbot.service"
register: services_deploy_rproxy_systemd_files
2023-07-17 22:31:05 +02:00
- name: "{{ services_service_name }} : systemd user daemon reload"
2022-12-16 22:16:23 +01:00
ansible.builtin.systemd:
2022-12-16 21:49:50 +01:00
daemon_reload: true
scope: "user"
when:
services_deploy_rproxy_systemd_files.changed
2023-07-17 22:31:05 +02:00
- name: "{{ services_service_name }} : generate diffie hellman ephemeral parameters"
2022-12-18 23:43:40 +01:00
ansible.builtin.command: >-
openssl dhparam --out /{{ services_service_user_home }}/.config/service/dhparam.pem 4096
2022-12-16 21:49:50 +01:00
args:
creates: "{{ services_service_user_home }}/.config/service/dhparam.pem"
2022-12-16 21:49:50 +01:00
register: services_deploy_rproxy_dhparam
2023-07-17 22:31:05 +02:00
- name: "{{ services_service_name }} : get uid"
ansible.builtin.getent:
database: "passwd"
key: "{{ services_service_user_name }}"
2022-12-16 21:49:50 +01:00
2023-07-17 22:31:05 +02:00
- 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_rproxy_service_active_state
2022-12-16 21:49:50 +01:00
2023-07-17 22:31:05 +02:00
- name: "{{ services_service_name }} : restart the service"
2022-12-16 21:49:50 +01:00
ansible.builtin.systemd:
name: "pod-{{ services_service_name }}.service"
state: "restarted"
scope: "user"
2022-12-16 21:49:50 +01:00
when:
(services_deploy_rproxy_hosts_file.changed or
services_deploy_rproxy_generic_config.changed or
2023-07-17 22:31:05 +02:00
services_deploy_rproxy_stream_config.changed or
services_deploy_rproxy_subdomain_config_files.changed or
2023-11-10 11:19:08 +01:00
services_deploy_rproxy_crontabs_root.changed or
2022-12-16 21:49:50 +01:00
services_deploy_rproxy_systemd_files.changed or
services_deploy_rproxy_dhparam.changed) and
services_deploy_rproxy_service_active_state.stdout == "active"
2022-12-16 21:49:50 +01:00
become_user: "{{ services_service_user_name }}"