From a9a1448f625018374d14f4443ddd3fedb7fba52f Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Sat, 13 Jan 2024 15:28:45 +0200 Subject: [PATCH] Add self-check for the matrix-corporal HTTP API (if enabled) --- .../custom/matrix-corporal/defaults/main.yml | 1 + .../matrix-corporal/tasks/self_check.yml | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/roles/custom/matrix-corporal/defaults/main.yml b/roles/custom/matrix-corporal/defaults/main.yml index cb2fd4c33..0b77350e5 100644 --- a/roles/custom/matrix-corporal/defaults/main.yml +++ b/roles/custom/matrix-corporal/defaults/main.yml @@ -165,3 +165,4 @@ matrix_corporal_configuration_extension: "{{ matrix_corporal_configuration_exten matrix_corporal_configuration: "{{ matrix_corporal_configuration_default | combine(matrix_corporal_configuration_extension, recursive=True) }}" matrix_corporal_self_check_matrix_client_api_url_endpoint_public: "https://{{ matrix_corporal_matrix_homeserver_api_domain_name }}/_matrix/client/corporal" +matrix_corporal_self_check_corporal_api_url_endpoint_public: "https://{{ matrix_corporal_matrix_homeserver_api_domain_name }}/_matrix/corporal/policy" diff --git a/roles/custom/matrix-corporal/tasks/self_check.yml b/roles/custom/matrix-corporal/tasks/self_check.yml index 3e45547df..0758863f8 100644 --- a/roles/custom/matrix-corporal/tasks/self_check.yml +++ b/roles/custom/matrix-corporal/tasks/self_check.yml @@ -19,3 +19,27 @@ - name: Report working Matrix Corporal HTTP gateway ansible.builtin.debug: msg: "Matrix Corporal is fronting the Matrix Client API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_corporal_self_check_matrix_client_api_url_endpoint_public }}`)" + +- when: matrix_corporal_http_api_enabled | bool + block: + - name: Check Matrix Corporal HTTP API + ansible.builtin.uri: + url: "{{ matrix_corporal_self_check_corporal_api_url_endpoint_public }}" + headers: + Authorization: "Bearer {{ matrix_corporal_http_api_auth_token }}" + follow_redirects: none + return_content: false + check_mode: false + register: result_corporal_api + ignore_errors: true + delegate_to: 127.0.0.1 + become: false + + - name: Fail if Matrix Corporal HTTP API not working + ansible.builtin.fail: + msg: "Failed checking Matrix Corporal is fronting the Matrix Client API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_corporal_self_check_matrix_client_api_url_endpoint_public }}`). Is matrix-corporal running? Is port 443 open in your firewall? Full error: {{ result_corporal_api }}" + when: "result_corporal_api.failed or result_corporal_api.status != 200" + + - name: Report working Matrix Corporal HTTP API + ansible.builtin.debug: + msg: "Matrix Corporal API is working at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_corporal_self_check_corporal_api_url_endpoint_public }}`)"