Duplicate matrix-mxisd role for matrix-ma1sd fork
(adapting strings and URLs)
This commit is contained in:
10
roles/matrix-ma1sd/tasks/init.yml
Normal file
10
roles/matrix-ma1sd/tasks/init.yml
Normal file
@ -0,0 +1,10 @@
|
||||
- set_fact:
|
||||
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-ma1sd'] }}"
|
||||
when: matrix_ma1sd_enabled|bool
|
||||
|
||||
# ansible lower than 2.8, does not support docker_image build parameters
|
||||
# for self buildig it is explicitly needed, so we rather fail here
|
||||
- name: Fail if running on Ansible lower than 2.8 and trying self building
|
||||
fail:
|
||||
msg: "To self build ma1sd image, you should usa ansible 2.8 or higher. E.g. pip contains such packages."
|
||||
when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_ma1sd_container_image_self_build"
|
21
roles/matrix-ma1sd/tasks/main.yml
Normal file
21
roles/matrix-ma1sd/tasks/main.yml
Normal file
@ -0,0 +1,21 @@
|
||||
- import_tasks: "{{ role_path }}/tasks/init.yml"
|
||||
tags:
|
||||
- always
|
||||
|
||||
- import_tasks: "{{ role_path }}/tasks/validate_config.yml"
|
||||
when: "run_setup|bool and matrix_ma1sd_enabled|bool"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-ma1sd
|
||||
|
||||
- import_tasks: "{{ role_path }}/tasks/setup_ma1sd.yml"
|
||||
tags:
|
||||
- setup-all
|
||||
- setup-ma1sd
|
||||
|
||||
- import_tasks: "{{ role_path }}/tasks/self_check_ma1sd.yml"
|
||||
delegate_to: 127.0.0.1
|
||||
become: false
|
||||
when: "run_self_check|bool and matrix_ma1sd_enabled|bool"
|
||||
tags:
|
||||
- self-check
|
21
roles/matrix-ma1sd/tasks/self_check_ma1sd.yml
Normal file
21
roles/matrix-ma1sd/tasks/self_check_ma1sd.yml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
|
||||
- set_fact:
|
||||
ma1sd_url_endpoint_public: "https://{{ matrix_server_fqn_matrix }}/_matrix/identity/api/v1"
|
||||
|
||||
- name: Check ma1sd Identity Service
|
||||
uri:
|
||||
url: "{{ ma1sd_url_endpoint_public }}"
|
||||
follow_redirects: none
|
||||
validate_certs: "{{ matrix_ma1sd_self_check_validate_certificates }}"
|
||||
register: result_ma1sd
|
||||
ignore_errors: true
|
||||
|
||||
- name: Fail if ma1sd Identity Service not working
|
||||
fail:
|
||||
msg: "Failed checking ma1sd is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ ma1sd_url_endpoint_public }}`). Is ma1sd running? Is port 443 open in your firewall? Full error: {{ result_ma1sd }}"
|
||||
when: "result_ma1sd.failed or 'json' not in result_ma1sd"
|
||||
|
||||
- name: Report working ma1sd Identity Service
|
||||
debug:
|
||||
msg: "ma1sd at `{{ matrix_server_fqn_matrix }}` is working (checked endpoint: `{{ ma1sd_url_endpoint_public }}`)"
|
137
roles/matrix-ma1sd/tasks/setup_ma1sd.yml
Normal file
137
roles/matrix-ma1sd/tasks/setup_ma1sd.yml
Normal file
@ -0,0 +1,137 @@
|
||||
---
|
||||
|
||||
#
|
||||
# Tasks related to setting up ma1sd
|
||||
#
|
||||
|
||||
- name: Ensure ma1sd paths exist
|
||||
file:
|
||||
path: "{{ item.path }}"
|
||||
state: directory
|
||||
mode: 0750
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_username }}"
|
||||
with_items:
|
||||
- { path: "{{ matrix_ma1sd_config_path }}", when: true }
|
||||
- { path: "{{ matrix_ma1sd_data_path }}", when: true }
|
||||
- { path: "{{ matrix_ma1sd_docker_src_files_path }}", when: "{{ matrix_ma1sd_container_image_self_build }}"}
|
||||
when: matrix_ma1sd_enabled|bool and item.when
|
||||
|
||||
- name: Ensure ma1sd image is pulled
|
||||
docker_image:
|
||||
name: "{{ matrix_ma1sd_docker_image }}"
|
||||
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
|
||||
force_source: "{{ matrix_ma1sd_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
|
||||
force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_ma1sd_docker_image_force_pull }}"
|
||||
when: matrix_ma1sd_enabled|bool and not matrix_ma1sd_container_image_self_build
|
||||
|
||||
- block:
|
||||
- name: Ensure gradle is installed for self-building (Debian)
|
||||
apt:
|
||||
name:
|
||||
- gradle
|
||||
state: present
|
||||
update_cache: yes
|
||||
when: (ansible_os_family == 'Debian')
|
||||
|
||||
- name: Ensure gradle is installed for self-building (CentOS)
|
||||
fail:
|
||||
msg: "Installing gradle on CentOS is currently not supported, so self-building ma1sd cannot happen at this time"
|
||||
when: ansible_distribution == 'CentOS'
|
||||
|
||||
- name: Ensure gradle is installed for self-building (Archlinux)
|
||||
pacman:
|
||||
name:
|
||||
- gradle
|
||||
state: latest
|
||||
update_cache: yes
|
||||
when: ansible_distribution == 'Archlinux'
|
||||
|
||||
- name: Ensure ma1sd repository is present on self-build
|
||||
git:
|
||||
repo: https://github.com/ma1uta/ma1sd.git
|
||||
dest: "{{ matrix_ma1sd_docker_src_files_path }}"
|
||||
version: "v{{ matrix_ma1sd_docker_image.split(':')[1] }}"
|
||||
force: "yes"
|
||||
|
||||
- name: Ensure ma1sd Docker image is built
|
||||
shell: "./gradlew dockerBuild"
|
||||
args:
|
||||
chdir: "{{ matrix_ma1sd_docker_src_files_path }}"
|
||||
when: "matrix_ma1sd_enabled|bool and matrix_ma1sd_container_image_self_build"
|
||||
|
||||
- name: Ensure ma1sd config installed
|
||||
copy:
|
||||
content: "{{ matrix_ma1sd_configuration|to_nice_yaml }}"
|
||||
dest: "{{ matrix_ma1sd_config_path }}/ma1sd.yaml"
|
||||
mode: 0644
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_username }}"
|
||||
when: matrix_ma1sd_enabled|bool
|
||||
|
||||
- name: Ensure custom templates are installed if any
|
||||
copy:
|
||||
content: "{{ item.value }}"
|
||||
dest: "{{ matrix_ma1sd_data_path }}/{{ item.location }}"
|
||||
mode: 0644
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_username }}"
|
||||
with_items:
|
||||
- {value: "{{ matrix_ma1sd_threepid_medium_email_custom_invite_template }}", location: 'invite-template.eml'}
|
||||
- {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'}
|
||||
- {value: "{{ matrix_ma1sd_threepid_medium_email_custom_unbind_fraudulent_template }}", location: 'unbind-fraudulent.eml'}
|
||||
- {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'}
|
||||
when: "matrix_ma1sd_enabled|bool and matrix_ma1sd_threepid_medium_email_custom_templates_enabled|bool and item.value"
|
||||
|
||||
- name: Ensure matrix-ma1sd.service installed
|
||||
template:
|
||||
src: "{{ role_path }}/templates/systemd/matrix-ma1sd.service.j2"
|
||||
dest: "{{ matrix_systemd_path }}/matrix-ma1sd.service"
|
||||
mode: 0644
|
||||
register: matrix_ma1sd_systemd_service_result
|
||||
when: matrix_ma1sd_enabled|bool
|
||||
|
||||
- name: Ensure systemd reloaded after matrix-ma1sd.service installation
|
||||
service:
|
||||
daemon_reload: yes
|
||||
when: "matrix_ma1sd_enabled|bool and matrix_ma1sd_systemd_service_result.changed"
|
||||
|
||||
#
|
||||
# Tasks related to getting rid of ma1sd (if it was previously enabled)
|
||||
#
|
||||
|
||||
- name: Check existence of matrix-ma1sd service
|
||||
stat:
|
||||
path: "{{ matrix_systemd_path }}/matrix-ma1sd.service"
|
||||
register: matrix_ma1sd_service_stat
|
||||
|
||||
- name: Ensure matrix-ma1sd is stopped
|
||||
service:
|
||||
name: matrix-ma1sd
|
||||
state: stopped
|
||||
daemon_reload: yes
|
||||
register: stopping_result
|
||||
when: "not matrix_ma1sd_enabled|bool and matrix_ma1sd_service_stat.stat.exists"
|
||||
|
||||
- name: Ensure matrix-ma1sd.service doesn't exist
|
||||
file:
|
||||
path: "{{ matrix_systemd_path }}/matrix-ma1sd.service"
|
||||
state: absent
|
||||
when: "not matrix_ma1sd_enabled|bool and matrix_ma1sd_service_stat.stat.exists"
|
||||
|
||||
- name: Ensure systemd reloaded after matrix-ma1sd.service removal
|
||||
service:
|
||||
daemon_reload: yes
|
||||
when: "not matrix_ma1sd_enabled|bool and matrix_ma1sd_service_stat.stat.exists"
|
||||
|
||||
- name: Ensure Matrix ma1sd paths don't exist
|
||||
file:
|
||||
path: "{{ matrix_ma1sd_base_path }}"
|
||||
state: absent
|
||||
when: "not matrix_ma1sd_enabled|bool"
|
||||
|
||||
- name: Ensure ma1sd Docker image doesn't exist
|
||||
docker_image:
|
||||
name: "{{ matrix_ma1sd_docker_image }}"
|
||||
state: absent
|
||||
when: "not matrix_ma1sd_enabled|bool"
|
57
roles/matrix-ma1sd/tasks/validate_config.yml
Normal file
57
roles/matrix-ma1sd/tasks/validate_config.yml
Normal file
@ -0,0 +1,57 @@
|
||||
---
|
||||
|
||||
- name: (Deprecation) Warn about ma1sd variables that are not used anymore
|
||||
fail:
|
||||
msg: >
|
||||
The `{{ item }}` variable defined in your configuration is not used by this playbook anymore!
|
||||
You'll need to adapt to the new way of extending ma1sd configuration.
|
||||
See the CHANGELOG and the `matrix_ma1sd_configuration_extension_yaml` variable for more information and examples.
|
||||
when: "item in vars"
|
||||
with_items:
|
||||
- 'matrix_ma1sd_ldap_enabled'
|
||||
- 'matrix_ma1sd_ldap_connection_host'
|
||||
- 'matrix_ma1sd_ldap_connection_tls'
|
||||
- 'matrix_ma1sd_ldap_connection_port'
|
||||
- 'matrix_ma1sd_ldap_connection_baseDn'
|
||||
- 'matrix_ma1sd_ldap_connection_baseDns'
|
||||
- 'matrix_ma1sd_ldap_connection_bindDn'
|
||||
- 'matrix_ma1sd_ldap_connection_bindPassword'
|
||||
- 'matrix_ma1sd_ldap_filter'
|
||||
- 'matrix_ma1sd_ldap_attribute_uid_type'
|
||||
- 'matrix_ma1sd_ldap_attribute_uid_value'
|
||||
- 'matrix_ma1sd_ldap_connection_bindPassword'
|
||||
- 'matrix_ma1sd_ldap_attribute_name'
|
||||
- 'matrix_ma1sd_ldap_attribute_threepid_email'
|
||||
- 'matrix_ma1sd_ldap_attribute_threepid_msisdn'
|
||||
- 'matrix_ma1sd_ldap_identity_filter'
|
||||
- 'matrix_ma1sd_ldap_identity_medium'
|
||||
- 'matrix_ma1sd_ldap_auth_filter'
|
||||
- 'matrix_ma1sd_ldap_directory_filter'
|
||||
- 'matrix_ma1sd_template_config'
|
||||
|
||||
- name: Ensure ma1sd configuration does not contain any dot-notation keys
|
||||
fail:
|
||||
msg: >
|
||||
Since version 1.3.0, ma1sd will not accept property-style configuration keys.
|
||||
You have defined a key (`{{ item.key }}`) which contains a dot.
|
||||
Instead, use nesting. See: https://github.com/kamax-matrix/mxisd/wiki/Upgrade-Notes#v130
|
||||
when: "'.' in item.key"
|
||||
with_dict: "{{ matrix_ma1sd_configuration }}"
|
||||
|
||||
- name: Fail if required ma1sd settings not defined
|
||||
fail:
|
||||
msg: >
|
||||
You need to define a required configuration setting (`{{ item }}`) for using ma1sd.
|
||||
when: "vars[item] == ''"
|
||||
with_items:
|
||||
- "matrix_ma1sd_threepid_medium_email_connectors_smtp_host"
|
||||
|
||||
|
||||
- name: (Deprecation) Catch and report renamed ma1sd variables
|
||||
fail:
|
||||
msg: >-
|
||||
Your configuration contains a variable, which now has a different name.
|
||||
Please change your configuration to rename the variable (`{{ item.old }}` -> `{{ item.new }}`).
|
||||
when: "item.old in vars"
|
||||
with_items:
|
||||
- {'old': 'matrix_ma1sd_container_expose_port', 'new': '<superseded by matrix_ma1sd_container_http_host_bind_port>'}
|
Reference in New Issue
Block a user