2019-02-05 11:07:08 +02:00
---
2022-07-18 09:39:08 +02:00
- ansible.builtin.set_fact :
2019-02-28 11:51:09 +02:00
well_known_url_matrix : "https://{{ matrix_server_fqn_matrix }}{{ well_known_file_check.path }}"
well_known_url_identity : "https://{{ matrix_domain }}{{ well_known_file_check.path }}"
2019-02-05 11:07:08 +02:00
# These well-known files may be served without a `Content-Type: application/json` header,
# so we can't rely on the uri module's automatic parsing of JSON.
- name : Check .well-known on the matrix hostname
2022-07-18 09:39:08 +02:00
ansible.builtin.uri :
2019-02-05 11:07:08 +02:00
url : "{{ well_known_url_matrix }}"
2020-01-22 23:33:20 +02:00
follow_redirects : none
2019-02-05 11:07:08 +02:00
return_content : true
2019-03-22 09:39:17 +02:00
validate_certs : "{{ well_known_file_check.validate_certs }}"
2021-03-15 11:22:37 +02:00
headers :
Origin : example.com
2022-02-05 22:32:54 +02:00
check_mode : false
2019-02-05 11:07:08 +02:00
register : result_well_known_matrix
ignore_errors : true
- name : Fail if .well-known not working on the matrix hostname
2022-07-18 09:39:08 +02:00
ansible.builtin.fail :
2019-02-28 11:51:09 +02:00
msg : "Failed checking that the well-known file for {{ well_known_file_check.purpose }} is configured at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ well_known_url_matrix }}`). Is port 443 open in your firewall? Full error: {{ result_well_known_matrix }}"
2019-02-05 11:07:08 +02:00
when : "result_well_known_matrix.failed"
- name : Parse JSON for well-known payload at the matrix hostname
2022-07-18 09:39:08 +02:00
ansible.builtin.set_fact :
2022-07-18 11:28:39 +02:00
well_known_matrix_payload : "{{ result_well_known_matrix.content | from_json }}"
2019-02-05 11:07:08 +02:00
- name : Fail if .well-known not CORS-aware on the matrix hostname
2022-07-18 09:39:08 +02:00
ansible.builtin.fail :
2019-02-28 11:51:09 +02:00
msg : "The well-known file for {{ well_known_file_check.purpose }} on `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ well_known_url_matrix }}`) is not CORS-aware. The file needs to be served with an Access-Control-Allow-Origin header set."
2019-02-05 11:07:08 +02:00
when : "well_known_file_check.cors and 'access_control_allow_origin' not in result_well_known_matrix"
- name : Report working .well-known on the matrix hostname
2022-07-18 09:39:08 +02:00
ansible.builtin.debug :
2019-02-28 11:51:09 +02:00
msg : "well-known for {{ well_known_file_check.purpose }} is configured correctly for `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ well_known_url_matrix }}`)"
2019-02-05 11:07:08 +02:00
- name : Check .well-known on the identity hostname
2022-07-18 09:39:08 +02:00
ansible.builtin.uri :
2019-02-05 11:07:08 +02:00
url : "{{ well_known_url_identity }}"
2019-02-25 21:01:52 +02:00
follow_redirects : "{{ well_known_file_check.follow_redirects }}"
2019-02-05 11:07:08 +02:00
return_content : true
2019-03-22 09:39:17 +02:00
validate_certs : "{{ well_known_file_check.validate_certs }}"
2021-03-15 11:22:37 +02:00
headers :
Origin : example.com
2022-02-05 22:32:54 +02:00
check_mode : false
2019-02-05 11:07:08 +02:00
register : result_well_known_identity
ignore_errors : true
- name : Fail if .well-known not working on the identity hostname
2022-07-18 09:39:08 +02:00
ansible.builtin.fail :
2019-02-28 11:51:09 +02:00
msg : "Failed checking that the well-known file for {{ well_known_file_check.purpose }} is configured at `{{ matrix_domain }}` (checked endpoint: `{{ well_known_url_identity }}`). Is port 443 open in your firewall? Full error: {{ result_well_known_identity }}"
2019-02-05 11:07:08 +02:00
when : "result_well_known_identity.failed"
- name : Parse JSON for well-known payload at the identity hostname
2022-07-18 09:39:08 +02:00
ansible.builtin.set_fact :
2022-07-18 11:28:39 +02:00
well_known_identity_payload : "{{ result_well_known_identity.content | from_json }}"
2019-02-05 11:07:08 +02:00
- name : Fail if .well-known not CORS-aware on the identity hostname
2022-07-18 09:39:08 +02:00
ansible.builtin.fail :
2019-02-28 11:51:09 +02:00
msg : "The well-known file for {{ well_known_file_check.purpose }} on `{{ matrix_domain }}` (checked endpoint: `{{ well_known_url_identity }}`) is not CORS-aware. The file needs to be served with an Access-Control-Allow-Origin header set. See docs/configuring-well-known.md"
2019-02-05 11:07:08 +02:00
when : "well_known_file_check.cors and 'access_control_allow_origin' not in result_well_known_identity"
# For people who manually copy the well-known file, try to detect if it's outdated
- name : Fail if well-known is different on matrix hostname and identity hostname
2022-07-18 09:39:08 +02:00
ansible.builtin.fail :
2019-02-28 11:51:09 +02:00
msg : "The well-known files for {{ well_known_file_check.purpose }} at `{{ matrix_server_fqn_matrix }}` and `{{ matrix_domain }}` are different. Perhaps you copied the file ({{ well_known_file_check.path }}) manually before and now it's outdated?"
2019-02-05 11:07:08 +02:00
when : "well_known_matrix_payload != well_known_identity_payload"
- name : Report working .well-known on the identity hostname
2022-07-18 09:39:08 +02:00
ansible.builtin.debug :
2019-02-28 11:51:09 +02:00
msg : "well-known for {{ well_known_file_check.purpose }} ({{ well_known_file_check.path }}) is configured correctly for `{{ matrix_domain }}` (checked endpoint: `{{ well_known_url_identity }}`)"