mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2025-06-25 10:47:51 +02:00
Move roles/matrix* to roles/custom/matrix*
This paves the way for installing other roles into `roles/galaxy` using `ansible-galaxy`, similar to how it's done in: - https://github.com/spantaleev/gitea-docker-ansible-deploy - https://github.com/spantaleev/nextcloud-docker-ansible-deploy In the near future, we'll be removing a lot of the shared role code from here and using upstream roles for it. Some of the core `matrix-*` roles have already been extracted out into other reusable roles: - https://github.com/devture/com.devture.ansible.role.postgres - https://github.com/devture/com.devture.ansible.role.systemd_docker_base - https://github.com/devture/com.devture.ansible.role.timesync - https://github.com/devture/com.devture.ansible.role.vars_preserver - https://github.com/devture/com.devture.ansible.role.playbook_runtime_messages - https://github.com/devture/com.devture.ansible.role.playbook_help We just need to migrate to those.
This commit is contained in:
57
roles/custom/matrix-ldap-registration-proxy/tasks/init.yml
Normal file
57
roles/custom/matrix-ldap-registration-proxy/tasks/init.yml
Normal file
@ -0,0 +1,57 @@
|
||||
---
|
||||
# See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1070
|
||||
# and https://github.com/spantaleev/matrix-docker-ansible-deploy/commit/1ab507349c752042d26def3e95884f6df8886b74#commitcomment-51108407
|
||||
- name: Fail if trying to self-build on Ansible < 2.8
|
||||
ansible.builtin.fail:
|
||||
msg: "To self-build the matrix_ldap_registration_proxy image, you should use Ansible 2.8 or higher. See docs/ansible.md"
|
||||
when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_ldap_registration_proxy_container_image_self_build and matrix_ldap_registration_proxy_enabled | bool"
|
||||
|
||||
- ansible.builtin.set_fact:
|
||||
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-ldap-registration-proxy.service'] }}"
|
||||
when: matrix_ldap_registration_proxy_enabled | bool
|
||||
|
||||
- when: matrix_ldap_registration_proxy_enabled | bool
|
||||
tags:
|
||||
- always
|
||||
block:
|
||||
- name: Fail if matrix-nginx-proxy role already executed
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
Trying to append Matrix LDAP registration proxy's reverse-proxying configuration to matrix-nginx-proxy,
|
||||
but it's pointless since the matrix-nginx-proxy role had already executed.
|
||||
To fix this, please change the order of roles in your playbook,
|
||||
so that the matrix-nginx-proxy role would run after the matrix-bridge-mautrix-telegram role.
|
||||
when: matrix_nginx_proxy_role_executed | default(False) | bool
|
||||
|
||||
- name: Generate Matrix LDAP registration proxy proxying configuration for matrix-nginx-proxy
|
||||
ansible.builtin.set_fact:
|
||||
matrix_ldap_registration_proxy_matrix_nginx_proxy_configuration: |
|
||||
location {{ matrix_ldap_registration_proxy_registration_endpoint }} {
|
||||
{% if matrix_nginx_proxy_enabled | default(False) %}
|
||||
{# Use the embedded DNS resolver in Docker containers to discover the service #}
|
||||
resolver 127.0.0.11 valid=5s;
|
||||
set $backend "{{ matrix_ldap_registration_proxy_registration_addr_with_container }}";
|
||||
proxy_pass http://$backend/register;
|
||||
{% else %}
|
||||
{# Generic configuration for use outside of our container setup #}
|
||||
proxy_pass http://{{ matrix_ldap_registration_proxy_registration_addr_sans_container }}/register;
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
- name: Register Matrix LDAP registration proxy proxying configuration with matrix-nginx-proxy
|
||||
ansible.builtin.set_fact:
|
||||
matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: |
|
||||
{{
|
||||
matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([])
|
||||
+
|
||||
[matrix_ldap_registration_proxy_matrix_nginx_proxy_configuration]
|
||||
}}
|
||||
- name: Warn about reverse-proxying if matrix-nginx-proxy not used
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
NOTE: You've enabled the Matrix LDAP registration proxy bridge but are not using the matrix-nginx-proxy
|
||||
reverse proxy.
|
||||
Please make sure that you're proxying the `{{ matrix_ldap_registration_proxy_public_endpoint }}`
|
||||
URL endpoint to the matrix-ldap-proxy container.
|
||||
You can expose the container's port using the `matrix_ldap_registration_proxy_container_http_host_bind_port` variable.
|
||||
when: "not matrix_nginx_proxy_enabled | default(False) | bool"
|
23
roles/custom/matrix-ldap-registration-proxy/tasks/main.yml
Normal file
23
roles/custom/matrix-ldap-registration-proxy/tasks/main.yml
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
|
||||
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml"
|
||||
tags:
|
||||
- always
|
||||
|
||||
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml"
|
||||
when: "run_setup | bool and matrix_ldap_registration_proxy_enabled | bool"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-matrix-ldap-registration-proxy
|
||||
|
||||
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml"
|
||||
when: "run_setup | bool and matrix_ldap_registration_proxy_enabled | bool"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-matrix-ldap-registration-proxy
|
||||
|
||||
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml"
|
||||
when: "run_setup | bool and not matrix_ldap_registration_proxy_enabled | bool"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-matrix-ldap-registration-proxy
|
@ -0,0 +1,63 @@
|
||||
---
|
||||
|
||||
- name: Ensure matrix_ldap_registration_proxy paths exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
state: directory
|
||||
mode: 0750
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
with_items:
|
||||
- {path: "{{ matrix_ldap_registration_proxy_config_path }}", when: true}
|
||||
- {path: "{{ matrix_ldap_registration_proxy_docker_src_files_path }}", when: true}
|
||||
when: "item.when | bool"
|
||||
|
||||
- ansible.builtin.set_fact:
|
||||
matrix_ldap_registration_proxy_requires_restart: false
|
||||
|
||||
- name: Ensure matrix_ldap_registration_proxy repository is present on self-build
|
||||
ansible.builtin.git:
|
||||
repo: "{{ matrix_ldap_registration_proxy_container_image_self_build_repo }}"
|
||||
dest: "{{ matrix_ldap_registration_proxy_docker_src_files_path }}"
|
||||
version: "{{ matrix_ldap_registration_proxy_container_image_self_build_branch }}"
|
||||
force: "yes"
|
||||
become: true
|
||||
become_user: "{{ matrix_user_username }}"
|
||||
register: matrix_ldap_registration_proxy_git_pull_results
|
||||
|
||||
- name: Ensure matrix_ldap_registration_proxy Docker image is built
|
||||
community.docker.docker_image:
|
||||
name: "{{ matrix_ldap_registration_proxy_docker_image }}"
|
||||
source: build
|
||||
force_source: "{{ matrix_ldap_registration_proxy_git_pull_results.changed }}"
|
||||
build:
|
||||
dockerfile: Dockerfile
|
||||
path: "{{ matrix_ldap_registration_proxy_docker_src_files_path }}"
|
||||
pull: true
|
||||
when: true
|
||||
|
||||
- name: Ensure matrix_ldap_registration_proxy config installed
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/ldap-registration-proxy.env.j2"
|
||||
dest: "{{ matrix_ldap_registration_proxy_config_path }}/ldap-registration-proxy.env"
|
||||
mode: 0644
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
|
||||
- name: Ensure matrix-ldap-registration-proxy.service installed
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/systemd/matrix-ldap-registration-proxy.service.j2"
|
||||
dest: "{{ matrix_systemd_path }}/matrix-ldap-registration-proxy.service"
|
||||
mode: 0644
|
||||
register: matrix_ldap_registration_proxy_systemd_service_result
|
||||
|
||||
- name: Ensure systemd reloaded after matrix-ldap-registration-proxy.service installation
|
||||
ansible.builtin.service:
|
||||
daemon_reload: true
|
||||
when: "matrix_ldap_registration_proxy_systemd_service_result.changed | bool"
|
||||
|
||||
- name: Ensure matrix-ldap-registration-proxy.service restarted, if necessary
|
||||
ansible.builtin.service:
|
||||
name: "matrix-ldap-registration-proxy.service"
|
||||
state: restarted
|
||||
when: "matrix_ldap_registration_proxy_requires_restart | bool"
|
@ -0,0 +1,36 @@
|
||||
---
|
||||
|
||||
- name: Check existence of matrix-matrix_ldap_registration_proxy service
|
||||
ansible.builtin.stat:
|
||||
path: "{{ matrix_systemd_path }}/matrix-ldap-registration-proxy.service"
|
||||
register: matrix_ldap_registration_proxy_service_stat
|
||||
|
||||
- name: Ensure matrix-matrix_ldap_registration_proxy is stopped
|
||||
ansible.builtin.service:
|
||||
name: matrix-matrix_ldap_registration_proxy
|
||||
state: stopped
|
||||
enabled: false
|
||||
daemon_reload: true
|
||||
register: stopping_result
|
||||
when: "matrix_ldap_registration_proxy_service_stat.stat.exists | bool"
|
||||
|
||||
- name: Ensure matrix-ldap-registration-proxy.service doesn't exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ matrix_systemd_path }}/matrix-ldap-registration-proxy.service"
|
||||
state: absent
|
||||
when: "matrix_ldap_registration_proxy_service_stat.stat.exists | bool"
|
||||
|
||||
- name: Ensure systemd reloaded after matrix-ldap-registration-proxy.service removal
|
||||
ansible.builtin.service:
|
||||
daemon_reload: true
|
||||
when: "matrix_ldap_registration_proxy_service_stat.stat.exists | bool"
|
||||
|
||||
- name: Ensure Matrix matrix_ldap_registration_proxy paths don't exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ matrix_ldap_registration_proxy_base_path }}"
|
||||
state: absent
|
||||
|
||||
- name: Ensure matrix_ldap_registration_proxy Docker image doesn't exist
|
||||
community.docker.docker_image:
|
||||
name: "{{ matrix_ldap_registration_proxy_docker_image }}"
|
||||
state: absent
|
@ -0,0 +1,12 @@
|
||||
---
|
||||
|
||||
- name: Fail if required settings not defined
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
You need to define a required configuration setting (`{{ item }}`).
|
||||
when: "vars[item] == ''"
|
||||
with_items:
|
||||
- "matrix_ldap_registration_proxy_ldap_uri"
|
||||
- "matrix_ldap_registration_proxy_ldap_base_dn"
|
||||
- "matrix_ldap_registration_proxy_ldap_user"
|
||||
- "matrix_ldap_registration_proxy_ldap_password"
|
Reference in New Issue
Block a user