diff --git a/.config/ansible-lint.yml b/.config/ansible-lint.yml new file mode 100644 index 000000000..beff46585 --- /dev/null +++ b/.config/ansible-lint.yml @@ -0,0 +1,13 @@ +--- + +use_default_rules: true + +skip_list: + - unnamed-task + - no-handler + - no-jinja-nesting + - schema + - command-instead-of-shell + - role-name + +offline: false diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..f0aeb3971 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +.PHONY: lint + +help: ## Show this help. + @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' + +lint: ## Runs ansible-lint against all roles in the playbook + ansible-lint diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 221662c5d..a7290f9de 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -22,16 +22,16 @@ matrix_identity_server_url: "{{ ('https://' + matrix_server_fqn_matrix) if matri matrix_homeserver_container_url: |- {{ 'http://matrix-nginx-proxy:12080' if matrix_nginx_proxy_enabled else { - 'synapse': ('http://matrix-synapse:'+ matrix_synapse_container_client_api_port|string), - 'dendrite': ('http://matrix-dendrite:' + matrix_dendrite_http_bind_port|string), + 'synapse': ('http://matrix-synapse:'+ matrix_synapse_container_client_api_port | string), + 'dendrite': ('http://matrix-dendrite:' + matrix_dendrite_http_bind_port | string), }[matrix_homeserver_implementation] }} matrix_homeserver_container_federation_url: |- {{ 'http://matrix-nginx-proxy:12088' if matrix_nginx_proxy_enabled else { - 'synapse': ('http://matrix-synapse:'+ matrix_synapse_container_federation_api_plain_port|string), - 'dendrite': ('http://matrix-dendrite:' + matrix_dendrite_http_bind_port|string), + 'synapse': ('http://matrix-synapse:'+ matrix_synapse_container_federation_api_plain_port | string), + 'dendrite': ('http://matrix-dendrite:' + matrix_dendrite_http_bind_port | string), }[matrix_homeserver_implementation] }} @@ -1158,7 +1158,7 @@ matrix_backup_borg_postgresql_databases: | 'name': matrix_synapse_database_database }] if (matrix_synapse_enabled and matrix_synapse_database_database == matrix_postgres_db_name and matrix_synapse_database_host == 'matrix-postgres') else []) + - matrix_postgres_additional_databases)|map(attribute='name')|list + matrix_postgres_additional_databases)|map(attribute='name') | list }} matrix_backup_borg_location_source_directories: - "{{ matrix_base_data_path }}" @@ -1431,7 +1431,7 @@ matrix_ma1sd_container_image_self_build: "{{ matrix_architecture != 'amd64' }}" # Normally, matrix-nginx-proxy is enabled and nginx can reach ma1sd over the container network. # If matrix-nginx-proxy is not enabled, or you otherwise have a need for it, you can expose # ma1sd's web-server port. -matrix_ma1sd_container_http_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_ma1sd_container_port|string }}" +matrix_ma1sd_container_http_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_ma1sd_container_port | string }}" # We enable Synapse integration via its Postgres database by default. @@ -1540,14 +1540,14 @@ matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container: "127.0.0.1:1 matrix_nginx_proxy_proxy_synapse_enabled: "{{ matrix_synapse_enabled }}" matrix_nginx_proxy_proxy_synapse_client_api_addr_with_container: "matrix-synapse:{{ matrix_synapse_container_client_api_port }}" matrix_nginx_proxy_proxy_synapse_client_api_addr_sans_container: "127.0.0.1:{{ matrix_synapse_container_client_api_port }}" -matrix_nginx_proxy_proxy_synapse_federation_api_addr_with_container: "matrix-synapse:{{matrix_synapse_container_federation_api_plain_port|string}}" -matrix_nginx_proxy_proxy_synapse_federation_api_addr_sans_container: "127.0.0.1:{{matrix_synapse_container_federation_api_plain_port|string}}" +matrix_nginx_proxy_proxy_synapse_federation_api_addr_with_container: "matrix-synapse:{{matrix_synapse_container_federation_api_plain_port | string}}" +matrix_nginx_proxy_proxy_synapse_federation_api_addr_sans_container: "127.0.0.1:{{matrix_synapse_container_federation_api_plain_port | string}}" matrix_nginx_proxy_proxy_dendrite_enabled: "{{ matrix_dendrite_enabled }}" -matrix_nginx_proxy_proxy_dendrite_client_api_addr_with_container: "matrix-dendrite:{{ matrix_dendrite_http_bind_port|string }}" -matrix_nginx_proxy_proxy_dendrite_client_api_addr_sans_container: "127.0.0.1:{{ matrix_dendrite_http_bind_port|string }}" -matrix_nginx_proxy_proxy_dendrite_federation_api_addr_with_container: "matrix-dendrite:{{ matrix_dendrite_http_bind_port|string }}" -matrix_nginx_proxy_proxy_dendrite_federation_api_addr_sans_container: "127.0.0.1:{{ matrix_dendrite_http_bind_port|string }}" +matrix_nginx_proxy_proxy_dendrite_client_api_addr_with_container: "matrix-dendrite:{{ matrix_dendrite_http_bind_port | string }}" +matrix_nginx_proxy_proxy_dendrite_client_api_addr_sans_container: "127.0.0.1:{{ matrix_dendrite_http_bind_port | string }}" +matrix_nginx_proxy_proxy_dendrite_federation_api_addr_with_container: "matrix-dendrite:{{ matrix_dendrite_http_bind_port | string }}" +matrix_nginx_proxy_proxy_dendrite_federation_api_addr_sans_container: "127.0.0.1:{{ matrix_dendrite_http_bind_port | string }}" # When matrix-nginx-proxy is disabled, the actual port number that the vhost uses may begin to matter. matrix_nginx_proxy_proxy_matrix_federation_port: "{{ matrix_federation_public_port }}" @@ -1885,14 +1885,14 @@ matrix_postgres_import_roles_to_ignore: | {{ [matrix_postgres_connection_username] + - matrix_postgres_additional_databases|map(attribute='username')|list + matrix_postgres_additional_databases|map(attribute='username') | list }} matrix_postgres_import_databases_to_ignore: | {{ [matrix_postgres_db_name] + - matrix_postgres_additional_databases|map(attribute='name')|list + matrix_postgres_additional_databases|map(attribute='name') | list }} ###################################################################### @@ -2058,18 +2058,18 @@ matrix_synapse_container_image_self_build: "{{ matrix_architecture not in ['arm6 # When ma1sd is enabled, we can use it to validate email addresses and phone numbers. # Synapse can validate email addresses by itself as well, but it's probably not what we want by default when we have an identity server. -matrix_synapse_account_threepid_delegates_email: "{{ 'http://matrix-ma1sd:' + matrix_ma1sd_container_port|string if matrix_ma1sd_enabled else '' }}" -matrix_synapse_account_threepid_delegates_msisdn: "{{ 'http://matrix-ma1sd:' + matrix_ma1sd_container_port|string if matrix_ma1sd_enabled else '' }}" +matrix_synapse_account_threepid_delegates_email: "{{ 'http://matrix-ma1sd:' + matrix_ma1sd_container_port | string if matrix_ma1sd_enabled else '' }}" +matrix_synapse_account_threepid_delegates_msisdn: "{{ 'http://matrix-ma1sd:' + matrix_ma1sd_container_port | string if matrix_ma1sd_enabled else '' }}" # Normally, matrix-nginx-proxy is enabled and nginx can reach Synapse over the container network. # If matrix-nginx-proxy is not enabled, or you otherwise have a need for it, # you can expose Synapse's ports to the host. # # For exposing the Matrix Client API's port (plain HTTP) to the local host. -matrix_synapse_container_client_api_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_synapse_container_client_api_port|string }}" +matrix_synapse_container_client_api_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_synapse_container_client_api_port | string }}" # # For exposing the Matrix Federation API's plain port (plain HTTP) to the local host. -matrix_synapse_container_federation_api_plain_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_synapse_container_federation_api_plain_port|string }}" +matrix_synapse_container_federation_api_plain_host_bind_port: "{{ '' if matrix_nginx_proxy_enabled else '127.0.0.1:' + matrix_synapse_container_federation_api_plain_port | string }}" # # For exposing the Matrix Federation API's TLS port (HTTPS) to the internet on all network interfaces. matrix_synapse_container_federation_api_tls_host_bind_port: "{{ matrix_federation_public_port if (matrix_synapse_federation_enabled and matrix_synapse_tls_federation_listener_enabled) else '' }}" @@ -2213,10 +2213,10 @@ matrix_prometheus_scraper_node_enabled: "{{ matrix_prometheus_node_exporter_enab matrix_prometheus_scraper_node_targets: "{{ ['matrix-prometheus-node-exporter:9100'] if matrix_prometheus_node_exporter_enabled else [] }}" matrix_prometheus_scraper_postgres_enabled: "{{ matrix_prometheus_postgres_exporter_enabled }}" -matrix_prometheus_scraper_postgres_targets: "{{ ['matrix-prometheus-postgres-exporter:'+ matrix_prometheus_postgres_exporter_port|string] if matrix_prometheus_scraper_postgres_enabled else [] }}" +matrix_prometheus_scraper_postgres_targets: "{{ ['matrix-prometheus-postgres-exporter:'+ matrix_prometheus_postgres_exporter_port | string] if matrix_prometheus_scraper_postgres_enabled else [] }}" matrix_prometheus_scraper_hookshot_enabled: "{{ matrix_hookshot_metrics_enabled|default(false) }}" -matrix_prometheus_scraper_hookshot_targets: "{{ [matrix_hookshot_container_url|string +':'+ matrix_hookshot_metrics_port|string] if matrix_hookshot_metrics_enabled else [] }}" +matrix_prometheus_scraper_hookshot_targets: "{{ [matrix_hookshot_container_url | string +':'+ matrix_hookshot_metrics_port | string] if matrix_hookshot_metrics_enabled else [] }}" ###################################################################### # @@ -2345,7 +2345,7 @@ matrix_postgres_backup_databases: | 'name': matrix_synapse_database_database }] if (matrix_synapse_enabled and matrix_synapse_database_database == matrix_postgres_db_name and matrix_synapse_database_host == 'matrix-postgres') else []) + - matrix_postgres_additional_databases)|map(attribute='name')|list + matrix_postgres_additional_databases)|map(attribute='name') | list }} ###################################################################### @@ -2367,10 +2367,10 @@ matrix_dendrite_enabled: "{{ matrix_homeserver_implementation == 'dendrite' }}" # you can expose Dendrite's ports to the host. # # For exposing Dendrite's plain HTTP server to the local host. -matrix_dendrite_container_http_host_bind_address: "{{ '' if matrix_nginx_proxy_enabled else ('127.0.0.1:' + matrix_dendrite_http_bind_port|string) }}" +matrix_dendrite_container_http_host_bind_address: "{{ '' if matrix_nginx_proxy_enabled else ('127.0.0.1:' + matrix_dendrite_http_bind_port | string) }}" # # For exposing Dendrite's HTTPS server to the local host. -matrix_dendrite_container_https_host_bind_address: "{{ '' if matrix_nginx_proxy_enabled or not matrix_dendrite_https_bind_port else ('127.0.0.1:' + matrix_dendrite_https_bind_port|string) }}" +matrix_dendrite_container_https_host_bind_address: "{{ '' if matrix_nginx_proxy_enabled or not matrix_dendrite_https_bind_port else ('127.0.0.1:' + matrix_dendrite_https_bind_port | string) }}" matrix_dendrite_sync_api_real_ip_header: "{{ 'X-Forwarded-For' if matrix_nginx_proxy_enabled else '' }}" diff --git a/roles/matrix-aux/tasks/main.yml b/roles/matrix-aux/tasks/main.yml index 2585715be..df7c77d0c 100644 --- a/roles/matrix-aux/tasks/main.yml +++ b/roles/matrix-aux/tasks/main.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/setup.yml" - when: run_stop|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup.yml" + when: run_stop | bool tags: - setup-all - setup-aux-files diff --git a/roles/matrix-aux/tasks/setup.yml b/roles/matrix-aux/tasks/setup.yml index 949c0b4a5..ccb0bdcb4 100644 --- a/roles/matrix-aux/tasks/setup.yml +++ b/roles/matrix-aux/tasks/setup.yml @@ -1,19 +1,19 @@ --- - name: Ensure AUX directories are created - file: + ansible.builtin.file: dest: "{{ item.dest }}" state: directory - owner: "{{ item.owner|default(matrix_user_username) }}" - group: "{{ item.group|default(matrix_user_groupname) }}" - mode: "{{ item.mode|default(matrix_aux_directory_default_mode) }}" + owner: "{{ item.owner | default(matrix_user_username) }}" + group: "{{ item.group | default(matrix_user_groupname) }}" + mode: "{{ item.mode | default(matrix_aux_directory_default_mode) }}" with_items: "{{ matrix_aux_directory_definitions }}" - name: Ensure AUX files are created - copy: + ansible.builtin.copy: dest: "{{ item.dest }}" content: "{{ item.content }}" - owner: "{{ item.owner|default(matrix_user_username) }}" - group: "{{ item.group|default(matrix_user_groupname) }}" - mode: "{{ item.mode|default(matrix_aux_file_default_mode) }}" + owner: "{{ item.owner | default(matrix_user_username) }}" + group: "{{ item.group | default(matrix_user_groupname) }}" + mode: "{{ item.mode | default(matrix_aux_file_default_mode) }}" with_items: "{{ matrix_aux_file_definitions }}" diff --git a/roles/matrix-backup-borg/defaults/main.yml b/roles/matrix-backup-borg/defaults/main.yml index 5003c26c6..893817888 100644 --- a/roles/matrix-backup-borg/defaults/main.yml +++ b/roles/matrix-backup-borg/defaults/main.yml @@ -8,13 +8,14 @@ matrix_backup_borg_config_path: "{{ matrix_backup_borg_base_path }}/config" matrix_backup_borg_container_image_self_build: false matrix_backup_borg_docker_repo: "https://gitlab.com/etke.cc/borgmatic" +matrix_backup_borg_docker_repo_version: main matrix_backup_borg_docker_src_files_path: "{{ matrix_backup_borg_base_path }}/docker-src" # version determined automatically, based on postgres server version (if enabled), otherwise latest is used matrix_backup_borg_version: "" matrix_backup_borg_docker_image: "{{ matrix_backup_borg_docker_image_name_prefix }}etke.cc/borgmatic:{{ matrix_backup_borg_version }}" matrix_backup_borg_docker_image_name_prefix: "{{ 'localhost/' if matrix_backup_borg_container_image_self_build else 'registry.gitlab.com/' }}" -matrix_backup_borg_docker_image_force_pull: "{{ matrix_backup_borg_docker_image.endswith(':latest') or matrix_backup_borg_version|default('') == '' }}" +matrix_backup_borg_docker_image_force_pull: "{{ matrix_backup_borg_docker_image.endswith(':latest') or matrix_backup_borg_version | default('') == '' }}" # A list of extra arguments to pass to the container matrix_backup_borg_container_extra_arguments: [] @@ -93,8 +94,8 @@ matrix_backup_borg_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_backup_borg_configuration_yaml`. -matrix_backup_borg_configuration_extension: "{{ matrix_backup_borg_configuration_extension_yaml|from_yaml if matrix_backup_borg_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_backup_borg_configuration_extension: "{{ matrix_backup_borg_configuration_extension_yaml | from_yaml if matrix_backup_borg_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final borgmatic configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_backup_borg_configuration_yaml`. -matrix_backup_borg_configuration: "{{ matrix_backup_borg_configuration_yaml|from_yaml|combine(matrix_backup_borg_configuration_extension, recursive=True) }}" +matrix_backup_borg_configuration: "{{ matrix_backup_borg_configuration_yaml | from_yaml | combine(matrix_backup_borg_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-backup-borg/tasks/init.yml b/roles/matrix-backup-borg/tasks/init.yml index a82fb7b8e..d57f12491 100644 --- a/roles/matrix-backup-borg/tasks/init.yml +++ b/roles/matrix-backup-borg/tasks/init.yml @@ -1,4 +1,4 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-backup-borg.timer'] }}" - when: matrix_backup_borg_enabled|bool + when: matrix_backup_borg_enabled | bool diff --git a/roles/matrix-backup-borg/tasks/main.yml b/roles/matrix-backup-borg/tasks/main.yml index 0dbf54e15..5de4559c5 100644 --- a/roles/matrix-backup-borg/tasks/main.yml +++ b/roles/matrix-backup-borg/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_backup_borg_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_backup_borg_enabled | bool" tags: - setup-all - setup-backup-borg -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_backup_borg_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_backup_borg_enabled | bool" tags: - setup-all - setup-backup-borg -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_backup_borg_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_backup_borg_enabled | bool" tags: - setup-all - setup-backup-borg diff --git a/roles/matrix-backup-borg/tasks/setup_install.yml b/roles/matrix-backup-borg/tasks/setup_install.yml index 6ef398631..cc9816fa9 100644 --- a/roles/matrix-backup-borg/tasks/setup_install.yml +++ b/roles/matrix-backup-borg/tasks/setup_install.yml @@ -1,19 +1,22 @@ --- + - block: - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/detect_existing_postgres_version.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: detect_existing_postgres_version - name: Fail if detected Postgres version is unsupported - fail: + ansible.builtin.fail: msg: "You cannot use borg backup with such an old version ({{ matrix_postgres_detected_version }}) of Postgres. Consider upgrading - link to docs for upgrading Postgres: docs/maintenance-postgres.md#upgrading-postgresql" when: "matrix_postgres_detected_version not in matrix_backup_borg_supported_postgres_versions" - name: Set the correct borg backup version to use - set_fact: + ansible.builtin.set_fact: matrix_backup_borg_version: "{{ matrix_postgres_detected_version }}" - when: matrix_backup_borg_postgresql_enabled|bool and matrix_backup_borg_version == '' + when: matrix_backup_borg_postgresql_enabled | bool and matrix_backup_borg_version == '' - name: Ensure borg paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -22,18 +25,18 @@ with_items: - {path: "{{ matrix_backup_borg_config_path }}", when: true} - {path: "{{ matrix_backup_borg_docker_src_files_path }}", when: true} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure borgmatic config is created - copy: - content: "{{ matrix_backup_borg_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_backup_borg_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_backup_borg_config_path }}/config.yaml" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: 0640 - name: Ensure borg passwd is created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/passwd.j2" dest: "{{ matrix_backup_borg_config_path }}/passwd" owner: "{{ matrix_user_username }}" @@ -41,7 +44,7 @@ mode: 0640 - name: Ensure borg ssh key is created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/sshkey.j2" dest: "{{ matrix_backup_borg_config_path }}/sshkey" owner: "{{ matrix_user_username }}" @@ -54,21 +57,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_backup_borg_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_backup_borg_docker_image_force_pull }}" - when: "not matrix_backup_borg_container_image_self_build|bool" + when: "not matrix_backup_borg_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure borg repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_backup_borg_docker_repo }}" + version: "{{ matrix_backup_borg_docker_repo_version }}" dest: "{{ matrix_backup_borg_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_backup_borg_git_pull_results - when: "matrix_backup_borg_container_image_self_build|bool" + when: "matrix_backup_borg_container_image_self_build | bool" - name: Ensure borg image is built docker_image: @@ -80,33 +84,33 @@ dockerfile: Dockerfile path: "{{ matrix_backup_borg_docker_src_files_path }}" pull: true - when: "matrix_backup_borg_container_image_self_build|bool" + when: "matrix_backup_borg_container_image_self_build | bool" - name: Ensure matrix-backup-borg.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-backup-borg.service.j2" dest: "{{ matrix_systemd_path }}/matrix-backup-borg.service" mode: 0644 register: matrix_backup_borg_systemd_service_result - name: Ensure matrix-backup-borg.timer installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-backup-borg.timer.j2" dest: "{{ matrix_systemd_path }}/matrix-backup-borg.timer" mode: 0644 register: matrix_backup_borg_systemd_timer_result - name: Ensure systemd reloaded after matrix-backup-borg.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_backup_borg_systemd_service_result.changed|bool" + when: "matrix_backup_borg_systemd_service_result.changed | bool" - name: Ensure matrix-backup-borg.service enabled - service: + ansible.builtin.service: enabled: true name: matrix-backup-borg.service - name: Ensure matrix-backup-borg.timer enabled - service: + ansible.builtin.service: enabled: true name: matrix-backup-borg.timer diff --git a/roles/matrix-backup-borg/tasks/setup_uninstall.yml b/roles/matrix-backup-borg/tasks/setup_uninstall.yml index faad44f72..fb583f57a 100644 --- a/roles/matrix-backup-borg/tasks/setup_uninstall.yml +++ b/roles/matrix-backup-borg/tasks/setup_uninstall.yml @@ -1,37 +1,37 @@ --- - name: Check existence of matrix-backup-borg service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-backup-borg.service" register: matrix_backup_borg_service_stat - name: Ensure matrix-backup-borg is stopped - service: + ansible.builtin.service: name: matrix-backup-borg state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_backup_borg_service_stat.stat.exists|bool" + when: "matrix_backup_borg_service_stat.stat.exists | bool" - name: Ensure matrix-backup-borg.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-backup-borg.service" state: absent - when: "matrix_backup_borg_service_stat.stat.exists|bool" + when: "matrix_backup_borg_service_stat.stat.exists | bool" - name: Ensure matrix-backup-borg.timer doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-backup-borg.timer" state: absent - when: "matrix_backup_borg_service_stat.stat.exists|bool" + when: "matrix_backup_borg_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-backup-borg.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_backup_borg_service_stat.stat.exists|bool" + when: "matrix_backup_borg_service_stat.stat.exists | bool" - name: Ensure Matrix borg paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_backup_borg_base_path }}" state: absent diff --git a/roles/matrix-backup-borg/tasks/validate_config.yml b/roles/matrix-backup-borg/tasks/validate_config.yml index 84b78d1ea..66e487dd9 100644 --- a/roles/matrix-backup-borg/tasks/validate_config.yml +++ b/roles/matrix-backup-borg/tasks/validate_config.yml @@ -1,6 +1,6 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -9,7 +9,7 @@ - "matrix_backup_borg_location_repositories" - name: Fail if encryption passphrase is undefined unless repository is unencrypted - fail: + ansible.builtin.fail: msg: >- You need to define a required passphrase using the `matrix_backup_borg_storage_encryption_passphrase` variable. when: "matrix_backup_borg_storage_encryption_passphrase == '' and matrix_backup_borg_encryption != 'none'" diff --git a/roles/matrix-base/defaults/main.yml b/roles/matrix-base/defaults/main.yml index a0c0da9bb..b658f4e24 100644 --- a/roles/matrix-base/defaults/main.yml +++ b/roles/matrix-base/defaults/main.yml @@ -134,8 +134,8 @@ matrix_host_command_openssl: "/usr/bin/env openssl" matrix_host_command_systemctl: "/usr/bin/env systemctl" matrix_host_command_sh: "/usr/bin/env sh" -matrix_ntpd_package: "{{ 'systemd-timesyncd' if (ansible_os_family == 'RedHat' and ansible_distribution_major_version|int > 7) or (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version|int > 18) else ( 'systemd' if ansible_os_family == 'Suse' else 'ntp' ) }}" -matrix_ntpd_service: "{{ 'systemd-timesyncd' if (ansible_os_family == 'RedHat' and ansible_distribution_major_version|int > 7) or (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version|int > 18) or ansible_distribution == 'Archlinux' or ansible_os_family == 'Suse' else ('ntpd' if ansible_os_family == 'RedHat' else 'ntp') }}" +matrix_ntpd_package: "{{ 'systemd-timesyncd' if (ansible_os_family == 'RedHat' and ansible_distribution_major_version | int > 7) or (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version | int > 18) else ( 'systemd' if ansible_os_family == 'Suse' else 'ntp' ) }}" +matrix_ntpd_service: "{{ 'systemd-timesyncd' if (ansible_os_family == 'RedHat' and ansible_distribution_major_version | int > 7) or (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version | int > 18) or ansible_distribution == 'Archlinux' or ansible_os_family == 'Suse' else ('ntpd' if ansible_os_family == 'RedHat' else 'ntp') }}" matrix_homeserver_url: "https://{{ matrix_server_fqn_matrix }}" @@ -157,7 +157,7 @@ matrix_integration_manager_ui_url: ~ # The domain name where a Jitsi server is self-hosted. # If set, `/.well-known/matrix/client` will suggest Element clients to use that Jitsi server. # See: https://github.com/vector-im/element-web/blob/develop/docs/jitsi.md#configuring-element-to-use-your-self-hosted-jitsi-server -matrix_client_element_jitsi_preferredDomain: '' +matrix_client_element_jitsi_preferredDomain: '' # noqa var-naming # Controls whether Element should use End-to-End Encryption by default. # Setting this to false will update `/.well-known/matrix/client` and tell Element clients to avoid E2EE. @@ -202,11 +202,11 @@ matrix_well_known_matrix_client_configuration_default: "{{ lookup('template', 't # } matrix_well_known_matrix_client_configuration_extension_json: '{}' -matrix_well_known_matrix_client_configuration_extension: "{{ matrix_well_known_matrix_client_configuration_extension_json|from_json if matrix_well_known_matrix_client_configuration_extension_json|from_json is mapping else {} }}" +matrix_well_known_matrix_client_configuration_extension: "{{ matrix_well_known_matrix_client_configuration_extension_json | from_json if matrix_well_known_matrix_client_configuration_extension_json | from_json is mapping else {} }}" # Holds the final `/.well-known/matrix/client` configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_well_known_matrix_client_configuration_default` and `matrix_well_known_matrix_client_configuration_extension_json`. -matrix_well_known_matrix_client_configuration: "{{ matrix_well_known_matrix_client_configuration_default|combine(matrix_well_known_matrix_client_configuration_extension, recursive=True) }}" +matrix_well_known_matrix_client_configuration: "{{ matrix_well_known_matrix_client_configuration_default | combine(matrix_well_known_matrix_client_configuration_extension, recursive=True) }}" # Default `/.well-known/matrix/server` configuration - it covers the generic use case. # You can customize it by controlling the various variables inside the template file that it references. @@ -234,11 +234,11 @@ matrix_well_known_matrix_server_configuration_default: "{{ lookup('template', 't # } matrix_well_known_matrix_server_configuration_extension_json: '{}' -matrix_well_known_matrix_server_configuration_extension: "{{ matrix_well_known_matrix_server_configuration_extension_json|from_json if matrix_well_known_matrix_server_configuration_extension_json|from_json is mapping else {} }}" +matrix_well_known_matrix_server_configuration_extension: "{{ matrix_well_known_matrix_server_configuration_extension_json | from_json if matrix_well_known_matrix_server_configuration_extension_json | from_json is mapping else {} }}" # Holds the final `/.well-known/matrix/server` configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_well_known_matrix_server_configuration_default` and `matrix_well_known_matrix_server_configuration_extension_json`. -matrix_well_known_matrix_server_configuration: "{{ matrix_well_known_matrix_server_configuration_default|combine(matrix_well_known_matrix_server_configuration_extension, recursive=True) }}" +matrix_well_known_matrix_server_configuration: "{{ matrix_well_known_matrix_server_configuration_default | combine(matrix_well_known_matrix_server_configuration_extension, recursive=True) }}" # The side-effect of this lookup is that Ansible would even parse the JSON for us, returning a dict. # This is unlike what it does when looking up YAML template files (no automatic parsing there). @@ -246,11 +246,11 @@ matrix_well_known_matrix_support_configuration_default: "{{ lookup('template', ' matrix_well_known_matrix_support_configuration_extension_json: '{}' -matrix_well_known_matrix_support_configuration_extension: "{{ matrix_well_known_matrix_support_configuration_extension_json|from_json if matrix_well_known_matrix_support_configuration_extension_json|from_json is mapping else {} }}" +matrix_well_known_matrix_support_configuration_extension: "{{ matrix_well_known_matrix_support_configuration_extension_json | from_json if matrix_well_known_matrix_support_configuration_extension_json | from_json is mapping else {} }}" # Holds the final `/.well-known/matrix/support` configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_well_known_matrix_support_configuration_default` and `matrix_well_known_matrix_support_configuration_extension_json`. -matrix_well_known_matrix_support_configuration: "{{ matrix_well_known_matrix_support_configuration_default|combine(matrix_well_known_matrix_support_configuration_extension, recursive=True) }}" +matrix_well_known_matrix_support_configuration: "{{ matrix_well_known_matrix_support_configuration_default | combine(matrix_well_known_matrix_support_configuration_extension, recursive=True) }}" # The Docker network that all services would be put into matrix_docker_network: "matrix" diff --git a/roles/matrix-base/tasks/clean_up_old_files.yml b/roles/matrix-base/tasks/clean_up_old_files.yml index 03eb8bcce..b79c01b3f 100644 --- a/roles/matrix-base/tasks/clean_up_old_files.yml +++ b/roles/matrix-base/tasks/clean_up_old_files.yml @@ -1,7 +1,7 @@ --- - name: Get rid of old files and directories - file: + ansible.builtin.file: path: "{{ item }}" state: absent with_items: diff --git a/roles/matrix-base/tasks/main.yml b/roles/matrix-base/tasks/main.yml index 1cdc0432e..2205056d8 100644 --- a/roles/matrix-base/tasks/main.yml +++ b/roles/matrix-base/tasks/main.yml @@ -1,34 +1,34 @@ --- -- import_tasks: "{{ role_path }}/tasks/sanity_check.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/sanity_check.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/clean_up_old_files.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/clean_up_old_files.yml" + when: run_setup | bool tags: - setup-all -- import_tasks: "{{ role_path }}/tasks/server_base/setup.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/server_base/setup.yml" + when: run_setup | bool tags: - setup-all # This needs to always run, because it populates `matrix_user_uid` and `matrix_user_gid`, # which are required by many other roles. -- import_tasks: "{{ role_path }}/tasks/setup_matrix_user.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_matrix_user.yml" + when: run_setup | bool tags: - always - setup-system-user -- import_tasks: "{{ role_path }}/tasks/setup_matrix_base.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_matrix_base.yml" + when: run_setup | bool tags: - setup-all -- import_tasks: "{{ role_path }}/tasks/setup_well_known.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_well_known.yml" + when: run_setup | bool tags: - setup-all - setup-ma1sd diff --git a/roles/matrix-base/tasks/sanity_check.yml b/roles/matrix-base/tasks/sanity_check.yml index 98fa2738f..761006870 100644 --- a/roles/matrix-base/tasks/sanity_check.yml +++ b/roles/matrix-base/tasks/sanity_check.yml @@ -1,27 +1,27 @@ --- - name: Fail if invalid homeserver implementation - fail: + ansible.builtin.fail: msg: "You need to set a valid homeserver implementation in `matrix_homeserver_implementation`" when: "matrix_homeserver_implementation not in ['synapse', 'dendrite']" # We generally support Ansible 2.7.1 and above. - name: Fail if running on Ansible < 2.7.1 - fail: + ansible.builtin.fail: msg: "You are running on Ansible {{ ansible_version.string }}, which is not supported. See our guide about Ansible: https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/docs/ansible.md" when: - "(ansible_version.major < 2) or (ansible_version.major == 2 and ansible_version.minor < 7) or (ansible_version.major == 2 and ansible_version.minor == 7 and ansible_version.revision < 1)" # Though we do not support Ansible 2.9.6 which is buggy - name: Fail if running on Ansible 2.9.6 on Ubuntu - fail: + ansible.builtin.fail: msg: "You are running on Ansible {{ ansible_version.string }}, which is not supported. See our guide about Ansible: https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/docs/ansible.md" when: - ansible_distribution == 'Ubuntu' - "ansible_version.major == 2 and ansible_version.minor == 9 and ansible_version.revision == 6" - name: (Deprecation) Catch and report renamed settings - fail: + ansible.builtin.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 }}`). @@ -35,7 +35,7 @@ # We have a dedicated check for this variable, because we'd like to have a custom (friendlier) message. - name: Fail if matrix_homeserver_generic_secret_key is undefined - fail: + ansible.builtin.fail: msg: | The `matrix_homeserver_generic_secret_key` variable must be defined and have a non-null and non-empty value. @@ -47,41 +47,41 @@ when: "matrix_homeserver_generic_secret_key is none or matrix_homeserver_generic_secret_key == ''" - name: Fail if required variables are undefined - fail: + ansible.builtin.fail: msg: "The `{{ item.var }}` variable must be defined and have a non-null and non-empty value" with_items: - - {'var': matrix_domain, 'value': "{{ matrix_domain|default('') }}"} - - {'var': matrix_server_fqn_matrix, 'value': "{{ matrix_server_fqn_matrix|default('') }}"} - - {'var': matrix_server_fqn_element, 'value': "{{ matrix_server_fqn_element|default('') }}"} - - {'var': matrix_homeserver_container_url, 'value': "{{ matrix_homeserver_container_url|default('') }}"} - - {'var': matrix_homeserver_container_federation_url, 'value': "{{ matrix_homeserver_container_federation_url|default('') }}"} + - {'var': matrix_domain, 'value': "{{ matrix_domain | default('') }}"} + - {'var': matrix_server_fqn_matrix, 'value': "{{ matrix_server_fqn_matrix | default('') }}"} + - {'var': matrix_server_fqn_element, 'value': "{{ matrix_server_fqn_element | default('') }}"} + - {'var': matrix_homeserver_container_url, 'value': "{{ matrix_homeserver_container_url | default('') }}"} + - {'var': matrix_homeserver_container_federation_url, 'value': "{{ matrix_homeserver_container_federation_url | default('') }}"} when: "item.value is none or item.value == ''" - name: Fail if uppercase domain used - fail: + ansible.builtin.fail: msg: "Detected that you're using an uppercase domain name - `{{ item }}`. This will cause trouble. Please use all-lowercase!" with_items: - "{{ matrix_domain }}" - "{{ matrix_server_fqn_matrix }}" - "{{ matrix_server_fqn_element }}" - when: "item != item|lower" + when: "item != item | lower" - name: Fail if using python2 on Archlinux - fail: + ansible.builtin.fail: msg: "Detected that you're using python2 when installing onto Archlinux. Archlinux by default only supports python3." when: - ansible_distribution == 'Archlinux' - ansible_python.version.major != 3 - name: Fail if architecture is set incorrectly - fail: + ansible.builtin.fail: msg: "Detected that variable matrix_architecture {{ matrix_architecture }} appears to be set incorrectly. See docs/alternative-architectures.md. Server appears to be {{ ansible_architecture }}." when: (ansible_architecture == "x86_64" and matrix_architecture != "amd64") or (ansible_architecture == "aarch64" and matrix_architecture != "arm64") or (ansible_architecture.startswith("armv") and matrix_architecture != "arm32") - name: Fail if encountering usage of removed role (mx-puppet-skype) - fail: + ansible.builtin.fail: msg: >- Your configuration seems to include a reference to `matrix_mx_puppet_skype_enabled`. Are you trying to install the mx-puppet-skype bridge? The playbook no longer includes a role for installing mx-puppet-skype, because the mx-puppet-bridge is unmaintained and has been reported as broken for a long time. diff --git a/roles/matrix-base/tasks/server_base/setup.yml b/roles/matrix-base/tasks/server_base/setup.yml index bbfa077c8..40d5a4d01 100644 --- a/roles/matrix-base/tasks/server_base/setup.yml +++ b/roles/matrix-base/tasks/server_base/setup.yml @@ -1,18 +1,18 @@ --- -- include_tasks: "{{ role_path }}/tasks/server_base/setup_redhat.yml" - when: ansible_os_family == 'RedHat' and ansible_distribution_major_version|int < 8 +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_redhat.yml" + when: ansible_os_family == 'RedHat' and ansible_distribution_major_version | int < 8 -- include_tasks: "{{ role_path }}/tasks/server_base/setup_redhat8.yml" - when: ansible_os_family == 'RedHat' and ansible_distribution_major_version|int > 7 and ansible_distribution_major_version|int < 30 +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_redhat8.yml" + when: ansible_os_family == 'RedHat' and ansible_distribution_major_version | int > 7 and ansible_distribution_major_version | int < 30 -- include_tasks: "{{ role_path }}/tasks/server_base/setup_fedora.yml" - when: ansible_os_family == 'RedHat' and ansible_distribution_major_version|int > 30 +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_fedora.yml" + when: ansible_os_family == 'RedHat' and ansible_distribution_major_version | int > 30 - block: # ansible_lsb is only available if lsb-release is installed. - name: Ensure lsb-release installed - apt: + ansible.builtin.apt: name: - lsb-release state: present @@ -20,27 +20,27 @@ register: lsb_release_installation_result - name: Reread ansible_lsb facts if lsb-release got installed - setup: filter=ansible_lsb* + ansible.builtin.setup: filter=ansible_lsb* when: lsb_release_installation_result.changed - - include_tasks: "{{ role_path }}/tasks/server_base/setup_debian.yml" + - ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_debian.yml" when: (ansible_os_family == 'Debian') and (ansible_lsb.id != 'Raspbian') - - include_tasks: "{{ role_path }}/tasks/server_base/setup_raspbian.yml" + - ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_raspbian.yml" when: (ansible_os_family == 'Debian') and (ansible_lsb.id == 'Raspbian') when: ansible_os_family == 'Debian' -- include_tasks: "{{ role_path }}/tasks/server_base/setup_archlinux.yml" +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/server_base/setup_archlinux.yml" when: ansible_distribution == 'Archlinux' - name: Ensure Docker is started and autoruns - service: + ansible.builtin.service: name: docker state: started enabled: true - name: "Ensure {{ matrix_ntpd_service }} is started and autoruns" - service: + ansible.builtin.service: name: "{{ matrix_ntpd_service }}" state: started enabled: true diff --git a/roles/matrix-base/tasks/server_base/setup_archlinux.yml b/roles/matrix-base/tasks/server_base/setup_archlinux.yml index a4912a5db..c912e58f3 100644 --- a/roles/matrix-base/tasks/server_base/setup_archlinux.yml +++ b/roles/matrix-base/tasks/server_base/setup_archlinux.yml @@ -5,12 +5,12 @@ name: - python-docker - python-dnspython - state: latest + state: present update_cache: true - name: Ensure Docker is installed pacman: name: - docker - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/server_base/setup_debian.yml b/roles/matrix-base/tasks/server_base/setup_debian.yml index 5b169df77..271fab41f 100644 --- a/roles/matrix-base/tasks/server_base/setup_debian.yml +++ b/roles/matrix-base/tasks/server_base/setup_debian.yml @@ -1,7 +1,7 @@ --- - name: Ensure APT usage dependencies are installed - apt: + ansible.builtin.apt: name: - apt-transport-https - ca-certificates @@ -10,32 +10,32 @@ update_cache: true - name: Ensure Docker's APT key is trusted - apt_key: - url: "https://download.docker.com/linux/{{ ansible_distribution|lower }}/gpg" + ansible.builtin.apt_key: + url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg" id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 state: present register: add_repository_key ignore_errors: true - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure Docker repository is enabled - apt_repository: - repo: "deb [arch={{ matrix_debian_arch }}] https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} stable" + ansible.builtin.apt_repository: + repo: "deb [arch={{ matrix_debian_arch }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable" state: present update_cache: true - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure APT packages are installed - apt: + ansible.builtin.apt: name: - "{{ matrix_ntpd_package }}" - state: latest + state: present update_cache: true - name: Ensure Docker is installed - apt: + ansible.builtin.apt: name: - "{{ matrix_docker_package_name }}" - - "python{{'3' if ansible_python.version.major == 3 else ''}}-docker" - state: latest - when: matrix_docker_installation_enabled|bool + - "python{{ '3' if ansible_python.version.major == 3 else '' }}-docker" + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/server_base/setup_fedora.yml b/roles/matrix-base/tasks/server_base/setup_fedora.yml index 7369b6ad1..2c7d528fb 100644 --- a/roles/matrix-base/tasks/server_base/setup_fedora.yml +++ b/roles/matrix-base/tasks/server_base/setup_fedora.yml @@ -1,7 +1,7 @@ --- - name: Ensure Docker repository is enabled - template: + ansible.builtin.template: src: "{{ role_path }}/files/yum.repos.d/{{ item }}" dest: "/etc/yum.repos.d/docker-ce.repo" owner: "root" @@ -9,31 +9,31 @@ mode: 0644 with_items: - docker-ce-fedora.repo - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure Docker's RPM key is trusted - rpm_key: + ansible.builtin.rpm_key: state: present key: https://download.docker.com/linux/fedora/gpg - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure yum packages are installed - yum: + ansible.builtin.yum: name: - "{{ matrix_ntpd_package }}" - state: latest + state: present update_cache: true - name: Ensure Docker is installed - yum: + ansible.builtin.yum: name: - "{{ matrix_docker_package_name }}" - python3-pip - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool - name: Ensure Docker-Py is installed - pip: + ansible.builtin.pip: name: docker-py - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/server_base/setup_raspbian.yml b/roles/matrix-base/tasks/server_base/setup_raspbian.yml index 6a09f2fe1..54ea4d185 100644 --- a/roles/matrix-base/tasks/server_base/setup_raspbian.yml +++ b/roles/matrix-base/tasks/server_base/setup_raspbian.yml @@ -1,7 +1,7 @@ --- - name: Ensure APT usage dependencies are installed - apt: + ansible.builtin.apt: name: - apt-transport-https - ca-certificates @@ -10,32 +10,32 @@ update_cache: true - name: Ensure Docker's APT key is trusted - apt_key: + ansible.builtin.apt_key: url: https://download.docker.com/linux/raspbian/gpg id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 state: present register: add_repository_key ignore_errors: true - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure Docker repository is enabled - apt_repository: + ansible.builtin.apt_repository: repo: "deb [arch={{ matrix_debian_arch }}] https://download.docker.com/linux/raspbian {{ ansible_distribution_release }} stable" state: present update_cache: true - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure APT packages are installed - apt: + ansible.builtin.apt: name: - "{{ matrix_ntpd_package }}" - state: latest + state: present update_cache: true - name: Ensure Docker is installed - apt: + ansible.builtin.apt: name: - "{{ matrix_docker_package_name }}" - "python{{'3' if ansible_python.version.major == 3 else ''}}-docker" - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/server_base/setup_redhat.yml b/roles/matrix-base/tasks/server_base/setup_redhat.yml index b4be1d081..4e5c97d4d 100644 --- a/roles/matrix-base/tasks/server_base/setup_redhat.yml +++ b/roles/matrix-base/tasks/server_base/setup_redhat.yml @@ -1,31 +1,31 @@ --- - name: Ensure Docker repository is enabled - template: + ansible.builtin.template: src: "{{ role_path }}/files/yum.repos.d/docker-ce-centos.repo" dest: "/etc/yum.repos.d/docker-ce.repo" owner: "root" group: "root" mode: 0644 - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure Docker's RPM key is trusted - rpm_key: + ansible.builtin.rpm_key: state: present key: https://download.docker.com/linux/centos/gpg - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure yum packages are installed - yum: + ansible.builtin.yum: name: - "{{ matrix_ntpd_package }}" - state: latest + state: present update_cache: true - name: Ensure Docker is installed - yum: + ansible.builtin.yum: name: - "{{ matrix_docker_package_name }}" - docker-python - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/server_base/setup_redhat8.yml b/roles/matrix-base/tasks/server_base/setup_redhat8.yml index d9dd6e23f..932dbab50 100644 --- a/roles/matrix-base/tasks/server_base/setup_redhat8.yml +++ b/roles/matrix-base/tasks/server_base/setup_redhat8.yml @@ -1,44 +1,44 @@ --- - name: Ensure Docker repository is enabled - template: + ansible.builtin.template: src: "{{ role_path }}/files/yum.repos.d/docker-ce-centos.repo" dest: "/etc/yum.repos.d/docker-ce.repo" owner: "root" group: "root" mode: 0644 - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure Docker's RPM key is trusted - rpm_key: + ansible.builtin.rpm_key: state: present key: https://download.docker.com/linux/centos/gpg - when: matrix_docker_installation_enabled|bool and matrix_docker_package_name == 'docker-ce' + when: matrix_docker_installation_enabled | bool and matrix_docker_package_name == 'docker-ce' - name: Ensure EPEL is installed - yum: + ansible.builtin.yum: name: - epel-release - state: latest + state: present update_cache: true - name: Ensure yum packages are installed - yum: + ansible.builtin.yum: name: - "{{ matrix_ntpd_package }}" - state: latest + state: present update_cache: true - name: Ensure Docker is installed - yum: + ansible.builtin.yum: name: - "{{ matrix_docker_package_name }}" - python3-pip - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool - name: Ensure Docker-Py is installed - pip: + ansible.builtin.pip: name: docker-py - state: latest - when: matrix_docker_installation_enabled|bool + state: present + when: matrix_docker_installation_enabled | bool diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index 0fad2b3d6..2e8609873 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -1,7 +1,7 @@ --- - name: Ensure Matrix base path exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: "{{ matrix_base_data_path_mode }}" @@ -11,13 +11,13 @@ - "{{ matrix_base_data_path }}" - name: Preserve vars.yml on the server for easily restoring if it gets lost later on - copy: + ansible.builtin.copy: src: "{{ matrix_vars_yml_snapshotting_src }}" dest: "{{ matrix_base_data_path }}/vars.yml" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: '0660' - when: "matrix_vars_yml_snapshotting_enabled|bool" + when: "matrix_vars_yml_snapshotting_enabled | bool" - name: Ensure Matrix network is created in Docker docker_network: @@ -25,7 +25,7 @@ driver: bridge - name: Ensure matrix-remove-all script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-remove-all.j2" dest: "{{ matrix_local_bin_path }}/matrix-remove-all" mode: 0750 diff --git a/roles/matrix-base/tasks/setup_matrix_user.yml b/roles/matrix-base/tasks/setup_matrix_user.yml index 41604f874..0435b7a3c 100644 --- a/roles/matrix-base/tasks/setup_matrix_user.yml +++ b/roles/matrix-base/tasks/setup_matrix_user.yml @@ -1,18 +1,18 @@ --- - name: Ensure Matrix group is created - group: + ansible.builtin.group: name: "{{ matrix_user_groupname }}" gid: "{{ omit if matrix_user_gid is none else matrix_user_gid }}" state: present register: matrix_group - name: Set Matrix Group GID Variable - set_fact: + ansible.builtin.set_fact: matrix_user_gid: "{{ matrix_group.gid }}" - name: Ensure Matrix user is created - user: + ansible.builtin.user: name: "{{ matrix_user_username }}" uid: "{{ omit if matrix_user_uid is none else matrix_user_uid }}" state: present @@ -23,5 +23,5 @@ register: matrix_user - name: Set Matrix Group UID Variable - set_fact: + ansible.builtin.set_fact: matrix_user_uid: "{{ matrix_user.uid }}" diff --git a/roles/matrix-base/tasks/setup_well_known.yml b/roles/matrix-base/tasks/setup_well_known.yml index da9b534f8..d51e93d3f 100644 --- a/roles/matrix-base/tasks/setup_well_known.yml +++ b/roles/matrix-base/tasks/setup_well_known.yml @@ -4,7 +4,7 @@ # # For running with another webserver, we recommend being part of the `matrix` group. - name: Ensure Matrix static-files path exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0755 @@ -14,27 +14,27 @@ - "{{ matrix_static_files_base_path }}/.well-known/matrix" - name: Ensure Matrix /.well-known/matrix/client file configured - copy: - content: "{{ matrix_well_known_matrix_client_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_well_known_matrix_client_configuration | to_nice_json }}" dest: "{{ matrix_static_files_base_path }}/.well-known/matrix/client" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Matrix /.well-known/matrix/server file configured - copy: - content: "{{ matrix_well_known_matrix_server_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_well_known_matrix_server_configuration | to_nice_json }}" dest: "{{ matrix_static_files_base_path }}/.well-known/matrix/server" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_well_known_matrix_server_enabled|bool + when: matrix_well_known_matrix_server_enabled | bool - name: Ensure Matrix /.well-known/matrix/server file deleted - file: + ansible.builtin.file: path: "{{ matrix_static_files_base_path }}/.well-known/matrix/server" state: absent - when: "not matrix_well_known_matrix_server_enabled|bool" + when: "not matrix_well_known_matrix_server_enabled | bool" - name: Ensure Matrix /.well-known/matrix/support file configured ansible.builtin.copy: diff --git a/roles/matrix-base/tasks/util/ensure_fuse_installed.yml b/roles/matrix-base/tasks/util/ensure_fuse_installed.yml index 7a3fde41d..47d2d9e85 100644 --- a/roles/matrix-base/tasks/util/ensure_fuse_installed.yml +++ b/roles/matrix-base/tasks/util/ensure_fuse_installed.yml @@ -1,23 +1,23 @@ --- # This is for both RedHat 7 and 8 - name: Ensure fuse installed (RedHat) - yum: + ansible.builtin.yum: name: - fuse - state: latest + state: present when: ansible_os_family == 'RedHat' # This is for both Debian and Raspbian - name: Ensure fuse installed (Debian/Raspbian) - apt: + ansible.builtin.apt: name: - fuse - state: latest + state: present when: ansible_os_family == 'Debian' - name: Ensure fuse installed (Archlinux) pacman: name: - fuse3 - state: latest + state: present when: ansible_distribution == 'Archlinux' diff --git a/roles/matrix-base/tasks/util/ensure_openssl_installed.yml b/roles/matrix-base/tasks/util/ensure_openssl_installed.yml index 53fc9b03e..ae22fb495 100644 --- a/roles/matrix-base/tasks/util/ensure_openssl_installed.yml +++ b/roles/matrix-base/tasks/util/ensure_openssl_installed.yml @@ -1,23 +1,23 @@ --- # This is for both RedHat 7 and 8 - name: Ensure openssl installed (RedHat) - yum: + ansible.builtin.yum: name: - openssl - state: latest + state: present when: ansible_os_family == 'RedHat' # This is for both Debian and Raspbian - name: Ensure openssl installed (Debian/Raspbian) - apt: + ansible.builtin.apt: name: - openssl - state: latest + state: present when: ansible_os_family == 'Debian' - name: Ensure openssl installed (Archlinux) pacman: name: - openssl - state: latest + state: present when: ansible_distribution == 'Archlinux' diff --git a/roles/matrix-bot-buscarron/defaults/main.yml b/roles/matrix-bot-buscarron/defaults/main.yml index aff54ceb0..6d289bb9c 100644 --- a/roles/matrix-bot-buscarron/defaults/main.yml +++ b/roles/matrix-bot-buscarron/defaults/main.yml @@ -6,6 +6,7 @@ matrix_bot_buscarron_enabled: true matrix_bot_buscarron_container_image_self_build: false matrix_bot_buscarron_docker_repo: "https://gitlab.com/etke.cc/buscarron.git" +matrix_bot_buscarron_docker_repo_version: "{{ matrix_bot_buscarron_version }}" matrix_bot_buscarron_docker_src_files_path: "{{ matrix_base_data_path }}/buscarron/docker-src" matrix_bot_buscarron_version: v1.2.0 diff --git a/roles/matrix-bot-buscarron/tasks/init.yml b/roles/matrix-bot-buscarron/tasks/init.yml index 3da32948f..a1f5751db 100644 --- a/roles/matrix-bot-buscarron/tasks/init.yml +++ b/roles/matrix-bot-buscarron/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-buscarron.service'] }}" - when: matrix_bot_buscarron_enabled|bool + when: matrix_bot_buscarron_enabled | bool diff --git a/roles/matrix-bot-buscarron/tasks/main.yml b/roles/matrix-bot-buscarron/tasks/main.yml index 63e87dfb8..e6712262f 100644 --- a/roles/matrix-bot-buscarron/tasks/main.yml +++ b/roles/matrix-bot-buscarron/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_bot_buscarron_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_buscarron_enabled | bool" tags: - setup-all - setup-bot-buscarron -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_bot_buscarron_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_buscarron_enabled | bool" tags: - setup-all - setup-bot-buscarron -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_bot_buscarron_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_buscarron_enabled | bool" tags: - setup-all - setup-bot-buscarron diff --git a/roles/matrix-bot-buscarron/tasks/setup_install.yml b/roles/matrix-bot-buscarron/tasks/setup_install.yml index 0ebe7e426..0db7b728b 100644 --- a/roles/matrix-bot-buscarron/tasks/setup_install.yml +++ b/roles/matrix-bot-buscarron/tasks/setup_install.yml @@ -1,32 +1,34 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_bot_buscarron_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_bot_buscarron_sqlite_database_path_local }}" register: matrix_bot_buscarron_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_bot_buscarron_sqlite_database_path_local }}" dst: "{{ matrix_bot_buscarron_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_bot_buscarron_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-bot-buscarron.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_bot_buscarron_requires_restart: true - when: "matrix_bot_buscarron_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_bot_buscarron_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_bot_buscarron_database_engine == 'postgres'" - name: Ensure buscarron paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -37,10 +39,10 @@ - {path: "{{ matrix_bot_buscarron_data_path }}", when: true} - {path: "{{ matrix_bot_buscarron_data_store_path }}", when: true} - {path: "{{ matrix_bot_buscarron_docker_src_files_path }}", when: true} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure buscarron environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/env.j2" dest: "{{ matrix_bot_buscarron_config_path }}/env" owner: "{{ matrix_user_username }}" @@ -53,21 +55,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_bot_buscarron_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_bot_buscarron_docker_image_force_pull }}" - when: "not matrix_bot_buscarron_container_image_self_build|bool" + when: "not matrix_bot_buscarron_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure buscarron repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_bot_buscarron_docker_repo }}" + version: "{{ matrix_bot_buscarron_docker_repo_version }}" dest: "{{ matrix_bot_buscarron_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_bot_buscarron_git_pull_results - when: "matrix_bot_buscarron_container_image_self_build|bool" + when: "matrix_bot_buscarron_container_image_self_build | bool" - name: Ensure buscarron image is built docker_image: @@ -79,22 +82,22 @@ dockerfile: Dockerfile path: "{{ matrix_bot_buscarron_docker_src_files_path }}" pull: true - when: "matrix_bot_buscarron_container_image_self_build|bool" + when: "matrix_bot_buscarron_container_image_self_build | bool" - name: Ensure matrix-bot-buscarron.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-bot-buscarron.service.j2" dest: "{{ matrix_systemd_path }}/matrix-bot-buscarron.service" mode: 0644 register: matrix_bot_buscarron_systemd_service_result - name: Ensure systemd reloaded after matrix-bot-buscarron.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_buscarron_systemd_service_result.changed|bool" + when: "matrix_bot_buscarron_systemd_service_result.changed | bool" - name: Ensure matrix-bot-buscarron.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-bot-buscarron.service" state: restarted - when: "matrix_bot_buscarron_requires_restart|bool" + when: "matrix_bot_buscarron_requires_restart | bool" diff --git a/roles/matrix-bot-buscarron/tasks/setup_uninstall.yml b/roles/matrix-bot-buscarron/tasks/setup_uninstall.yml index cc70e79a3..ad9e78cdd 100644 --- a/roles/matrix-bot-buscarron/tasks/setup_uninstall.yml +++ b/roles/matrix-bot-buscarron/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-buscarron service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-bot-buscarron.service" register: matrix_bot_buscarron_service_stat - name: Ensure matrix-buscarron is stopped - service: + ansible.builtin.service: name: matrix-bot-buscarron state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_bot_buscarron_service_stat.stat.exists|bool" + when: "matrix_bot_buscarron_service_stat.stat.exists | bool" - name: Ensure matrix-bot-buscarron.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-bot-buscarron.service" state: absent - when: "matrix_bot_buscarron_service_stat.stat.exists|bool" + when: "matrix_bot_buscarron_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-bot-buscarron.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_buscarron_service_stat.stat.exists|bool" + when: "matrix_bot_buscarron_service_stat.stat.exists | bool" - name: Ensure Matrix buscarron paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_bot_buscarron_base_path }}" state: absent diff --git a/roles/matrix-bot-buscarron/tasks/validate_config.yml b/roles/matrix-bot-buscarron/tasks/validate_config.yml index 5a517d394..04238012a 100644 --- a/roles/matrix-bot-buscarron/tasks/validate_config.yml +++ b/roles/matrix-bot-buscarron/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bot-go-neb/defaults/main.yml b/roles/matrix-bot-go-neb/defaults/main.yml index 31cb27d67..61c5d54d4 100644 --- a/roles/matrix-bot-go-neb/defaults/main.yml +++ b/roles/matrix-bot-go-neb/defaults/main.yml @@ -224,8 +224,8 @@ matrix_bot_go_neb_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_bot_go_neb_configuration_yaml`. -matrix_bot_go_neb_configuration_extension: "{{ matrix_bot_go_neb_configuration_extension_yaml|from_yaml if matrix_bot_go_neb_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_bot_go_neb_configuration_extension: "{{ matrix_bot_go_neb_configuration_extension_yaml | from_yaml if matrix_bot_go_neb_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_bot_go_neb_configuration_yaml`. -matrix_bot_go_neb_configuration: "{{ matrix_bot_go_neb_configuration_yaml|from_yaml|combine(matrix_bot_go_neb_configuration_extension, recursive=True) }}" +matrix_bot_go_neb_configuration: "{{ matrix_bot_go_neb_configuration_yaml | from_yaml | combine(matrix_bot_go_neb_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-bot-go-neb/tasks/init.yml b/roles/matrix-bot-go-neb/tasks/init.yml index b046d4944..9d5b4f896 100644 --- a/roles/matrix-bot-go-neb/tasks/init.yml +++ b/roles/matrix-bot-go-neb/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-go-neb.service'] }}" - when: matrix_bot_go_neb_enabled|bool + when: matrix_bot_go_neb_enabled | bool diff --git a/roles/matrix-bot-go-neb/tasks/main.yml b/roles/matrix-bot-go-neb/tasks/main.yml index 3c2ed9c58..27487ac53 100644 --- a/roles/matrix-bot-go-neb/tasks/main.yml +++ b/roles/matrix-bot-go-neb/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_bot_go_neb_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_go_neb_enabled | bool" tags: - setup-all - setup-bot-go-neb -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_bot_go_neb_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_go_neb_enabled | bool" tags: - setup-all - setup-bot-go-neb -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_bot_go_neb_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_go_neb_enabled | bool" tags: - setup-all - setup-bot-go-neb diff --git a/roles/matrix-bot-go-neb/tasks/setup_install.yml b/roles/matrix-bot-go-neb/tasks/setup_install.yml index ef2dfbb03..a651c1608 100644 --- a/roles/matrix-bot-go-neb/tasks/setup_install.yml +++ b/roles/matrix-bot-go-neb/tasks/setup_install.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_bot_go_neb_requires_restart: false - name: Ensure go-neb paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -14,7 +14,7 @@ - {path: "{{ matrix_bot_go_neb_config_path }}", when: true} - {path: "{{ matrix_bot_go_neb_data_path }}", when: true} - {path: "{{ matrix_bot_go_neb_data_store_path }}", when: true} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure go-neb image is pulled docker_image: @@ -28,27 +28,27 @@ until: result is not failed - name: Ensure go-neb config installed - copy: - content: "{{ matrix_bot_go_neb_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_bot_go_neb_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_bot_go_neb_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-bot-go-neb.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-bot-go-neb.service.j2" dest: "{{ matrix_systemd_path }}/matrix-bot-go-neb.service" mode: 0644 register: matrix_bot_go_neb_systemd_service_result - name: Ensure systemd reloaded after matrix-bot-go-neb.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_go_neb_systemd_service_result.changed|bool" + when: "matrix_bot_go_neb_systemd_service_result.changed | bool" - name: Ensure matrix-bot-go-neb.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-bot-go-neb.service" state: restarted - when: "matrix_bot_go_neb_requires_restart|bool" + when: "matrix_bot_go_neb_requires_restart | bool" diff --git a/roles/matrix-bot-go-neb/tasks/setup_uninstall.yml b/roles/matrix-bot-go-neb/tasks/setup_uninstall.yml index a009badfd..9794a90ad 100644 --- a/roles/matrix-bot-go-neb/tasks/setup_uninstall.yml +++ b/roles/matrix-bot-go-neb/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-go-neb service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-bot-go-neb.service" register: matrix_bot_go_neb_service_stat - name: Ensure matrix-go-neb is stopped - service: + ansible.builtin.service: name: matrix-bot-go-neb state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_bot_go_neb_service_stat.stat.exists|bool" + when: "matrix_bot_go_neb_service_stat.stat.exists | bool" - name: Ensure matrix-bot-go-neb.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-bot-go-neb.service" state: absent - when: "matrix_bot_go_neb_service_stat.stat.exists|bool" + when: "matrix_bot_go_neb_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-bot-go-neb.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_go_neb_service_stat.stat.exists|bool" + when: "matrix_bot_go_neb_service_stat.stat.exists | bool" - name: Ensure Matrix go-neb paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_bot_go_neb_base_path }}" state: absent diff --git a/roles/matrix-bot-go-neb/tasks/validate_config.yml b/roles/matrix-bot-go-neb/tasks/validate_config.yml index 7b292250a..72bc3cb41 100644 --- a/roles/matrix-bot-go-neb/tasks/validate_config.yml +++ b/roles/matrix-bot-go-neb/tasks/validate_config.yml @@ -1,13 +1,13 @@ --- - name: Fail if there's not at least 1 client - fail: + ansible.builtin.fail: msg: >- You need at least 1 client in the matrix_bot_go_neb_clients block. when: matrix_bot_go_neb_clients is not defined or matrix_bot_go_neb_clients[0] is not defined - name: Fail if there's not at least 1 service - fail: + ansible.builtin.fail: msg: >- You need at least 1 service in the matrix_bot_go_neb_services block. when: matrix_bot_go_neb_services is not defined or matrix_bot_go_neb_services[0] is not defined diff --git a/roles/matrix-bot-honoroit/defaults/main.yml b/roles/matrix-bot-honoroit/defaults/main.yml index 665c64e9c..a48fb8789 100644 --- a/roles/matrix-bot-honoroit/defaults/main.yml +++ b/roles/matrix-bot-honoroit/defaults/main.yml @@ -6,6 +6,7 @@ matrix_bot_honoroit_enabled: true matrix_bot_honoroit_container_image_self_build: false matrix_bot_honoroit_docker_repo: "https://gitlab.com/etke.cc/honoroit.git" +matrix_bot_honoroit_docker_repo_version: "{{ matrix_bot_honoroit_version }}" matrix_bot_honoroit_docker_src_files_path: "{{ matrix_base_data_path }}/honoroit/docker-src" matrix_bot_honoroit_version: v0.9.9 diff --git a/roles/matrix-bot-honoroit/tasks/init.yml b/roles/matrix-bot-honoroit/tasks/init.yml index 5ace015b1..1b03373c8 100644 --- a/roles/matrix-bot-honoroit/tasks/init.yml +++ b/roles/matrix-bot-honoroit/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-honoroit.service'] }}" - when: matrix_bot_honoroit_enabled|bool + when: matrix_bot_honoroit_enabled | bool diff --git a/roles/matrix-bot-honoroit/tasks/main.yml b/roles/matrix-bot-honoroit/tasks/main.yml index 7d66177c6..5de468fe7 100644 --- a/roles/matrix-bot-honoroit/tasks/main.yml +++ b/roles/matrix-bot-honoroit/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_bot_honoroit_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_honoroit_enabled | bool" tags: - setup-all - setup-bot-honoroit -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_bot_honoroit_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_honoroit_enabled | bool" tags: - setup-all - setup-bot-honoroit -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_bot_honoroit_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_honoroit_enabled | bool" tags: - setup-all - setup-bot-honoroit diff --git a/roles/matrix-bot-honoroit/tasks/setup_install.yml b/roles/matrix-bot-honoroit/tasks/setup_install.yml index 584df9b71..9bb979fc2 100644 --- a/roles/matrix-bot-honoroit/tasks/setup_install.yml +++ b/roles/matrix-bot-honoroit/tasks/setup_install.yml @@ -1,32 +1,34 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_bot_honoroit_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_bot_honoroit_sqlite_database_path_local }}" register: matrix_bot_honoroit_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_bot_honoroit_sqlite_database_path_local }}" dst: "{{ matrix_bot_honoroit_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_bot_honoroit_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-bot-honoroit.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_bot_honoroit_requires_restart: true - when: "matrix_bot_honoroit_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_bot_honoroit_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_bot_honoroit_database_engine == 'postgres'" - name: Ensure honoroit paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -37,10 +39,10 @@ - {path: "{{ matrix_bot_honoroit_data_path }}", when: true} - {path: "{{ matrix_bot_honoroit_data_store_path }}", when: true} - {path: "{{ matrix_bot_honoroit_docker_src_files_path }}", when: true} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure honoroit environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/env.j2" dest: "{{ matrix_bot_honoroit_config_path }}/env" owner: "{{ matrix_user_username }}" @@ -53,21 +55,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_bot_honoroit_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_bot_honoroit_docker_image_force_pull }}" - when: "not matrix_bot_honoroit_container_image_self_build|bool" + when: "not matrix_bot_honoroit_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure honoroit repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_bot_honoroit_docker_repo }}" + version: "{{ matrix_bot_honoroit_docker_repo_version }}" dest: "{{ matrix_bot_honoroit_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_bot_honoroit_git_pull_results - when: "matrix_bot_honoroit_container_image_self_build|bool" + when: "matrix_bot_honoroit_container_image_self_build | bool" - name: Ensure honoroit image is built docker_image: @@ -79,22 +82,22 @@ dockerfile: Dockerfile path: "{{ matrix_bot_honoroit_docker_src_files_path }}" pull: true - when: "matrix_bot_honoroit_container_image_self_build|bool" + when: "matrix_bot_honoroit_container_image_self_build | bool" - name: Ensure matrix-bot-honoroit.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-bot-honoroit.service.j2" dest: "{{ matrix_systemd_path }}/matrix-bot-honoroit.service" mode: 0644 register: matrix_bot_honoroit_systemd_service_result - name: Ensure systemd reloaded after matrix-bot-honoroit.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_honoroit_systemd_service_result.changed|bool" + when: "matrix_bot_honoroit_systemd_service_result.changed | bool" - name: Ensure matrix-bot-honoroit.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-bot-honoroit.service" state: restarted - when: "matrix_bot_honoroit_requires_restart|bool" + when: "matrix_bot_honoroit_requires_restart | bool" diff --git a/roles/matrix-bot-honoroit/tasks/setup_uninstall.yml b/roles/matrix-bot-honoroit/tasks/setup_uninstall.yml index 45bccabd8..6ede0d1d2 100644 --- a/roles/matrix-bot-honoroit/tasks/setup_uninstall.yml +++ b/roles/matrix-bot-honoroit/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-honoroit service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-bot-honoroit.service" register: matrix_bot_honoroit_service_stat - name: Ensure matrix-honoroit is stopped - service: + ansible.builtin.service: name: matrix-bot-honoroit state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_bot_honoroit_service_stat.stat.exists|bool" + when: "matrix_bot_honoroit_service_stat.stat.exists | bool" - name: Ensure matrix-bot-honoroit.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-bot-honoroit.service" state: absent - when: "matrix_bot_honoroit_service_stat.stat.exists|bool" + when: "matrix_bot_honoroit_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-bot-honoroit.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_honoroit_service_stat.stat.exists|bool" + when: "matrix_bot_honoroit_service_stat.stat.exists | bool" - name: Ensure Matrix honoroit paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_bot_honoroit_base_path }}" state: absent diff --git a/roles/matrix-bot-honoroit/tasks/validate_config.yml b/roles/matrix-bot-honoroit/tasks/validate_config.yml index 562bf9fba..0057e3c2c 100644 --- a/roles/matrix-bot-honoroit/tasks/validate_config.yml +++ b/roles/matrix-bot-honoroit/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bot-matrix-registration-bot/defaults/main.yml b/roles/matrix-bot-matrix-registration-bot/defaults/main.yml index 6cd0d15ae..d8e52b719 100644 --- a/roles/matrix-bot-matrix-registration-bot/defaults/main.yml +++ b/roles/matrix-bot-matrix-registration-bot/defaults/main.yml @@ -5,6 +5,7 @@ matrix_bot_matrix_registration_bot_enabled: true matrix_bot_matrix_registration_bot_container_image_self_build: false matrix_bot_matrix_registration_bot_docker_repo: "https://github.com/moan0s/matrix-registration-bot.git" +matrix_bot_matrix_registration_bot_docker_repo_version: "{{ matrix_bot_matrix_registration_bot_version if matrix_bot_matrix_registration_bot_version != 'latest' else 'main' }}" matrix_bot_matrix_registration_bot_docker_src_files_path: "{{ matrix_bot_matrix_registration_bot_base_path }}/docker-src" matrix_bot_matrix_registration_bot_version: latest diff --git a/roles/matrix-bot-matrix-registration-bot/tasks/init.yml b/roles/matrix-bot-matrix-registration-bot/tasks/init.yml index 03235b805..91b1f095d 100644 --- a/roles/matrix-bot-matrix-registration-bot/tasks/init.yml +++ b/roles/matrix-bot-matrix-registration-bot/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-matrix-registration-bot.service'] }}" - when: matrix_bot_matrix_registration_bot_enabled|bool + when: matrix_bot_matrix_registration_bot_enabled | bool diff --git a/roles/matrix-bot-matrix-registration-bot/tasks/main.yml b/roles/matrix-bot-matrix-registration-bot/tasks/main.yml index c90da6a8b..cc162e991 100644 --- a/roles/matrix-bot-matrix-registration-bot/tasks/main.yml +++ b/roles/matrix-bot-matrix-registration-bot/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_bot_matrix_registration_bot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_matrix_registration_bot_enabled | bool" tags: - setup-all - setup-bot-matrix-registration-bot -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_bot_matrix_registration_bot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_matrix_registration_bot_enabled | bool" tags: - setup-all - setup-bot-matrix-registration-bot -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_bot_matrix_registration_bot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_matrix_registration_bot_enabled | bool" tags: - setup-all - setup-bot-matrix-registration-bot diff --git a/roles/matrix-bot-matrix-registration-bot/tasks/setup_install.yml b/roles/matrix-bot-matrix-registration-bot/tasks/setup_install.yml index 716d67bc3..d4522321e 100644 --- a/roles/matrix-bot-matrix-registration-bot/tasks/setup_install.yml +++ b/roles/matrix-bot-matrix-registration-bot/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure matrix-registration-bot paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -11,10 +11,10 @@ - {path: "{{ matrix_bot_matrix_registration_bot_config_path }}", when: true} - - {path: "{{ matrix_bot_matrix_registration_bot_data_path }}", when: true} - {path: "{{ matrix_bot_matrix_registration_bot_docker_src_files_path }}", when: true} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure matrix-registration-bot configuration file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/config/config.yml.j2" dest: "{{ matrix_bot_matrix_registration_bot_config_path }}/config.yml" owner: "{{ matrix_user_username }}" @@ -27,21 +27,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_bot_matrix_registration_bot_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_bot_matrix_registration_bot_docker_image_force_pull }}" - when: "not matrix_bot_matrix_registration_bot_container_image_self_build|bool" + when: "not matrix_bot_matrix_registration_bot_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-registration-bot repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_bot_matrix_registration_bot_docker_repo }}" + version: "{{ matrix_bot_matrix_registration_bot_docker_repo_version }}" dest: "{{ matrix_bot_matrix_registration_bot_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_bot_matrix_registration_bot_git_pull_results - when: "matrix_bot_matrix_registration_bot_container_image_self_build|bool" + when: "matrix_bot_matrix_registration_bot_container_image_self_build | bool" - name: Ensure matrix-registration-bot image is built docker_image: @@ -53,21 +54,21 @@ dockerfile: Dockerfile path: "{{ matrix_bot_matrix_registration_bot_docker_src_files_path }}" pull: true - when: "matrix_bot_matrix_registration_bot_container_image_self_build|bool" + when: "matrix_bot_matrix_registration_bot_container_image_self_build | bool" - name: Ensure matrix-bot-matrix-registration-bot.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-bot-matrix-registration-bot.service.j2" dest: "{{ matrix_systemd_path }}/matrix-bot-matrix-registration-bot.service" mode: 0644 register: matrix_bot_matrix_registration_bot_systemd_service_result - name: Ensure systemd reloaded after matrix-bot-matrix-registration-bot.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_matrix_registration_bot_systemd_service_result.changed|bool" + when: "matrix_bot_matrix_registration_bot_systemd_service_result.changed | bool" - name: Ensure matrix-bot-matrix-registration-bot.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-bot-matrix-registration-bot.service" state: restarted diff --git a/roles/matrix-bot-matrix-registration-bot/tasks/setup_uninstall.yml b/roles/matrix-bot-matrix-registration-bot/tasks/setup_uninstall.yml index 9881592fe..426eefc10 100644 --- a/roles/matrix-bot-matrix-registration-bot/tasks/setup_uninstall.yml +++ b/roles/matrix-bot-matrix-registration-bot/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-matrix-registration-bot service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-bot-matrix-registration-bot.service" register: matrix_bot_matrix_registration_bot_service_stat - name: Ensure matrix-matrix-registration-bot is stopped - service: + ansible.builtin.service: name: matrix-bot-matrix-registration-bot state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_bot_matrix_registration_bot_service_stat.stat.exists|bool" + when: "matrix_bot_matrix_registration_bot_service_stat.stat.exists | bool" - name: Ensure matrix-bot-matrix-registration-bot.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-bot-matrix-registration-bot.service" state: absent - when: "matrix_bot_matrix_registration_bot_service_stat.stat.exists|bool" + when: "matrix_bot_matrix_registration_bot_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-bot-matrix-registration-bot.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_matrix_registration_bot_service_stat.stat.exists|bool" + when: "matrix_bot_matrix_registration_bot_service_stat.stat.exists | bool" - name: Ensure Matrix matrix-registration-bot paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_bot_matrix_registration_bot_base_path }}" state: absent diff --git a/roles/matrix-bot-matrix-registration-bot/tasks/validate_config.yml b/roles/matrix-bot-matrix-registration-bot/tasks/validate_config.yml index d5db028d7..39e97cde2 100644 --- a/roles/matrix-bot-matrix-registration-bot/tasks/validate_config.yml +++ b/roles/matrix-bot-matrix-registration-bot/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bot-matrix-reminder-bot/defaults/main.yml b/roles/matrix-bot-matrix-reminder-bot/defaults/main.yml index 48e6f07b4..610a43a32 100644 --- a/roles/matrix-bot-matrix-reminder-bot/defaults/main.yml +++ b/roles/matrix-bot-matrix-reminder-bot/defaults/main.yml @@ -6,6 +6,7 @@ matrix_bot_matrix_reminder_bot_enabled: true matrix_bot_matrix_reminder_bot_container_image_self_build: false matrix_bot_matrix_reminder_bot_docker_repo: "https://github.com/anoadragon453/matrix-reminder-bot.git" +matrix_bot_matrix_reminder_bot_docker_repo_version: "{{ matrix_bot_matrix_reminder_bot_version }}" matrix_bot_matrix_reminder_bot_docker_src_files_path: "{{ matrix_base_data_path }}/matrix-reminder-bot/docker-src" matrix_bot_matrix_reminder_bot_version: release-v0.2.1 @@ -93,8 +94,8 @@ matrix_bot_matrix_reminder_bot_configuration_extension_yaml: | # matrix: # device_name: My-Reminder-Bot -matrix_bot_matrix_reminder_bot_configuration_extension: "{{ matrix_bot_matrix_reminder_bot_configuration_extension_yaml|from_yaml if matrix_bot_matrix_reminder_bot_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_bot_matrix_reminder_bot_configuration_extension: "{{ matrix_bot_matrix_reminder_bot_configuration_extension_yaml | from_yaml if matrix_bot_matrix_reminder_bot_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_bot_matrix_reminder_bot_configuration_yaml`. -matrix_bot_matrix_reminder_bot_configuration: "{{ matrix_bot_matrix_reminder_bot_configuration_yaml|from_yaml|combine(matrix_bot_matrix_reminder_bot_configuration_extension, recursive=True) }}" +matrix_bot_matrix_reminder_bot_configuration: "{{ matrix_bot_matrix_reminder_bot_configuration_yaml | from_yaml | combine(matrix_bot_matrix_reminder_bot_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-bot-matrix-reminder-bot/tasks/init.yml b/roles/matrix-bot-matrix-reminder-bot/tasks/init.yml index 414969557..0a5ba4821 100644 --- a/roles/matrix-bot-matrix-reminder-bot/tasks/init.yml +++ b/roles/matrix-bot-matrix-reminder-bot/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-matrix-reminder-bot.service'] }}" - when: matrix_bot_matrix_reminder_bot_enabled|bool + when: matrix_bot_matrix_reminder_bot_enabled | bool diff --git a/roles/matrix-bot-matrix-reminder-bot/tasks/main.yml b/roles/matrix-bot-matrix-reminder-bot/tasks/main.yml index d9a1df7e4..19c3823fa 100644 --- a/roles/matrix-bot-matrix-reminder-bot/tasks/main.yml +++ b/roles/matrix-bot-matrix-reminder-bot/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_bot_matrix_reminder_bot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_matrix_reminder_bot_enabled | bool" tags: - setup-all - setup-bot-matrix-reminder-bot -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_bot_matrix_reminder_bot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_matrix_reminder_bot_enabled | bool" tags: - setup-all - setup-bot-matrix-reminder-bot -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_bot_matrix_reminder_bot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_matrix_reminder_bot_enabled | bool" tags: - setup-all - setup-bot-matrix-reminder-bot diff --git a/roles/matrix-bot-matrix-reminder-bot/tasks/setup_install.yml b/roles/matrix-bot-matrix-reminder-bot/tasks/setup_install.yml index d7f4706fb..0ad895af3 100644 --- a/roles/matrix-bot-matrix-reminder-bot/tasks/setup_install.yml +++ b/roles/matrix-bot-matrix-reminder-bot/tasks/setup_install.yml @@ -1,33 +1,35 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_bot_matrix_reminder_bot_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_bot_matrix_reminder_bot_sqlite_database_path_local }}" register: matrix_bot_matrix_reminder_bot_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_bot_matrix_reminder_bot_sqlite_database_path_local }}" dst: "{{ matrix_bot_matrix_reminder_bot_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_bot_matrix_reminder_bot_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-bot-matrix-reminder-bot.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_bot_matrix_reminder_bot_requires_restart: true - when: "matrix_bot_matrix_reminder_bot_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_bot_matrix_reminder_bot_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_bot_matrix_reminder_bot_database_engine == 'postgres'" - name: Ensure matrix-reminder-bot paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -38,7 +40,7 @@ - {path: "{{ matrix_bot_matrix_reminder_bot_data_path }}", when: true} - {path: "{{ matrix_bot_matrix_reminder_bot_data_store_path }}", when: true} - {path: "{{ matrix_bot_matrix_reminder_bot_docker_src_files_path }}", when: true} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure matrix-reminder-bot image is pulled docker_image: @@ -46,21 +48,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_bot_matrix_reminder_bot_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_bot_matrix_reminder_bot_docker_image_force_pull }}" - when: "not matrix_bot_matrix_reminder_bot_container_image_self_build|bool" + when: "not matrix_bot_matrix_reminder_bot_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-reminder-bot repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_bot_matrix_reminder_bot_docker_repo }}" + version: "{{ matrix_bot_matrix_reminder_bot_docker_repo_version }}" dest: "{{ matrix_bot_matrix_reminder_bot_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_bot_matrix_reminder_bot_git_pull_results - when: "matrix_bot_matrix_reminder_bot_container_image_self_build|bool" + when: "matrix_bot_matrix_reminder_bot_container_image_self_build | bool" - name: Ensure matrix-reminder-bot image is built docker_image: @@ -72,30 +75,30 @@ dockerfile: docker/Dockerfile path: "{{ matrix_bot_matrix_reminder_bot_docker_src_files_path }}" pull: true - when: "matrix_bot_matrix_reminder_bot_container_image_self_build|bool" + when: "matrix_bot_matrix_reminder_bot_container_image_self_build | bool" - name: Ensure matrix-reminder-bot config installed - copy: - content: "{{ matrix_bot_matrix_reminder_bot_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_bot_matrix_reminder_bot_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_bot_matrix_reminder_bot_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-bot-matrix-reminder-bot.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-bot-matrix-reminder-bot.service.j2" dest: "{{ matrix_systemd_path }}/matrix-bot-matrix-reminder-bot.service" mode: 0644 register: matrix_bot_matrix_reminder_bot_systemd_service_result - name: Ensure systemd reloaded after matrix-bot-matrix-reminder-bot.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_matrix_reminder_bot_systemd_service_result.changed|bool" + when: "matrix_bot_matrix_reminder_bot_systemd_service_result.changed | bool" - name: Ensure matrix-bot-matrix-reminder-bot.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-bot-matrix-reminder-bot.service" state: restarted - when: "matrix_bot_matrix_reminder_bot_requires_restart|bool" + when: "matrix_bot_matrix_reminder_bot_requires_restart | bool" diff --git a/roles/matrix-bot-matrix-reminder-bot/tasks/setup_uninstall.yml b/roles/matrix-bot-matrix-reminder-bot/tasks/setup_uninstall.yml index eb7543c59..d8926df75 100644 --- a/roles/matrix-bot-matrix-reminder-bot/tasks/setup_uninstall.yml +++ b/roles/matrix-bot-matrix-reminder-bot/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-matrix-reminder-bot service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-bot-matrix-reminder-bot.service" register: matrix_bot_matrix_reminder_bot_service_stat - name: Ensure matrix-matrix-reminder-bot is stopped - service: + ansible.builtin.service: name: matrix-bot-matrix-reminder-bot state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists|bool" + when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists | bool" - name: Ensure matrix-bot-matrix-reminder-bot.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-bot-matrix-reminder-bot.service" state: absent - when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists|bool" + when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-bot-matrix-reminder-bot.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists|bool" + when: "matrix_bot_matrix_reminder_bot_service_stat.stat.exists | bool" - name: Ensure Matrix matrix-reminder-bot paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_bot_matrix_reminder_bot_base_path }}" state: absent diff --git a/roles/matrix-bot-matrix-reminder-bot/tasks/validate_config.yml b/roles/matrix-bot-matrix-reminder-bot/tasks/validate_config.yml index 8963a3125..54f38dd51 100644 --- a/roles/matrix-bot-matrix-reminder-bot/tasks/validate_config.yml +++ b/roles/matrix-bot-matrix-reminder-bot/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -10,7 +10,7 @@ - "matrix_bot_matrix_reminder_bot_reminders_timezone" - name: (Deprecation) Catch and report renamed settings - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-bot-mjolnir/defaults/main.yml b/roles/matrix-bot-mjolnir/defaults/main.yml index 94d04e782..0be97eaec 100644 --- a/roles/matrix-bot-mjolnir/defaults/main.yml +++ b/roles/matrix-bot-mjolnir/defaults/main.yml @@ -52,8 +52,8 @@ matrix_bot_mjolnir_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_bot_mjolnir_configuration_yaml`. -matrix_bot_mjolnir_configuration_extension: "{{ matrix_bot_mjolnir_configuration_extension_yaml|from_yaml if matrix_bot_mjolnir_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_bot_mjolnir_configuration_extension: "{{ matrix_bot_mjolnir_configuration_extension_yaml | from_yaml if matrix_bot_mjolnir_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_bot_mjolnir_configuration_yaml`. -matrix_bot_mjolnir_configuration: "{{ matrix_bot_mjolnir_configuration_yaml|from_yaml|combine(matrix_bot_mjolnir_configuration_extension, recursive=True) }}" +matrix_bot_mjolnir_configuration: "{{ matrix_bot_mjolnir_configuration_yaml | from_yaml | combine(matrix_bot_mjolnir_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-bot-mjolnir/tasks/init.yml b/roles/matrix-bot-mjolnir/tasks/init.yml index e09964ecd..2b6053428 100644 --- a/roles/matrix-bot-mjolnir/tasks/init.yml +++ b/roles/matrix-bot-mjolnir/tasks/init.yml @@ -2,10 +2,10 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Mjolnir 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_bot_mjolnir_container_image_self_build and matrix_bot_mjolnir_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-bot-mjolnir.service'] }}" - when: matrix_bot_mjolnir_enabled|bool + when: matrix_bot_mjolnir_enabled | bool diff --git a/roles/matrix-bot-mjolnir/tasks/main.yml b/roles/matrix-bot-mjolnir/tasks/main.yml index a2a209147..867201a20 100644 --- a/roles/matrix-bot-mjolnir/tasks/main.yml +++ b/roles/matrix-bot-mjolnir/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_bot_mjolnir_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_bot_mjolnir_enabled | bool" tags: - setup-all - setup-bot-mjolnir -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_bot_mjolnir_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_bot_mjolnir_enabled | bool" tags: - setup-all - setup-bot-mjolnir -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_bot_mjolnir_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_bot_mjolnir_enabled | bool" tags: - setup-all - setup-bot-mjolnir diff --git a/roles/matrix-bot-mjolnir/tasks/setup_install.yml b/roles/matrix-bot-mjolnir/tasks/setup_install.yml index 66f2806a8..08ac9d034 100644 --- a/roles/matrix-bot-mjolnir/tasks/setup_install.yml +++ b/roles/matrix-bot-mjolnir/tasks/setup_install.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_bot_mjolnir_requires_restart: false - name: Ensure matrix-bot-mjolnir paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -15,7 +15,7 @@ - {path: "{{ matrix_bot_mjolnir_config_path }}", when: true} - {path: "{{ matrix_bot_mjolnir_data_path }}", when: true} - {path: "{{ matrix_bot_mjolnir_docker_src_files_path }}", when: "{{ matrix_bot_mjolnir_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure mjolnir Docker image is pulled docker_image: @@ -23,14 +23,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_bot_mjolnir_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_bot_mjolnir_docker_image_force_pull }}" - when: "not matrix_bot_mjolnir_container_image_self_build|bool" + when: "not matrix_bot_mjolnir_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure mjolnir repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_bot_mjolnir_container_image_self_build_repo }}" dest: "{{ matrix_bot_mjolnir_docker_src_files_path }}" version: "{{ matrix_bot_mjolnir_docker_image.split(':')[1] }}" @@ -38,7 +38,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_bot_mjolnir_git_pull_results - when: "matrix_bot_mjolnir_container_image_self_build|bool" + when: "matrix_bot_mjolnir_container_image_self_build | bool" - name: Ensure mjolnir Docker image is built docker_image: @@ -49,30 +49,30 @@ dockerfile: Dockerfile path: "{{ matrix_bot_mjolnir_docker_src_files_path }}" pull: true - when: "matrix_bot_mjolnir_container_image_self_build|bool" + when: "matrix_bot_mjolnir_container_image_self_build | bool" - name: Ensure matrix-bot-mjolnir config installed - copy: - content: "{{ matrix_bot_mjolnir_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_bot_mjolnir_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_bot_mjolnir_config_path }}/production.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-bot-mjolnir.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-bot-mjolnir.service.j2" dest: "{{ matrix_systemd_path }}/matrix-bot-mjolnir.service" mode: 0644 register: matrix_bot_mjolnir_systemd_service_result - name: Ensure systemd reloaded after matrix-bot-mjolnir.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_mjolnir_systemd_service_result.changed|bool" + when: "matrix_bot_mjolnir_systemd_service_result.changed | bool" - name: Ensure matrix-bot-mjolnir.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-bot-mjolnir.service" state: restarted - when: "matrix_bot_mjolnir_requires_restart|bool" + when: "matrix_bot_mjolnir_requires_restart | bool" diff --git a/roles/matrix-bot-mjolnir/tasks/setup_uninstall.yml b/roles/matrix-bot-mjolnir/tasks/setup_uninstall.yml index 935859778..5c7f4c896 100644 --- a/roles/matrix-bot-mjolnir/tasks/setup_uninstall.yml +++ b/roles/matrix-bot-mjolnir/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-bot-mjolnir service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-bot-mjolnir.service" register: matrix_bot_mjolnir_service_stat - name: Ensure matrix-bot-mjolnir is stopped - service: + ansible.builtin.service: name: matrix-bot-mjolnir state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_bot_mjolnir_service_stat.stat.exists|bool" + when: "matrix_bot_mjolnir_service_stat.stat.exists | bool" - name: Ensure matrix-bot-mjolnir.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-bot-mjolnir.service" state: absent - when: "matrix_bot_mjolnir_service_stat.stat.exists|bool" + when: "matrix_bot_mjolnir_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-bot-mjolnir.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_bot_mjolnir_service_stat.stat.exists|bool" + when: "matrix_bot_mjolnir_service_stat.stat.exists | bool" - name: Ensure matrix-bot-mjolnir paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_bot_mjolnir_base_path }}" state: absent diff --git a/roles/matrix-bot-mjolnir/tasks/validate_config.yml b/roles/matrix-bot-mjolnir/tasks/validate_config.yml index cb961baf3..63289d7ba 100644 --- a/roles/matrix-bot-mjolnir/tasks/validate_config.yml +++ b/roles/matrix-bot-mjolnir/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required variables are undefined - fail: + ansible.builtin.fail: msg: "The `{{ item }}` variable must be defined and have a non-null value." with_items: - "matrix_bot_mjolnir_access_token" diff --git a/roles/matrix-bridge-appservice-discord/defaults/main.yml b/roles/matrix-bridge-appservice-discord/defaults/main.yml index f3e39f24f..9f6109ed5 100644 --- a/roles/matrix-bridge-appservice-discord/defaults/main.yml +++ b/roles/matrix-bridge-appservice-discord/defaults/main.yml @@ -39,10 +39,10 @@ matrix_appservice_discord_appservice_url: 'http://matrix-appservice-discord:9005 matrix_appservice_discord_bridge_domain: "{{ matrix_domain }}" # As of right now, the homeserver URL must be a public URL. See below. -matrix_appservice_discord_bridge_homeserverUrl: "{{ matrix_homeserver_url }}" -matrix_appservice_discord_bridge_disablePresence: false -matrix_appservice_discord_bridge_enableSelfServiceBridging: false -matrix_appservice_discord_bridge_disablePortalBridging: false +matrix_appservice_discord_bridge_homeserverUrl: "{{ matrix_homeserver_url }}" # noqa var-naming +matrix_appservice_discord_bridge_disablePresence: false # noqa var-naming +matrix_appservice_discord_bridge_enableSelfServiceBridging: false # noqa var-naming +matrix_appservice_discord_bridge_disablePortalBridging: false # noqa var-naming # Database-related configuration fields. # @@ -65,7 +65,7 @@ matrix_appservice_discord_database_name: 'matrix_appservice_discord' # These 2 variables are what actually ends up in the bridge configuration. # It's best if you don't change them directly, but rather redefine the sub-variables that constitute them. matrix_appservice_discord_database_filename: "{{ matrix_appservice_discord_sqlite_database_path_in_container }}" -matrix_appservice_discord_database_connString: 'postgresql://{{ matrix_appservice_discord_database_username }}:{{ matrix_appservice_discord_database_password }}@{{ matrix_appservice_discord_database_hostname }}:{{ matrix_appservice_discord_database_port }}/{{ matrix_appservice_discord_database_name }}' +matrix_appservice_discord_database_connString: 'postgresql://{{ matrix_appservice_discord_database_username }}:{{ matrix_appservice_discord_database_password }}@{{ matrix_appservice_discord_database_hostname }}:{{ matrix_appservice_discord_database_port }}/{{ matrix_appservice_discord_database_name }}' # noqa var-naming # Tells whether the bot should make use of "Privileged Gateway Intents". @@ -74,7 +74,7 @@ matrix_appservice_discord_database_connString: 'postgresql://{{ matrix_appservic # by triggering all Intent checkboxes on a page like this: `https://discord.com/developers/applications/694448564151123988/bot` # # Learn more: https://gist.github.com/advaith1/e69bcc1cdd6d0087322734451f15aa2f -matrix_appservice_discord_auth_usePrivilegedIntents: false +matrix_appservice_discord_auth_usePrivilegedIntents: false # noqa var-naming matrix_appservice_discord_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}" @@ -87,9 +87,9 @@ matrix_appservice_discord_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_appservice_discord_configuration_yaml`. -matrix_appservice_discord_configuration_extension: "{{ matrix_appservice_discord_configuration_extension_yaml|from_yaml if matrix_appservice_discord_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_appservice_discord_configuration_extension: "{{ matrix_appservice_discord_configuration_extension_yaml | from_yaml if matrix_appservice_discord_configuration_extension_yaml | from_yaml is mapping else {} }}" -matrix_appservice_discord_configuration: "{{ matrix_appservice_discord_configuration_yaml|from_yaml|combine(matrix_appservice_discord_configuration_extension, recursive=True) }}" +matrix_appservice_discord_configuration: "{{ matrix_appservice_discord_configuration_yaml | from_yaml | combine(matrix_appservice_discord_configuration_extension, recursive=True) }}" matrix_appservice_discord_registration_yaml: | #jinja2: lstrip_blocks: "True" @@ -99,14 +99,14 @@ matrix_appservice_discord_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_discord_.*:{{ matrix_appservice_discord_homeserver_domain|regex_escape }}' + regex: '@_discord_.*:{{ matrix_appservice_discord_homeserver_domain | regex_escape }}' aliases: - exclusive: true - regex: '#_discord_.*:{{ matrix_appservice_discord_homeserver_domain|regex_escape }}' + regex: '#_discord_.*:{{ matrix_appservice_discord_homeserver_domain | regex_escape }}' url: {{ matrix_appservice_discord_appservice_url }} sender_localpart: _discord_bot rate_limited: false protocols: - discord -matrix_appservice_discord_registration: "{{ matrix_appservice_discord_registration_yaml|from_yaml }}" +matrix_appservice_discord_registration: "{{ matrix_appservice_discord_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-appservice-discord/tasks/init.yml b/roles/matrix-bridge-appservice-discord/tasks/init.yml index a53112ad7..b9d875dae 100644 --- a/roles/matrix-bridge-appservice-discord/tasks/init.yml +++ b/roles/matrix-bridge-appservice-discord/tasks/init.yml @@ -2,28 +2,28 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-appservice-discord role needs to execute before the matrix-synapse role. - when: "matrix_appservice_discord_enabled and matrix_synapse_role_executed|default(False)" + when: "matrix_appservice_discord_enabled and matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-appservice-discord.service'] }}" - when: matrix_appservice_discord_enabled|bool + when: matrix_appservice_discord_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_appservice_discord_config_path }}/registration.yaml,dst=/matrix-appservice-discord-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-appservice-discord-registration.yaml"] }} - when: matrix_appservice_discord_enabled|bool + when: matrix_appservice_discord_enabled | bool diff --git a/roles/matrix-bridge-appservice-discord/tasks/main.yml b/roles/matrix-bridge-appservice-discord/tasks/main.yml index 5df7bfe2b..7ab8f3a65 100644 --- a/roles/matrix-bridge-appservice-discord/tasks/main.yml +++ b/roles/matrix-bridge-appservice-discord/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_appservice_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_appservice_discord_enabled | bool" tags: - setup-all - setup-appservice-discord -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_appservice_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_appservice_discord_enabled | bool" tags: - setup-all - setup-appservice-discord -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_appservice_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_appservice_discord_enabled | bool" tags: - setup-all - setup-appservice-discord diff --git a/roles/matrix-bridge-appservice-discord/tasks/setup_install.yml b/roles/matrix-bridge-appservice-discord/tasks/setup_install.yml index a06d38aca..af17613c6 100644 --- a/roles/matrix-bridge-appservice-discord/tasks/setup_install.yml +++ b/roles/matrix-bridge-appservice-discord/tasks/setup_install.yml @@ -1,29 +1,31 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_appservice_discord_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_discord_sqlite_database_path_local }}" register: matrix_appservice_discord_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_appservice_discord_sqlite_database_path_local }}" dst: "{{ matrix_appservice_discord_database_connString }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_appservice_discord_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-appservice-discord.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_appservice_discord_requires_restart: true - when: "matrix_appservice_discord_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_appservice_discord_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_appservice_discord_database_engine == 'postgres'" - name: Ensure Appservice Discord image is pulled @@ -38,7 +40,7 @@ until: result is not failed - name: Ensure AppService Discord paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -50,12 +52,12 @@ - "{{ matrix_appservice_discord_data_path }}" - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_discord_base_path }}/discord.db" register: matrix_appservice_discord_stat_db - name: (Data relocation) Ensure matrix-appservice-discord.service is stopped - service: + ansible.builtin.service: name: matrix-appservice-discord state: stopped enabled: false @@ -64,7 +66,7 @@ when: "matrix_appservice_discord_stat_db.stat.exists" - name: (Data relocation) Move AppService Discord discord.db file to ./data directory - command: "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}" + ansible.builtin.command: "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}" with_items: - discord.db - user-store.db @@ -72,16 +74,16 @@ when: "matrix_appservice_discord_stat_db.stat.exists" - name: Ensure AppService Discord config.yaml installed - copy: - content: "{{ matrix_appservice_discord_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_discord_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_discord_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure AppService Discord registration.yaml installed - copy: - content: "{{ matrix_appservice_discord_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_discord_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_discord_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" @@ -90,7 +92,7 @@ # If `matrix_appservice_discord_client_id` hasn't changed, the same invite link would be generated. # We intentionally suppress Ansible changes. - name: Generate AppService Discord invite link - shell: >- + ansible.builtin.shell: >- {{ matrix_host_command_docker }} run --rm --name matrix-appservice-discord-link-gen --user={{ matrix_user_uid }}:{{ matrix_user_gid }} --cap-drop=ALL @@ -101,19 +103,19 @@ changed_when: false - name: Ensure matrix-appservice-discord.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2" dest: "{{ matrix_systemd_path }}/matrix-appservice-discord.service" mode: 0644 register: matrix_appservice_discord_systemd_service_result - name: Ensure systemd reloaded after matrix-appservice-discord.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_discord_systemd_service_result.changed" - name: Ensure matrix-appservice-discord.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-appservice-discord.service" state: restarted - when: "matrix_appservice_discord_requires_restart|bool" + when: "matrix_appservice_discord_requires_restart | bool" diff --git a/roles/matrix-bridge-appservice-discord/tasks/setup_uninstall.yml b/roles/matrix-bridge-appservice-discord/tasks/setup_uninstall.yml index ab56c26b6..83588d1c1 100644 --- a/roles/matrix-bridge-appservice-discord/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-appservice-discord/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-appservice-discord service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-appservice-discord.service" register: matrix_appservice_discord_service_stat - name: Ensure matrix-appservice-discord is stopped - service: + ansible.builtin.service: name: matrix-appservice-discord state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_appservice_discord_service_stat.stat.exists" - name: Ensure matrix-appservice-discord.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-appservice-discord.service" state: absent when: "matrix_appservice_discord_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-appservice-discord.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_discord_service_stat.stat.exists" diff --git a/roles/matrix-bridge-appservice-discord/tasks/validate_config.yml b/roles/matrix-bridge-appservice-discord/tasks/validate_config.yml index 73253ba03..901b760bf 100644 --- a/roles/matrix-bridge-appservice-discord/tasks/validate_config.yml +++ b/roles/matrix-bridge-appservice-discord/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -13,7 +13,7 @@ - "matrix_appservice_discord_homeserver_domain" - name: (Deprecation) Catch and report renamed appservice-discord variables - fail: + ansible.builtin.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 }}`). @@ -22,5 +22,5 @@ - {'old': 'matrix_appservice_discord_container_expose_client_server_api_port', 'new': ''} - name: Require a valid database engine - fail: msg="`matrix_appservice_discord_database_engine` needs to be either 'sqlite' or 'postgres'" + ansible.builtin.fail: msg="`matrix_appservice_discord_database_engine` needs to be either 'sqlite' or 'postgres'" when: "matrix_appservice_discord_database_engine not in ['sqlite', 'postgres']" diff --git a/roles/matrix-bridge-appservice-discord/templates/config.yaml.j2 b/roles/matrix-bridge-appservice-discord/templates/config.yaml.j2 index 569a30304..a530af2e5 100644 --- a/roles/matrix-bridge-appservice-discord/templates/config.yaml.j2 +++ b/roles/matrix-bridge-appservice-discord/templates/config.yaml.j2 @@ -34,7 +34,7 @@ bridge: determineCodeLanguage: false # Authentication configuration for the discord bot. auth: - clientID: {{ matrix_appservice_discord_client_id|string|to_json }} + clientID: {{ matrix_appservice_discord_client_id | string|to_json }} botToken: {{ matrix_appservice_discord_bot_token|to_json }} # You must enable "Privileged Gateway Intents" in your bot settings on discord.com (e.g. https://discord.com/developers/applications/12345/bot) # for this to work diff --git a/roles/matrix-bridge-appservice-irc/defaults/main.yml b/roles/matrix-bridge-appservice-irc/defaults/main.yml index 52554f61b..93a8e0844 100644 --- a/roles/matrix-bridge-appservice-irc/defaults/main.yml +++ b/roles/matrix-bridge-appservice-irc/defaults/main.yml @@ -6,10 +6,14 @@ matrix_appservice_irc_enabled: true matrix_appservice_irc_container_image_self_build: false matrix_appservice_irc_docker_repo: "https://github.com/matrix-org/matrix-appservice-irc.git" +matrix_appservice_irc_docker_repo_version: "{{ 'master' if matrix_appservice_irc_version == 'latest' else matrix_appservice_irc_version }}" matrix_appservice_irc_docker_src_files_path: "{{ matrix_base_data_path }}/appservice-irc/docker-src" -matrix_appservice_irc_version: release-0.34.0 -matrix_appservice_irc_docker_image: "{{ matrix_container_global_registry_prefix }}matrixdotorg/matrix-appservice-irc:{{ matrix_appservice_irc_version }}" +# matrix_appservice_irc_version used to contain the full Docker image tag (e.g. `release-X.X.X`). +# It's a bare version number now. We try to somewhat retain compatibility below. +matrix_appservice_irc_version: 0.34.0 +matrix_appservice_irc_docker_image: "{{ matrix_container_global_registry_prefix }}matrixdotorg/matrix-appservice-irc:{{ matrix_appservice_irc_docker_image_tag }}" +matrix_appservice_irc_docker_image_tag: "{{ 'latest' if matrix_appservice_irc_version == 'latest' else ('release-' + matrix_appservice_irc_version) }}" matrix_appservice_irc_docker_image_force_pull: "{{ matrix_appservice_irc_docker_image.endswith(':latest') }}" matrix_appservice_irc_base_path: "{{ matrix_base_data_path }}/appservice-irc" @@ -19,7 +23,7 @@ matrix_appservice_irc_data_path: "{{ matrix_appservice_irc_base_path }}/data" matrix_appservice_irc_homeserver_url: "{{ matrix_homeserver_container_url }}" matrix_appservice_irc_homeserver_media_url: 'https://{{ matrix_server_fqn_matrix }}' matrix_appservice_irc_homeserver_domain: '{{ matrix_domain }}' -matrix_appservice_irc_homeserver_enablePresence: true +matrix_appservice_irc_homeserver_enablePresence: true # noqa var-naming matrix_appservice_irc_appservice_address: 'http://matrix-appservice-irc:9999' matrix_appservice_irc_database_engine: nedb @@ -34,14 +38,15 @@ matrix_appservice_irc_database_name: matrix_appservice_irc matrix_appservice_irc_database_connection_string: 'postgresql://{{ matrix_appservice_irc_database_username }}:{{ matrix_appservice_irc_database_password }}@{{ matrix_appservice_irc_database_hostname }}:{{ matrix_appservice_irc_database_port }}/{{ matrix_appservice_irc_database_name }}?sslmode=disable' # This is what actually goes into `database.connectionString` for the bridge. -matrix_appservice_irc_database_connectionString: "{{ - { - 'nedb': 'nedb:///data', - 'postgres': matrix_appservice_irc_database_connection_string, - }[matrix_appservice_irc_database_engine] -}}" +matrix_appservice_irc_database_connectionString: |- # noqa var-naming + {{ + { + 'nedb': 'nedb:///data', + 'postgres': matrix_appservice_irc_database_connection_string, + }[matrix_appservice_irc_database_engine] + }} -matrix_appservice_irc_ircService_servers: [] +matrix_appservice_irc_ircService_servers: [] # noqa var-naming # Example of `matrix_appservice_irc_ircService_servers` with one server (and all its options): # @@ -382,9 +387,9 @@ matrix_appservice_irc_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_appservice_irc_configuration_yaml`. -matrix_appservice_irc_configuration_extension: "{{ matrix_appservice_irc_configuration_extension_yaml|from_yaml if matrix_appservice_irc_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_appservice_irc_configuration_extension: "{{ matrix_appservice_irc_configuration_extension_yaml | from_yaml if matrix_appservice_irc_configuration_extension_yaml | from_yaml is mapping else {} }}" -matrix_appservice_irc_configuration: "{{ matrix_appservice_irc_configuration_yaml|from_yaml|combine(matrix_appservice_irc_configuration_extension, recursive=True) }}" +matrix_appservice_irc_configuration: "{{ matrix_appservice_irc_configuration_yaml | from_yaml | combine(matrix_appservice_irc_configuration_extension, recursive=True) }}" # The original registration.yaml file generated by AppService IRC is merged with this config override, # to produce the final registration.yaml file ultimately used by both the bridge and the homeserver. @@ -399,4 +404,4 @@ matrix_appservice_irc_registration_override_yaml: | as_token: "{{ matrix_appservice_irc_appservice_token }}" hs_token: "{{ matrix_appservice_irc_homeserver_token }}" -matrix_appservice_irc_registration_override: "{{ matrix_appservice_irc_registration_override_yaml|from_yaml }}" +matrix_appservice_irc_registration_override: "{{ matrix_appservice_irc_registration_override_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-appservice-irc/tasks/init.yml b/roles/matrix-bridge-appservice-irc/tasks/init.yml index a35144f05..d22dd5d71 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/init.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/init.yml @@ -2,35 +2,35 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_appservice_irc_container_image_self_build and matrix_appservice_irc_enabled" # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-appservice-irc role needs to execute before the matrix-synapse role. - when: "matrix_appservice_irc_enabled|bool and matrix_synapse_role_executed|default(False)" + when: "matrix_appservice_irc_enabled | bool and matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-appservice-irc.service'] }}" - when: matrix_appservice_irc_enabled|bool + when: matrix_appservice_irc_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_appservice_irc_config_path }}/registration.yaml,dst=/matrix-appservice-irc-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-appservice-irc-registration.yaml"] }} - when: matrix_appservice_irc_enabled|bool + when: matrix_appservice_irc_enabled | bool diff --git a/roles/matrix-bridge-appservice-irc/tasks/main.yml b/roles/matrix-bridge-appservice-irc/tasks/main.yml index 339615eab..41d2017b0 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/main.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_appservice_irc_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_appservice_irc_enabled | bool" tags: - setup-all - setup-appservice-irc -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_appservice_irc_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_appservice_irc_enabled | bool" tags: - setup-all - setup-appservice-irc -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_appservice_irc_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_appservice_irc_enabled | bool" tags: - setup-all - setup-appservice-irc diff --git a/roles/matrix-bridge-appservice-irc/tasks/migrate_nedb_to_postgres.yml b/roles/matrix-bridge-appservice-irc/tasks/migrate_nedb_to_postgres.yml index d7fcaa07b..d5f4eefd3 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/migrate_nedb_to_postgres.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/migrate_nedb_to_postgres.yml @@ -1,46 +1,46 @@ --- - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" # Actual import work - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true register: matrix_postgres_service_start_result - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false - when: "matrix_postgres_service_start_result.changed|bool" + when: "matrix_postgres_service_start_result.changed | bool" - name: Check existence of matrix-appservice-irc service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-appservice-irc.service" register: matrix_appservice_irc_service_stat - name: Ensure matrix-appservice-irc is stopped - service: + ansible.builtin.service: name: matrix-appservice-irc state: stopped when: "matrix_appservice_irc_service_stat.stat.exists" - name: Import appservice-irc NeDB database into Postgres - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -52,19 +52,23 @@ {{ matrix_appservice_irc_docker_image }} -c '/usr/local/bin/node /app/lib/scripts/migrate-db-to-pgres.js --dbdir /data --privateKey /data/passkey.pem --connectionString {{ matrix_appservice_irc_database_connection_string }}' + register: matrix_appservice_irc_import_nedb_to_postgres_result + changed_when: matrix_appservice_irc_import_nedb_to_postgres_result.rc == 0 - name: Archive NeDB database files - command: + ansible.builtin.command: cmd: "mv {{ matrix_appservice_irc_data_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}.backup" with_items: - rooms.db - users.db + register: matrix_appservice_irc_import_nedb_to_postgres_move_result + changed_when: matrix_appservice_irc_import_nedb_to_postgres_move_result.rc == 0 - name: Inject result - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your appservice-irc database files have been imported into Postgres. The original database files have been moved from `{{ matrix_appservice_irc_data_path }}/*.db` to `{{ matrix_appservice_irc_data_path }}/*.db.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete these files." diff --git a/roles/matrix-bridge-appservice-irc/tasks/setup_install.yml b/roles/matrix-bridge-appservice-irc/tasks/setup_install.yml index 1ae0b3fa3..6b7fc92d9 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/setup_install.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/setup_install.yml @@ -1,9 +1,9 @@ --- -- import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" - name: Ensure Appservice IRC paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -14,47 +14,53 @@ - {path: "{{ matrix_appservice_irc_config_path }}", when: true} - {path: "{{ matrix_appservice_irc_data_path }}", when: true} - {path: "{{ matrix_appservice_irc_docker_src_files_path }}", when: "{{ matrix_appservice_irc_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Check if an old passkey file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_irc_base_path }}/passkey.pem" register: matrix_appservice_irc_stat_passkey - block: - name: (Data relocation) Ensure matrix-appservice-irc.service is stopped - service: + ansible.builtin.service: name: matrix-appservice-irc state: stopped daemon_reload: true failed_when: false - name: (Data relocation) Move AppService IRC passkey.pem file to ./data directory - command: "mv {{ matrix_appservice_irc_base_path }}/passkey.pem {{ matrix_appservice_irc_data_path }}/passkey.pem" + ansible.builtin.command: + cmd: "mv {{ matrix_appservice_irc_base_path }}/passkey.pem {{ matrix_appservice_irc_data_path }}/passkey.pem" + register: matrix_appservice_irc_move_passkey_result + changed_when: matrix_appservice_irc_move_passkey_result.rc == 0 - name: (Data relocation) Move AppService IRC database files to ./data directory - command: "mv {{ matrix_appservice_irc_base_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}" + ansible.builtin.command: + cmd: "mv {{ matrix_appservice_irc_base_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}" + register: matrix_appservice_irc_move_dbs_result + changed_when: matrix_appservice_irc_move_dbs_result.rc == 0 with_items: - rooms.db - users.db failed_when: false when: "matrix_appservice_irc_stat_passkey.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_appservice_irc_requires_restart: false - block: - name: Check if a nedb database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_irc_data_path }}/users.db" register: matrix_appservice_irc_nedb_database_path_local_stat_result - block: - - import_tasks: "{{ role_path }}/tasks/migrate_nedb_to_postgres.yml" + - ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_nedb_to_postgres.yml" - - set_fact: + - ansible.builtin.set_fact: matrix_appservice_irc_requires_restart: true - when: "matrix_appservice_irc_nedb_database_path_local_stat_result.stat.exists|bool" + when: "matrix_appservice_irc_nedb_database_path_local_stat_result.stat.exists | bool" when: "matrix_appservice_irc_database_engine == 'postgres'" - name: Ensure Appservice IRC image is pulled @@ -63,21 +69,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_appservice_irc_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_appservice_irc_docker_image_force_pull }}" - when: "matrix_appservice_irc_enabled|bool and not matrix_appservice_irc_container_image_self_build|bool" + when: "matrix_appservice_irc_enabled | bool and not matrix_appservice_irc_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-appservice-irc repository is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_appservice_irc_docker_repo }}" + version: "{{ matrix_appservice_irc_docker_repo_version }}" dest: "{{ matrix_appservice_irc_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_appservice_irc_git_pull_results - when: "matrix_appservice_irc_enabled|bool and matrix_appservice_irc_container_image_self_build|bool" + when: "matrix_appservice_irc_enabled | bool and matrix_appservice_irc_container_image_self_build | bool" - name: Ensure matrix-appservice-irc Docker image is built docker_image: @@ -89,23 +96,23 @@ dockerfile: Dockerfile path: "{{ matrix_appservice_irc_docker_src_files_path }}" pull: true - when: "matrix_appservice_irc_enabled|bool and matrix_appservice_irc_container_image_self_build|bool and matrix_appservice_irc_git_pull_results.changed" + when: "matrix_appservice_irc_enabled | bool and matrix_appservice_irc_container_image_self_build | bool and matrix_appservice_irc_git_pull_results.changed" - name: Ensure Matrix Appservice IRC config installed - copy: - content: "{{ matrix_appservice_irc_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_irc_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_irc_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Check if Appservice IRC passkey exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_irc_data_path }}/passkey.pem" register: irc_passkey_file - name: Generate Appservice IRC passkey if it doesn't exist - shell: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_appservice_irc_data_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:2048" + ansible.builtin.shell: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_appservice_irc_data_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:2048" become: true become_user: "{{ matrix_user_username }}" when: "not irc_passkey_file.stat.exists" @@ -113,7 +120,7 @@ # In the past, we used to generate the passkey.pem file with root, so permissions may not be okay. # Fix it. - name: (Migration) Ensure Appservice IRC passkey permissions are okay - file: + ansible.builtin.file: path: "{{ matrix_appservice_irc_data_path }}/passkey.pem" mode: 0644 owner: "{{ matrix_user_username }}" @@ -139,7 +146,7 @@ # an up-to-date file, and we fix it up with some static values later on, # to produce a final registration.yaml file, as we desire. - name: Generate Appservice IRC registration-template.yaml - shell: >- + ansible.builtin.shell: >- {{ matrix_host_command_docker }} run --rm --name matrix-appservice-irc-gen --user={{ matrix_user_uid }}:{{ matrix_user_gid }} --cap-drop=ALL @@ -157,46 +164,46 @@ changed_when: false - name: Read Appservice IRC registration-template.yaml - slurp: + ansible.builtin.slurp: src: "{{ matrix_appservice_irc_config_path }}/registration-template.yaml" register: matrix_appservice_irc_registration_template_slurp - name: Remove unnecessary Appservice IRC registration-template.yaml - file: + ansible.builtin.file: path: "{{ matrix_appservice_irc_config_path }}/registration-template.yaml" state: absent changed_when: false - name: Parse registration-template.yaml - set_fact: + ansible.builtin.set_fact: matrix_appservice_irc_registration_template: "{{ matrix_appservice_irc_registration_template_slurp['content'] | b64decode | from_yaml }}" - name: Combine registration-template.yaml and own registration override config - set_fact: - matrix_appservice_irc_registration: "{{ matrix_appservice_irc_registration_template|combine(matrix_appservice_irc_registration_override, recursive=True) }}" + ansible.builtin.set_fact: + matrix_appservice_irc_registration: "{{ matrix_appservice_irc_registration_template | combine(matrix_appservice_irc_registration_override, recursive=True) }}" - name: Ensure Appservice IRC registration.yaml installed - copy: - content: "{{ matrix_appservice_irc_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_irc_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_irc_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-appservice-irc.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-appservice-irc.service.j2" dest: "{{ matrix_systemd_path }}/matrix-appservice-irc.service" mode: 0644 register: matrix_appservice_irc_systemd_service_result - name: Ensure systemd reloaded after matrix-appservice-irc.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_irc_systemd_service_result.changed" - name: Ensure matrix-appservice-irc.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-appservice-irc.service" state: restarted - when: "matrix_appservice_irc_requires_restart|bool" + when: "matrix_appservice_irc_requires_restart | bool" diff --git a/roles/matrix-bridge-appservice-irc/tasks/setup_uninstall.yml b/roles/matrix-bridge-appservice-irc/tasks/setup_uninstall.yml index a4d95df55..176317dec 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-appservice-irc service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-appservice-irc.service" register: matrix_appservice_irc_service_stat - name: Ensure matrix-appservice-irc is stopped - service: + ansible.builtin.service: name: matrix-appservice-irc state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_appservice_irc_service_stat.stat.exists" - name: Ensure matrix-appservice-irc.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-appservice-irc.service" state: absent when: "matrix_appservice_irc_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-appservice-irc.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_irc_service_stat.stat.exists" diff --git a/roles/matrix-bridge-appservice-irc/tasks/validate_config.yml b/roles/matrix-bridge-appservice-irc/tasks/validate_config.yml index 303f26409..f101e6fea 100644 --- a/roles/matrix-bridge-appservice-irc/tasks/validate_config.yml +++ b/roles/matrix-bridge-appservice-irc/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -17,7 +17,7 @@ # # This is a safety check to ensure we fail earlier and in a nicer way. - name: Fail if no additional configuration provided - fail: + ansible.builtin.fail: msg: >- Your Appservice IRC configuration is incomplete (lacking an `ircService.servers` configuration). You need to define one or more servers by either using `matrix_appservice_irc_ircService_servers` @@ -26,7 +26,7 @@ when: "matrix_appservice_irc_configuration.ircService.servers|length == 0" - name: (Deprecation) Catch and report renamed appservice-irc variables - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-bridge-appservice-slack/defaults/main.yml b/roles/matrix-bridge-appservice-slack/defaults/main.yml index 91a00d3db..71fca8e6e 100644 --- a/roles/matrix-bridge-appservice-slack/defaults/main.yml +++ b/roles/matrix-bridge-appservice-slack/defaults/main.yml @@ -6,10 +6,14 @@ matrix_appservice_slack_enabled: true matrix_appservice_slack_container_image_self_build: false matrix_appservice_slack_docker_repo: "https://github.com/matrix-org/matrix-appservice-slack.git" +matrix_appservice_slack_docker_repo_version: "{{ 'master' if matrix_appservice_slack_version == 'latest' else matrix_appservice_slack_version }}" matrix_appservice_slack_docker_src_files_path: "{{ matrix_base_data_path }}/appservice-slack/docker-src" -matrix_appservice_slack_version: release-1.11.0 -matrix_appservice_slack_docker_image: "{{ matrix_container_global_registry_prefix }}matrixdotorg/matrix-appservice-slack:{{ matrix_appservice_slack_version }}" +# matrix_appservice_slack_version used to contain the full Docker image tag (e.g. `release-X.X.X`). +# It's a bare version number now. We try to somewhat retain compatibility below. +matrix_appservice_slack_version: 1.11.0 +matrix_appservice_slack_docker_image: "{{ matrix_container_global_registry_prefix }}matrixdotorg/matrix-appservice-slack:{{ matrix_appservice_slack_docker_image_tag }}" +matrix_appservice_slack_docker_image_tag: "{{ 'latest' if matrix_appservice_slack_version == 'latest' else ('release-' + matrix_appservice_slack_version) }}" matrix_appservice_slack_docker_image_force_pull: "{{ matrix_appservice_slack_docker_image.endswith(':latest') }}" matrix_appservice_slack_base_path: "{{ matrix_base_data_path }}/appservice-slack" @@ -63,12 +67,13 @@ matrix_appservice_slack_database_name: matrix_appservice_slack matrix_appservice_slack_database_connection_string: 'postgresql://{{ matrix_appservice_slack_database_username }}:{{ matrix_appservice_slack_database_password }}@{{ matrix_appservice_slack_database_hostname }}:{{ matrix_appservice_slack_database_port }}/{{ matrix_appservice_slack_database_name }}?sslmode=disable' # This is what actually goes into `database.connectionString` for the bridge. -matrix_appservice_slack_database_connectionString: "{{ - { - 'nedb': 'nedb:///data', - 'postgres': matrix_appservice_slack_database_connection_string, - }[matrix_appservice_slack_database_engine] -}}" +matrix_appservice_slack_database_connectionString: |- # noqa var-naming + {{ + { + 'nedb': 'nedb:///data', + 'postgres': matrix_appservice_slack_database_connection_string, + }[matrix_appservice_slack_database_engine] + }} matrix_appservice_slack_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}" @@ -95,9 +100,9 @@ matrix_appservice_slack_configuration_extension_yaml: | # - "./debug.log": "info" #- "./error.log": "error" -matrix_appservice_slack_configuration_extension: "{{ matrix_appservice_slack_configuration_extension_yaml|from_yaml if matrix_appservice_slack_configuration_extension_yaml|from_yaml else {} }}" +matrix_appservice_slack_configuration_extension: "{{ matrix_appservice_slack_configuration_extension_yaml | from_yaml if matrix_appservice_slack_configuration_extension_yaml | from_yaml else {} }}" -matrix_appservice_slack_configuration: "{{ matrix_appservice_slack_configuration_yaml|from_yaml|combine(matrix_appservice_slack_configuration_extension, recursive=True) }}" +matrix_appservice_slack_configuration: "{{ matrix_appservice_slack_configuration_yaml | from_yaml | combine(matrix_appservice_slack_configuration_extension, recursive=True) }}" matrix_appservice_slack_registration_yaml: | id: "{{ matrix_appservice_slack_id_token }}" @@ -111,9 +116,9 @@ matrix_appservice_slack_registration_yaml: | - exclusive: false regex: '#{{ matrix_appservice_slack_user_prefix }}.*' rooms: [] - url: "{{matrix_appservice_slack_appservice_url}}:{{ matrix_appservice_slack_matrix_port }}" + url: "{{ matrix_appservice_slack_appservice_url }}:{{ matrix_appservice_slack_matrix_port }}" sender_localpart: slackbot rate_limited: true protocols: null -matrix_appservice_slack_registration: "{{ matrix_appservice_slack_registration_yaml|from_yaml }}" +matrix_appservice_slack_registration: "{{ matrix_appservice_slack_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-appservice-slack/tasks/init.yml b/roles/matrix-bridge-appservice-slack/tasks/init.yml index c83318171..b4895aea7 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/init.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/init.yml @@ -2,62 +2,62 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_appservice_slack_container_image_self_build and matrix_appservice_slack_enabled" # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-appservice-slack role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-appservice-slack.service'] }}" - when: matrix_appservice_slack_enabled|bool + when: matrix_appservice_slack_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_appservice_slack_config_path }}/slack-registration.yaml,dst=/matrix-appservice-slack-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-appservice-slack-registration.yaml"] }} - when: matrix_appservice_slack_enabled|bool + when: matrix_appservice_slack_enabled | bool # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-appservice-slack role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Slack Appservice'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-appservice-slack role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Matrix Appservice Slack proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_appservice_slack_matrix_nginx_proxy_configuration: | location {{ matrix_appservice_slack_public_endpoint }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_appservice_slack_appservice_url }}:{{ matrix_appservice_slack_slack_port }}"; @@ -69,23 +69,23 @@ } - name: Register Slack Appservice proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_appservice_slack_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_appservice_slack_enabled|bool + when: matrix_appservice_slack_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Matrix Slack bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ something }}` URL endpoint to the matrix-appservice-slack container. You can expose the container's port using the `matrix_appservice_slack_container_http_host_bind_port` variable. - when: "matrix_appservice_slack_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_appservice_slack_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-appservice-slack/tasks/main.yml b/roles/matrix-bridge-appservice-slack/tasks/main.yml index 06c3abb61..cd83f61fb 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/main.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_appservice_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_appservice_slack_enabled | bool" tags: - setup-all - setup-appservice-slack -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_appservice_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_appservice_slack_enabled | bool" tags: - setup-all - setup-appservice-slack -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_appservice_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_appservice_slack_enabled | bool" tags: - setup-all - setup-appservice-slack diff --git a/roles/matrix-bridge-appservice-slack/tasks/migrate_nedb_to_postgres.yml b/roles/matrix-bridge-appservice-slack/tasks/migrate_nedb_to_postgres.yml index 0bea65bc4..b9aca080a 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/migrate_nedb_to_postgres.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/migrate_nedb_to_postgres.yml @@ -1,40 +1,40 @@ --- - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" # Actual import work - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true register: matrix_postgres_service_start_result - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false - when: "matrix_postgres_service_start_result.changed|bool" + when: "matrix_postgres_service_start_result.changed | bool" - name: Ensure matrix-appservice-slack is stopped - service: + ansible.builtin.service: name: matrix-appservice-slack state: stopped - name: Import appservice-slack NeDB database into Postgres - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -46,10 +46,14 @@ {{ matrix_appservice_slack_docker_image }} -c '/usr/local/bin/node /usr/src/app/lib/scripts/migrateToPostgres.js --dbdir /data --connectionString {{ matrix_appservice_slack_database_connection_string }}' + register: matrix_appservice_slack_import_nedb_to_postgres_result + changed_when: matrix_appservice_slack_import_nedb_to_postgres_result.rc == 0 - name: Archive NeDB database files - command: + ansible.builtin.command: cmd: "mv {{ matrix_appservice_slack_data_path }}/{{ item }} {{ matrix_appservice_slack_data_path }}/{{ item }}.backup" + register: matrix_appservice_slack_import_nedb_to_postgres_move_result + changed_when: matrix_appservice_slack_import_nedb_to_postgres_move_result.rc == 0 with_items: - teams.db - room-store.db @@ -57,10 +61,10 @@ - event-store.db - name: Inject result - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your appservice-slack database files have been imported into Postgres. The original database files have been moved from `{{ matrix_appservice_slack_data_path }}/*.db` to `{{ matrix_appservice_slack_data_path }}/*.db.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete these files." diff --git a/roles/matrix-bridge-appservice-slack/tasks/setup_install.yml b/roles/matrix-bridge-appservice-slack/tasks/setup_install.yml index 42aa020c5..a2921d980 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/setup_install.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure AppService Slack paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -12,23 +12,23 @@ - {path: "{{ matrix_appservice_slack_config_path }}", when: true} - {path: "{{ matrix_appservice_slack_data_path }}", when: true} - {path: "{{ matrix_appservice_slack_docker_src_files_path }}", when: "{{ matrix_appservice_slack_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool -- set_fact: +- ansible.builtin.set_fact: matrix_appservice_slack_requires_restart: false - block: - name: Check if a nedb database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_appservice_slack_data_path }}/teams.db" register: matrix_appservice_slack_nedb_database_path_local_stat_result - block: - - import_tasks: "{{ role_path }}/tasks/migrate_nedb_to_postgres.yml" + - ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_nedb_to_postgres.yml" - - set_fact: + - ansible.builtin.set_fact: matrix_appservice_slack_requires_restart: true - when: "matrix_appservice_slack_nedb_database_path_local_stat_result.stat.exists|bool" + when: "matrix_appservice_slack_nedb_database_path_local_stat_result.stat.exists | bool" when: "matrix_appservice_slack_database_engine == 'postgres'" - name: Ensure Appservice Slack image is pulled @@ -37,21 +37,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_appservice_slack_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_appservice_slack_docker_image_force_pull }}" - when: "not matrix_appservice_slack_container_image_self_build|bool" + when: "not matrix_appservice_slack_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-appservice-slack repository is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_appservice_slack_docker_repo }}" + version: "{{ matrix_appservice_slack_docker_repo_version }}" dest: "{{ matrix_appservice_slack_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_appservice_slack_git_pull_results - when: "matrix_appservice_slack_container_image_self_build|bool" + when: "matrix_appservice_slack_container_image_self_build | bool" - name: Ensure matrix-appservice-slack Docker image is built docker_image: @@ -63,38 +64,38 @@ dockerfile: Dockerfile path: "{{ matrix_appservice_slack_docker_src_files_path }}" pull: true - when: "matrix_appservice_slack_container_image_self_build|bool and matrix_appservice_slack_git_pull_results.changed" + when: "matrix_appservice_slack_container_image_self_build | bool and matrix_appservice_slack_git_pull_results.changed" - name: Ensure Matrix Appservice Slack config installed - copy: - content: "{{ matrix_appservice_slack_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_slack_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_slack_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure appservice-slack registration.yaml installed - copy: - content: "{{ matrix_appservice_slack_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_slack_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_slack_config_path }}/slack-registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-appservice-slack.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-appservice-slack.service.j2" dest: "{{ matrix_systemd_path }}/matrix-appservice-slack.service" mode: 0644 register: matrix_appservice_slack_systemd_service_result - name: Ensure systemd reloaded after matrix-appservice-slack.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_slack_systemd_service_result.changed" - name: Ensure matrix-appservice-slack.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-appservice-slack.service" state: restarted - when: "matrix_appservice_slack_requires_restart|bool" + when: "matrix_appservice_slack_requires_restart | bool" diff --git a/roles/matrix-bridge-appservice-slack/tasks/setup_uninstall.yml b/roles/matrix-bridge-appservice-slack/tasks/setup_uninstall.yml index dffe78b34..fa1aaf269 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-appservice-slack service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-appservice-slack.service" register: matrix_appservice_slack_service_stat - name: Ensure matrix-appservice-slack is stopped - service: + ansible.builtin.service: name: matrix-appservice-slack state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_appservice_slack_service_stat.stat.exists" - name: Ensure matrix-appservice-slack.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-appservice-slack.service" state: absent when: "matrix_appservice_slack_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-appservice-slack.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_slack_service_stat.stat.exists" diff --git a/roles/matrix-bridge-appservice-slack/tasks/validate_config.yml b/roles/matrix-bridge-appservice-slack/tasks/validate_config.yml index 1866c3123..e00eb6d4a 100644 --- a/roles/matrix-bridge-appservice-slack/tasks/validate_config.yml +++ b/roles/matrix-bridge-appservice-slack/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -13,7 +13,7 @@ - "matrix_appservice_slack_id_token" - name: (Deprecation) Catch and report renamed settings - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-bridge-appservice-webhooks/defaults/main.yml b/roles/matrix-bridge-appservice-webhooks/defaults/main.yml index e7ea26ed3..f181f0958 100644 --- a/roles/matrix-bridge-appservice-webhooks/defaults/main.yml +++ b/roles/matrix-bridge-appservice-webhooks/defaults/main.yml @@ -61,9 +61,9 @@ matrix_appservice_webhooks_configuration_yaml: "{{ lookup('template', 'templates matrix_appservice_webhooks_configuration_extension_yaml: | # -matrix_appservice_webhooks_configuration_extension: "{{ matrix_appservice_webhooks_configuration_extension_yaml|from_yaml if matrix_appservice_webhooks_configuration_extension_yaml|from_yaml else {} }}" +matrix_appservice_webhooks_configuration_extension: "{{ matrix_appservice_webhooks_configuration_extension_yaml | from_yaml if matrix_appservice_webhooks_configuration_extension_yaml | from_yaml else {} }}" -matrix_appservice_webhooks_configuration: "{{ matrix_appservice_webhooks_configuration_yaml|from_yaml|combine(matrix_appservice_webhooks_configuration_extension, recursive=True) }}" +matrix_appservice_webhooks_configuration: "{{ matrix_appservice_webhooks_configuration_yaml | from_yaml | combine(matrix_appservice_webhooks_configuration_extension, recursive=True) }}" matrix_appservice_webhooks_registration_yaml: | id: "{{ matrix_appservice_webhooks_id_token }}" @@ -80,4 +80,4 @@ matrix_appservice_webhooks_registration_yaml: | rate_limited: false protocols: null -matrix_appservice_webhooks_registration: "{{ matrix_appservice_webhooks_registration_yaml|from_yaml }}" +matrix_appservice_webhooks_registration: "{{ matrix_appservice_webhooks_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-appservice-webhooks/tasks/init.yml b/roles/matrix-bridge-appservice-webhooks/tasks/init.yml index 370b835d6..8a12a686e 100644 --- a/roles/matrix-bridge-appservice-webhooks/tasks/init.yml +++ b/roles/matrix-bridge-appservice-webhooks/tasks/init.yml @@ -2,54 +2,54 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-appservice-webhooks role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-appservice-webhooks.service'] }}" - when: matrix_appservice_webhooks_enabled|bool + when: matrix_appservice_webhooks_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_appservice_webhooks_config_path }}/webhooks-registration.yaml,dst=/matrix-appservice-webhooks-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-appservice-webhooks-registration.yaml"] }} - when: matrix_appservice_webhooks_enabled|bool + when: matrix_appservice_webhooks_enabled | bool # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-appservice-webhooks role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append webhooks Appservice'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-appservice-webhooks role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Matrix Appservice webhooks proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_appservice_webhooks_matrix_nginx_proxy_configuration: | - {% if matrix_nginx_proxy_enabled|default(False) %} + {% if matrix_nginx_proxy_enabled | default(False) %} {# Use the embedded DNS resolver in Docker containers to discover the service #} location ~ ^{{ matrix_appservice_webhooks_public_endpoint }}/(.*)$ { resolver 127.0.0.11 valid=5s; @@ -64,23 +64,23 @@ {% endif %} - name: Register webhooks Appservice proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_appservice_webhooks_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_appservice_webhooks_enabled|bool + when: matrix_appservice_webhooks_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Matrix webhooks bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_appservice_webhooks_public_endpoint }}` URL endpoint to the matrix-appservice-webhooks container. You can expose the container's port using the `matrix_appservice_webhooks_container_http_host_bind_port` variable. - when: "matrix_appservice_webhooks_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_appservice_webhooks_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-appservice-webhooks/tasks/main.yml b/roles/matrix-bridge-appservice-webhooks/tasks/main.yml index 26a7e24c7..30f05469c 100644 --- a/roles/matrix-bridge-appservice-webhooks/tasks/main.yml +++ b/roles/matrix-bridge-appservice-webhooks/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_appservice_webhooks_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_appservice_webhooks_enabled | bool" tags: - setup-all - setup-appservice-webhooks -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_appservice_webhooks_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_appservice_webhooks_enabled | bool" tags: - setup-all - setup-appservice-webhooks -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_appservice_webhooks_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_appservice_webhooks_enabled | bool" tags: - setup-all - setup-appservice-webhooks diff --git a/roles/matrix-bridge-appservice-webhooks/tasks/setup_install.yml b/roles/matrix-bridge-appservice-webhooks/tasks/setup_install.yml index 274f54c53..603f9d1d6 100644 --- a/roles/matrix-bridge-appservice-webhooks/tasks/setup_install.yml +++ b/roles/matrix-bridge-appservice-webhooks/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure AppService webhooks paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -12,7 +12,7 @@ - {path: "{{ matrix_appservice_webhooks_config_path }}", when: true} - {path: "{{ matrix_appservice_webhooks_data_path }}", when: true} - {path: "{{ matrix_appservice_webhooks_docker_src_files_path }}", when: "{{ matrix_appservice_webhooks_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Appservice webhooks image is pulled docker_image: @@ -20,7 +20,7 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_appservice_webhooks_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_appservice_webhooks_docker_image_force_pull }}" - when: "not matrix_appservice_webhooks_container_image_self_build|bool" + when: "not matrix_appservice_webhooks_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" @@ -28,7 +28,7 @@ - block: - name: Ensure Appservice webhooks repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_appservice_webhooks_container_image_self_build_repo }}" dest: "{{ matrix_appservice_webhooks_docker_src_files_path }}" version: "{{ matrix_appservice_webhooks_container_image_self_build_repo_version }}" @@ -47,18 +47,18 @@ dockerfile: "{{ matrix_appservice_webhooks_container_image_self_build_repo_dockerfile_path }}" path: "{{ matrix_appservice_webhooks_docker_src_files_path }}" pull: true - when: "matrix_appservice_webhooks_container_image_self_build|bool" + when: "matrix_appservice_webhooks_container_image_self_build | bool" - name: Ensure Matrix Appservice webhooks config is installed - copy: - content: "{{ matrix_appservice_webhooks_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_webhooks_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_webhooks_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Matrix Appservice webhooks schema.yml template exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/schema.yml.j2" dest: "{{ matrix_appservice_webhooks_config_path }}/schema.yml" mode: 0644 @@ -66,7 +66,7 @@ group: "{{ matrix_user_groupname }}" - name: Ensure Matrix Appservice webhooks database.json template exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/database.json.j2" dest: "{{ matrix_appservice_webhooks_data_path }}/database.json" mode: 0644 @@ -74,21 +74,21 @@ group: "{{ matrix_user_groupname }}" - name: Ensure appservice-webhooks registration.yaml installed - copy: - content: "{{ matrix_appservice_webhooks_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_appservice_webhooks_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_appservice_webhooks_config_path }}/webhooks-registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-appservice-webhooks.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-appservice-webhooks.service.j2" dest: "{{ matrix_systemd_path }}/matrix-appservice-webhooks.service" mode: 0644 register: matrix_appservice_webhooks_systemd_service_result - name: Ensure systemd reloaded after matrix-appservice-webhooks.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_webhooks_systemd_service_result.changed" diff --git a/roles/matrix-bridge-appservice-webhooks/tasks/setup_uninstall.yml b/roles/matrix-bridge-appservice-webhooks/tasks/setup_uninstall.yml index 38235652b..2b3c29d5e 100644 --- a/roles/matrix-bridge-appservice-webhooks/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-appservice-webhooks/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-appservice-webhooks service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-appservice-webhooks.service" register: matrix_appservice_webhooks_service_stat - name: Ensure matrix-appservice-webhooks is stopped - service: + ansible.builtin.service: name: matrix-appservice-webhooks state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_appservice_webhooks_service_stat.stat.exists" - name: Ensure matrix-appservice-webhooks.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-appservice-webhooks.service" state: absent when: "matrix_appservice_webhooks_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-appservice-webhooks.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_appservice_webhooks_service_stat.stat.exists" diff --git a/roles/matrix-bridge-appservice-webhooks/tasks/validate_config.yml b/roles/matrix-bridge-appservice-webhooks/tasks/validate_config.yml index 48f63e68b..d7f45c6f8 100644 --- a/roles/matrix-bridge-appservice-webhooks/tasks/validate_config.yml +++ b/roles/matrix-bridge-appservice-webhooks/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-beeper-linkedin/defaults/main.yml b/roles/matrix-bridge-beeper-linkedin/defaults/main.yml index 498e4894d..a83380932 100644 --- a/roles/matrix-bridge-beeper-linkedin/defaults/main.yml +++ b/roles/matrix-bridge-beeper-linkedin/defaults/main.yml @@ -88,11 +88,11 @@ matrix_beeper_linkedin_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_beeper_linkedin_configuration_yaml`. -matrix_beeper_linkedin_configuration_extension: "{{ matrix_beeper_linkedin_configuration_extension_yaml|from_yaml if matrix_beeper_linkedin_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_beeper_linkedin_configuration_extension: "{{ matrix_beeper_linkedin_configuration_extension_yaml | from_yaml if matrix_beeper_linkedin_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_beeper_linkedin_configuration_yaml`. -matrix_beeper_linkedin_configuration: "{{ matrix_beeper_linkedin_configuration_yaml|from_yaml|combine(matrix_beeper_linkedin_configuration_extension, recursive=True) }}" +matrix_beeper_linkedin_configuration: "{{ matrix_beeper_linkedin_configuration_yaml | from_yaml | combine(matrix_beeper_linkedin_configuration_extension, recursive=True) }}" matrix_beeper_linkedin_registration_yaml: | id: linkedin @@ -104,10 +104,10 @@ matrix_beeper_linkedin_registration_yaml: | rate_limited: false namespaces: users: - - regex: '^@linkedin_.+:{{ matrix_beeper_linkedin_homeserver_domain|regex_escape }}$' + - regex: '^@linkedin_.+:{{ matrix_beeper_linkedin_homeserver_domain | regex_escape }}$' exclusive: true - exclusive: true - regex: '^@{{ matrix_beeper_linkedin_appservice_bot_username|regex_escape }}:{{ matrix_beeper_linkedin_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_beeper_linkedin_appservice_bot_username | regex_escape }}:{{ matrix_beeper_linkedin_homeserver_domain | regex_escape }}$' de.sorunome.msc2409.push_ephemeral: true -matrix_beeper_linkedin_registration: "{{ matrix_beeper_linkedin_registration_yaml|from_yaml }}" +matrix_beeper_linkedin_registration: "{{ matrix_beeper_linkedin_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-beeper-linkedin/tasks/init.yml b/roles/matrix-bridge-beeper-linkedin/tasks/init.yml index 64057301f..14137b705 100644 --- a/roles/matrix-bridge-beeper-linkedin/tasks/init.yml +++ b/roles/matrix-bridge-beeper-linkedin/tasks/init.yml @@ -1,22 +1,22 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-beeper-linkedin.service'] }}" - when: matrix_beeper_linkedin_enabled|bool + when: matrix_beeper_linkedin_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_beeper_linkedin_config_path }}/registration.yaml,dst=/matrix-beeper-linkedin-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-beeper-linkedin-registration.yaml"] }} - when: matrix_beeper_linkedin_enabled|bool + when: matrix_beeper_linkedin_enabled | bool diff --git a/roles/matrix-bridge-beeper-linkedin/tasks/main.yml b/roles/matrix-bridge-beeper-linkedin/tasks/main.yml index 920265fb5..8f295d2ca 100644 --- a/roles/matrix-bridge-beeper-linkedin/tasks/main.yml +++ b/roles/matrix-bridge-beeper-linkedin/tasks/main.yml @@ -1,22 +1,22 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_beeper_linkedin_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_beeper_linkedin_enabled | bool" tags: - setup-all - setup-beeper-linkedin -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" when: "run_setup and matrix_beeper_linkedin_enabled" tags: - setup-all - setup-beeper-linkedin -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" when: "run_setup and not matrix_beeper_linkedin_enabled" tags: - setup-all diff --git a/roles/matrix-bridge-beeper-linkedin/tasks/setup_install.yml b/roles/matrix-bridge-beeper-linkedin/tasks/setup_install.yml index 74f80314b..04a787b83 100644 --- a/roles/matrix-bridge-beeper-linkedin/tasks/setup_install.yml +++ b/roles/matrix-bridge-beeper-linkedin/tasks/setup_install.yml @@ -3,12 +3,12 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-beeper-linkedin role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure Beeper LinkedIn paths exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -19,7 +19,7 @@ - {path: "{{ matrix_beeper_linkedin_config_path }}", when: true} - {path: "{{ matrix_beeper_linkedin_data_path }}", when: true} - {path: "{{ matrix_beeper_linkedin_docker_src_files_path }}", when: "{{ matrix_beeper_linkedin_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Beeper LinkedIn image is pulled @@ -28,7 +28,7 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_beeper_linkedin_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_beeper_linkedin_docker_image_force_pull }}" - when: "not matrix_beeper_linkedin_container_image_self_build|bool" + when: "not matrix_beeper_linkedin_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" @@ -36,7 +36,7 @@ - block: - name: Ensure Beeper LinkedIn repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_beeper_linkedin_container_image_self_build_repo }}" dest: "{{ matrix_beeper_linkedin_docker_src_files_path }}" version: "{{ matrix_beeper_linkedin_container_image_self_build_branch }}" @@ -48,14 +48,17 @@ # Building the container image (using the default Dockerfile) requires that a docker-requirements.txt file be generated. # See: https://gitlab.com/beeper/linkedin/-/blob/94442db17ccb9769b377cdb8e4bf1cb3955781d7/.gitlab-ci.yml#L30-40 - name: Ensure docker-requirements.txt is generated before building Beeper LinkedIn Docker Image - command: | - {{ matrix_host_command_docker }} run \ - --rm \ - --entrypoint=/bin/sh \ - --mount type=bind,src={{ matrix_beeper_linkedin_docker_src_files_path }},dst=/work \ - -w /work \ - docker.io/python:3.9.6-buster \ - -c "pip install poetry && poetry export --without-hashes -E e2be -E images -E metrics | sed 's/==.*//g' > docker-requirements.txt" + ansible.builtin.command: + cmd: | + {{ matrix_host_command_docker }} run \ + --rm \ + --entrypoint=/bin/sh \ + --mount type=bind,src={{ matrix_beeper_linkedin_docker_src_files_path }},dst=/work \ + -w /work \ + docker.io/python:3.9.6-buster \ + -c "pip install poetry && poetry export --without-hashes -E e2be -E images -E metrics | sed 's/==.*//g' > docker-requirements.txt" + register: matrix_beeper_linkedin_generate_docker_requirements_result + changed_when: matrix_beeper_linkedin_generate_docker_requirements_result.rc == 0 - name: Ensure Beeper LinkedIn Docker image is built docker_image: @@ -69,32 +72,32 @@ pull: true args: TARGETARCH: "{{ matrix_architecture }}" - when: "matrix_beeper_linkedin_container_image_self_build|bool" + when: "matrix_beeper_linkedin_container_image_self_build | bool" - name: Ensure beeper-linkedin config.yaml installed - copy: - content: "{{ matrix_beeper_linkedin_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_beeper_linkedin_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_beeper_linkedin_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure beeper-linkedin registration.yaml installed - copy: - content: "{{ matrix_beeper_linkedin_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_beeper_linkedin_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_beeper_linkedin_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-beeper-linkedin.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-beeper-linkedin.service.j2" dest: "{{ matrix_systemd_path }}/matrix-beeper-linkedin.service" mode: 0644 register: matrix_beeper_linkedin_systemd_service_result - name: Ensure systemd reloaded after matrix-beeper-linkedin.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_beeper_linkedin_systemd_service_result.changed" diff --git a/roles/matrix-bridge-beeper-linkedin/tasks/setup_uninstall.yml b/roles/matrix-bridge-beeper-linkedin/tasks/setup_uninstall.yml index befa2f610..25dbf82b0 100644 --- a/roles/matrix-bridge-beeper-linkedin/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-beeper-linkedin/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-beeper-linkedin service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-beeper-linkedin.service" register: matrix_beeper_linkedin_service_stat - name: Ensure matrix-beeper-linkedin is stopped - service: + ansible.builtin.service: name: matrix-beeper-linkedin state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_beeper_linkedin_service_stat.stat.exists" - name: Ensure matrix-beeper-linkedin.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-beeper-linkedin.service" state: absent when: "matrix_beeper_linkedin_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-beeper-linkedin.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_beeper_linkedin_service_stat.stat.exists" diff --git a/roles/matrix-bridge-beeper-linkedin/tasks/validate_config.yml b/roles/matrix-bridge-beeper-linkedin/tasks/validate_config.yml index d808de081..61489b7c6 100644 --- a/roles/matrix-bridge-beeper-linkedin/tasks/validate_config.yml +++ b/roles/matrix-bridge-beeper-linkedin/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-go-skype-bridge/defaults/main.yml b/roles/matrix-bridge-go-skype-bridge/defaults/main.yml index 5e31b0450..b05e78a58 100644 --- a/roles/matrix-bridge-go-skype-bridge/defaults/main.yml +++ b/roles/matrix-bridge-go-skype-bridge/defaults/main.yml @@ -101,11 +101,11 @@ matrix_go_skype_bridge_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_go_skype_bridge_configuration_yaml`. -matrix_go_skype_bridge_configuration_extension: "{{ matrix_go_skype_bridge_configuration_extension_yaml|from_yaml if matrix_go_skype_bridge_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_go_skype_bridge_configuration_extension: "{{ matrix_go_skype_bridge_configuration_extension_yaml | from_yaml if matrix_go_skype_bridge_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_go_skype_bridge_configuration_yaml`. -matrix_go_skype_bridge_configuration: "{{ matrix_go_skype_bridge_configuration_yaml|from_yaml|combine(matrix_go_skype_bridge_configuration_extension, recursive=True) }}" +matrix_go_skype_bridge_configuration: "{{ matrix_go_skype_bridge_configuration_yaml | from_yaml | combine(matrix_go_skype_bridge_configuration_extension, recursive=True) }}" matrix_go_skype_bridge_registration_yaml: | id: skype @@ -117,13 +117,13 @@ matrix_go_skype_bridge_registration_yaml: | rate_limited: false namespaces: users: - - regex: '^@skype-(.*):{{ matrix_go_skype_bridge_homeserver_domain|regex_escape }}$' + - regex: '^@skype-(.*):{{ matrix_go_skype_bridge_homeserver_domain | regex_escape }}$' exclusive: true - exclusive: true - regex: '^@{{ matrix_go_skype_bridge_appservice_bot_username|regex_escape }}:{{ matrix_go_skype_bridge_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_go_skype_bridge_appservice_bot_username | regex_escape }}:{{ matrix_go_skype_bridge_homeserver_domain | regex_escape }}$' de.sorunome.msc2409.push_ephemeral: true -matrix_go_skype_bridge_registration: "{{ matrix_go_skype_bridge_registration_yaml|from_yaml }}" +matrix_go_skype_bridge_registration: "{{ matrix_go_skype_bridge_registration_yaml | from_yaml }}" # Enable End-to-bridge encryption matrix_go_skype_bridge_bridge_encryption_allow: false diff --git a/roles/matrix-bridge-go-skype-bridge/tasks/init.yml b/roles/matrix-bridge-go-skype-bridge/tasks/init.yml index 452d835b7..9b8265560 100644 --- a/roles/matrix-bridge-go-skype-bridge/tasks/init.yml +++ b/roles/matrix-bridge-go-skype-bridge/tasks/init.yml @@ -1,21 +1,21 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-go-skype-bridge.service'] }}" - when: matrix_go_skype_bridge_enabled|bool + when: matrix_go_skype_bridge_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_go_skype_bridge_config_path }}/registration.yaml,dst=/matrix-go-skype-bridge-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-go-skype-bridge-registration.yaml"] }} - when: matrix_go_skype_bridge_enabled|bool + when: matrix_go_skype_bridge_enabled | bool diff --git a/roles/matrix-bridge-go-skype-bridge/tasks/main.yml b/roles/matrix-bridge-go-skype-bridge/tasks/main.yml index 456ea53cd..39f4b2e52 100644 --- a/roles/matrix-bridge-go-skype-bridge/tasks/main.yml +++ b/roles/matrix-bridge-go-skype-bridge/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_go_skype_bridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_go_skype_bridge_enabled | bool" tags: - setup-all - setup-go-skype-bridge -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_go_skype_bridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_go_skype_bridge_enabled | bool" tags: - setup-all - setup-go-skype-bridge -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_go_skype_bridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_go_skype_bridge_enabled | bool" tags: - setup-all - setup-go-skype-bridge diff --git a/roles/matrix-bridge-go-skype-bridge/tasks/setup_install.yml b/roles/matrix-bridge-go-skype-bridge/tasks/setup_install.yml index c884625ba..7403ff5c5 100644 --- a/roles/matrix-bridge-go-skype-bridge/tasks/setup_install.yml +++ b/roles/matrix-bridge-go-skype-bridge/tasks/setup_install.yml @@ -3,41 +3,43 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-go-skype-bridge role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_go_skype_bridge_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_go_skype_bridge_sqlite_database_path_local }}" register: matrix_go_skype_bridge_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_go_skype_bridge_sqlite_database_path_local }}" dst: "{{ matrix_go_skype_bridge_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_go_skype_bridge_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-go-skype-bridge.service'] pgloader_options: ['--with "quote identifiers"'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_go_skype_bridge_requires_restart: true - when: "matrix_go_skype_bridge_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_go_skype_bridge_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_go_skype_bridge_database_engine == 'postgres'" - name: Ensure Go Skype Bridge paths exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -48,7 +50,7 @@ - {path: "{{ matrix_go_skype_bridge_config_path }}", when: true} - {path: "{{ matrix_go_skype_bridge_data_path }}", when: true} - {path: "{{ matrix_go_skype_bridge_docker_src_files_path }}", when: "{{ matrix_go_skype_bridge_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Go Skype Bridge image is pulled docker_image: @@ -63,7 +65,7 @@ until: result is not failed - name: Ensure Go Skype Bridge repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_go_skype_bridge_container_image_self_build_repo }}" dest: "{{ matrix_go_skype_bridge_docker_src_files_path }}" version: "{{ matrix_go_skype_bridge_container_image_self_build_branch }}" @@ -71,7 +73,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_go_skype_bridge_git_pull_results - when: "matrix_go_skype_bridge_container_image_self_build|bool" + when: "matrix_go_skype_bridge_container_image_self_build | bool" - name: Ensure Go Skype Bridge Docker image is built docker_image: @@ -83,20 +85,20 @@ dockerfile: Dockerfile path: "{{ matrix_go_skype_bridge_docker_src_files_path }}" pull: true - when: "matrix_go_skype_bridge_container_image_self_build|bool" + when: "matrix_go_skype_bridge_container_image_self_build | bool" - name: Check if an old database file exists - stat: + ansible.builtin.stat: path: "{{ matrix_go_skype_bridge_base_path }}/go-skype-bridge.db" register: matrix_go_skype_bridge_stat_database - name: Check if an old matrix state file exists - stat: + ansible.builtin.stat: path: "{{ matrix_go_skype_bridge_base_path }}/mx-state.json" register: matrix_go_skype_bridge_stat_mx_state - name: (Data relocation) Ensure matrix-go-skype-bridge.service is stopped - service: + ansible.builtin.service: name: matrix-go-skype-bridge state: stopped enabled: false @@ -105,43 +107,43 @@ when: "matrix_go_skype_bridge_stat_database.stat.exists" - name: (Data relocation) Move go-skype-bridge database file to ./data directory - command: "mv {{ matrix_go_skype_bridge_base_path }}/go-skype-bridge.db {{ matrix_go_skype_bridge_data_path }}/go-skype-bridge.db" + ansible.builtin.command: "mv {{ matrix_go_skype_bridge_base_path }}/go-skype-bridge.db {{ matrix_go_skype_bridge_data_path }}/go-skype-bridge.db" when: "matrix_go_skype_bridge_stat_database.stat.exists" - name: (Data relocation) Move go-skype-bridge mx-state file to ./data directory - command: "mv {{ matrix_go_skype_bridge_base_path }}/mx-state.json {{ matrix_go_skype_bridge_data_path }}/mx-state.json" + ansible.builtin.command: "mv {{ matrix_go_skype_bridge_base_path }}/mx-state.json {{ matrix_go_skype_bridge_data_path }}/mx-state.json" when: "matrix_go_skype_bridge_stat_mx_state.stat.exists" - name: Ensure go-skype-bridge config.yaml installed - copy: - content: "{{ matrix_go_skype_bridge_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_go_skype_bridge_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_go_skype_bridge_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure go-skype-bridge registration.yaml installed - copy: - content: "{{ matrix_go_skype_bridge_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_go_skype_bridge_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_go_skype_bridge_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-go-skype-bridge.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-go-skype-bridge.service.j2" dest: "{{ matrix_systemd_path }}/matrix-go-skype-bridge.service" mode: 0644 register: matrix_go_skype_bridge_systemd_service_result - name: Ensure systemd reloaded after matrix-go-skype-bridge.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_go_skype_bridge_systemd_service_result.changed" - name: Ensure matrix-go-skype-bridge.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-go-skype-bridge.service" state: restarted - when: "matrix_go_skype_bridge_requires_restart|bool" + when: "matrix_go_skype_bridge_requires_restart | bool" diff --git a/roles/matrix-bridge-go-skype-bridge/tasks/setup_uninstall.yml b/roles/matrix-bridge-go-skype-bridge/tasks/setup_uninstall.yml index 19acff857..975b25ab4 100644 --- a/roles/matrix-bridge-go-skype-bridge/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-go-skype-bridge/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-go-skype-bridge service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-go-skype-bridge.service" register: matrix_go_skype_bridge_service_stat - name: Ensure matrix-go-skype-bridge is stopped - service: + ansible.builtin.service: name: matrix-go-skype-bridge state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_go_skype_bridge_service_stat.stat.exists" - name: Ensure matrix-go-skype-bridge.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-go-skype-bridge.service" state: absent when: "matrix_go_skype_bridge_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-go-skype-bridge.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_go_skype_bridge_service_stat.stat.exists" diff --git a/roles/matrix-bridge-go-skype-bridge/tasks/validate_config.yml b/roles/matrix-bridge-go-skype-bridge/tasks/validate_config.yml index 7e9f3dafb..d681299f2 100644 --- a/roles/matrix-bridge-go-skype-bridge/tasks/validate_config.yml +++ b/roles/matrix-bridge-go-skype-bridge/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-heisenbridge/defaults/main.yml b/roles/matrix-bridge-heisenbridge/defaults/main.yml index e8d2c7907..68c5d75bc 100644 --- a/roles/matrix-bridge-heisenbridge/defaults/main.yml +++ b/roles/matrix-bridge-heisenbridge/defaults/main.yml @@ -45,4 +45,4 @@ matrix_heisenbridge_registration_yaml: aliases: [] rooms: [] -matrix_heisenbridge_registration: "{{ matrix_heisenbridge_registration_yaml|from_yaml }}" +matrix_heisenbridge_registration: "{{ matrix_heisenbridge_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-heisenbridge/tasks/init.yml b/roles/matrix-bridge-heisenbridge/tasks/init.yml index ef3efb761..1612a5050 100644 --- a/roles/matrix-bridge-heisenbridge/tasks/init.yml +++ b/roles/matrix-bridge-heisenbridge/tasks/init.yml @@ -2,28 +2,28 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-heisenbridge role needs to execute before the matrix-synapse role. - when: "matrix_heisenbridge_enabled and matrix_synapse_role_executed|default(False)" + when: "matrix_heisenbridge_enabled and matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-heisenbridge.service'] }}" - when: matrix_heisenbridge_enabled|bool + when: matrix_heisenbridge_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_heisenbridge_base_path }}/registration.yaml,dst=/heisenbridge-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/heisenbridge-registration.yaml"] }} - when: matrix_heisenbridge_enabled|bool + when: matrix_heisenbridge_enabled | bool diff --git a/roles/matrix-bridge-heisenbridge/tasks/main.yml b/roles/matrix-bridge-heisenbridge/tasks/main.yml index a266643d1..6af9813ec 100644 --- a/roles/matrix-bridge-heisenbridge/tasks/main.yml +++ b/roles/matrix-bridge-heisenbridge/tasks/main.yml @@ -1,17 +1,17 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_heisenbridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_heisenbridge_enabled | bool" tags: - setup-all - setup-heisenbridge -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_heisenbridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_heisenbridge_enabled | bool" tags: - setup-all - setup-heisenbridge diff --git a/roles/matrix-bridge-heisenbridge/tasks/setup_install.yml b/roles/matrix-bridge-heisenbridge/tasks/setup_install.yml index f24bf9264..ffcc1c8b9 100644 --- a/roles/matrix-bridge-heisenbridge/tasks/setup_install.yml +++ b/roles/matrix-bridge-heisenbridge/tasks/setup_install.yml @@ -12,7 +12,7 @@ until: result is not failed - name: Ensure heisenbridge paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -22,21 +22,21 @@ - "{{ matrix_heisenbridge_base_path }}" - name: Ensure heisenbridge registration.yaml installed if provided - copy: - content: "{{ matrix_heisenbridge_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_heisenbridge_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_heisenbridge_base_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-heisenbridge.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-heisenbridge.service.j2" dest: "{{ matrix_systemd_path }}/matrix-heisenbridge.service" mode: 0644 register: matrix_heisenbridge_systemd_service_result - name: Ensure systemd reloaded after matrix-heisenbridge.service installation - service: + ansible.builtin.service: daemon_reload: true when: matrix_heisenbridge_systemd_service_result.changed diff --git a/roles/matrix-bridge-heisenbridge/tasks/setup_uninstall.yml b/roles/matrix-bridge-heisenbridge/tasks/setup_uninstall.yml index 54d5bd67b..a0232295f 100644 --- a/roles/matrix-bridge-heisenbridge/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-heisenbridge/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-heisenbridge service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-heisenbridge.service" register: matrix_heisenbridge_service_stat - name: Ensure matrix-heisenbridge is stopped - service: + ansible.builtin.service: name: matrix-heisenbridge state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_heisenbridge_service_stat.stat.exists" - name: Ensure matrix-heisenbridge.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-heisenbridge.service" state: absent when: "matrix_heisenbridge_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-heisenbridge.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_heisenbridge_service_stat.stat.exists" diff --git a/roles/matrix-bridge-hookshot/defaults/main.yml b/roles/matrix-bridge-hookshot/defaults/main.yml index 74f98bacd..62f797d08 100644 --- a/roles/matrix-bridge-hookshot/defaults/main.yml +++ b/roles/matrix-bridge-hookshot/defaults/main.yml @@ -72,7 +72,7 @@ matrix_hookshot_github_oauth_uri: "{{ matrix_hookshot_urlprefix }}{{ matrix_hook # These are the default settings mentioned here and don't need to be modified: https://matrix-org.github.io/matrix-hookshot/usage/room_configuration/github_repo.html#configuration matrix_hookshot_github_ignore_hooks: "{}" matrix_hookshot_github_command_prefix: '!gh' -matrix_hookshot_github_showIssueRoomLink: false +matrix_hookshot_github_showIssueRoomLink: false # noqa var-naming matrix_hookshot_github_pr_diff: "{enabled: false, maxLines: 5}" matrix_hookshot_github_including_labels: '' matrix_hookshot_github_excluding_labels: '' @@ -97,7 +97,7 @@ matrix_hookshot_gitlab_secret: '' matrix_hookshot_figma_enabled: false # Default value of matrix_hookshot_figma_endpoint: "/hookshot/webhooks/figma/webhook" matrix_hookshot_figma_endpoint: "{{ matrix_hookshot_webhook_endpoint }}/figma/webhook" -matrix_hookshot_figma_publicUrl: "{{ matrix_hookshot_urlprefix }}{{ matrix_hookshot_figma_endpoint }}" +matrix_hookshot_figma_publicUrl: "{{ matrix_hookshot_urlprefix }}{{ matrix_hookshot_figma_endpoint }}" # noqa var-naming # To bridge figma webhooks, you need to configure one of multiple instances like this: # matrix_hookshot_figma_instances: # your-instance: @@ -144,9 +144,9 @@ matrix_hookshot_provisioning_endpoint: "{{ matrix_hookshot_public_endpoint }}{{ matrix_hookshot_widgets_enabled: true matrix_hookshot_widgets_port: 9003 -matrix_hookshot_widgets_addToAdminRooms: false # default off as it is a beta feature -matrix_hookshot_widgets_roomSetupWidget_enabled: true -matrix_hookshot_widgets_roomSetupWidget_addOnInvite: false +matrix_hookshot_widgets_addToAdminRooms: false # default off as it is a beta feature # noqa var-naming +matrix_hookshot_widgets_roomSetupWidget_enabled: true # noqa var-naming +matrix_hookshot_widgets_roomSetupWidget_addOnInvite: false # noqa var-naming # `disallowedIpRanges` describes which IP ranges should be disallowed when resolving homeserver IP addresses (for security reasons). Unless you know what you are doing, it is recommended to not include this key. The following IPs are blocked by default, unless you supply another list. # matrix_hookshot_widgets_disallowedIpRanges: # - 127.0.0.0/8 @@ -168,12 +168,12 @@ matrix_hookshot_widgets_roomSetupWidget_addOnInvite: false # - 2001:db8::/32 # - ff00::/8 # - fec0::/10 -matrix_hookshot_widgets_disallowedIpRanges: '' +matrix_hookshot_widgets_disallowedIpRanges: '' # noqa var-naming matrix_hookshot_widgets_internal: "/widgetapi" # Default value of matrix_hookshot_widgets_endpoint: "/hookshot/widgetapi" matrix_hookshot_widgets_endpoint: "{{ matrix_hookshot_public_endpoint }}{{ matrix_hookshot_widgets_internal }}" -matrix_hookshot_widgets_publicUrl: "{{ matrix_hookshot_urlprefix }}{{ matrix_hookshot_widgets_endpoint }}/v1/static" -matrix_hookshot_widgets_branding_widgetTitle: "Hookshot Configuration" +matrix_hookshot_widgets_publicUrl: "{{ matrix_hookshot_urlprefix }}{{ matrix_hookshot_widgets_endpoint }}/v1/static" # noqa var-naming +matrix_hookshot_widgets_branding_widgetTitle: "Hookshot Configuration" # noqa var-naming # You can configure access to the bridge as documented here https://matrix-org.github.io/matrix-hookshot/setup.html#permissions @@ -233,11 +233,11 @@ matrix_hookshot_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_hookshot_configuration_yaml`. -matrix_hookshot_configuration_extension: "{{ matrix_hookshot_configuration_extension_yaml|from_yaml if matrix_hookshot_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_hookshot_configuration_extension: "{{ matrix_hookshot_configuration_extension_yaml | from_yaml if matrix_hookshot_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_hookshot_configuration_yaml`. -matrix_hookshot_configuration: "{{ matrix_hookshot_configuration_yaml|from_yaml|combine(matrix_hookshot_configuration_extension, recursive=True) }}" +matrix_hookshot_configuration: "{{ matrix_hookshot_configuration_yaml | from_yaml | combine(matrix_hookshot_configuration_extension, recursive=True) }}" # Default registration template which covers the generic use case. # You can customize it by controlling the various variables inside it. @@ -255,8 +255,8 @@ matrix_hookshot_registration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_hookshot_registration_yaml`. -matrix_hookshot_registration_extension: "{{ matrix_hookshot_registration_extension_yaml|from_yaml if matrix_hookshot_registration_extension_yaml|from_yaml is mapping else {} }}" +matrix_hookshot_registration_extension: "{{ matrix_hookshot_registration_extension_yaml | from_yaml if matrix_hookshot_registration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final registration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_hookshot_registration_yaml`. -matrix_hookshot_registration: "{{ matrix_hookshot_registration_yaml|from_yaml|combine(matrix_hookshot_registration_extension, recursive=True) }}" +matrix_hookshot_registration: "{{ matrix_hookshot_registration_yaml | from_yaml | combine(matrix_hookshot_registration_extension, recursive=True) }}" diff --git a/roles/matrix-bridge-hookshot/tasks/init.yml b/roles/matrix-bridge-hookshot/tasks/init.yml index 96d5740a7..f8a1e76cb 100644 --- a/roles/matrix-bridge-hookshot/tasks/init.yml +++ b/roles/matrix-bridge-hookshot/tasks/init.yml @@ -2,47 +2,47 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-hookshot role needs to execute before the matrix-synapse role. - when: "matrix_hookshot_enabled and matrix_synapse_role_executed|default(False)" + when: "matrix_hookshot_enabled and matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-hookshot.service'] }}" - when: matrix_hookshot_enabled|bool + when: matrix_hookshot_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_hookshot_base_path }}/registration.yml,dst=/hookshot-registration.yml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/hookshot-registration.yml"] }} - when: matrix_hookshot_enabled|bool + when: matrix_hookshot_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append hookshot'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-hookshot role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Matrix hookshot proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_hookshot_matrix_nginx_proxy_configuration: | location ~ ^{{ matrix_hookshot_appservice_endpoint }}/(.*)$ { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_hookshot_container_url }}:{{ matrix_hookshot_appservice_port }}"; @@ -55,7 +55,7 @@ } {% if matrix_hookshot_provisioning_enabled %} location ~ ^{{ matrix_hookshot_provisioning_endpoint }}/(.*)$ { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_hookshot_container_url }}:{{ matrix_hookshot_provisioning_port }}"; @@ -69,7 +69,7 @@ {% endif %} {% if matrix_hookshot_widgets_enabled %} location ~ ^{{ matrix_hookshot_widgets_endpoint }}/(.*)$ { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_hookshot_container_url }}:{{ matrix_hookshot_widgets_port }}"; @@ -82,7 +82,7 @@ } {% endif %} location ~ ^{{ matrix_hookshot_webhook_endpoint }}/(.*)$ { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_hookshot_container_url }}:{{ matrix_hookshot_webhook_port }}"; @@ -95,19 +95,19 @@ } - name: Register hookshot proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_hookshot_matrix_nginx_proxy_configuration] }} - name: Generate hookshot metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/hookshot) - set_fact: + ansible.builtin.set_fact: matrix_hookshot_matrix_nginx_proxy_metrics_configuration_matrix_domain: | location /metrics/hookshot { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_hookshot_container_url }}:{{ matrix_hookshot_metrics_port }}"; @@ -117,25 +117,25 @@ proxy_pass http://127.0.0.1:{{ matrix_hookshot_metrics_port }}/metrics; {% endif %} } - when: matrix_hookshot_metrics_enabled|bool and matrix_hookshot_metrics_proxying_enabled|bool + when: matrix_hookshot_metrics_enabled | bool and matrix_hookshot_metrics_proxying_enabled | bool - name: Register hookshot metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/hookshot) - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + [matrix_hookshot_matrix_nginx_proxy_metrics_configuration_matrix_domain] }} - when: matrix_hookshot_metrics_enabled|bool and matrix_hookshot_metrics_proxying_enabled|bool - when: matrix_hookshot_enabled|bool + when: matrix_hookshot_metrics_enabled | bool and matrix_hookshot_metrics_proxying_enabled | bool + when: matrix_hookshot_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the hookshot bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_hookshot_public_endpoint }}` URL endpoint to the matrix-hookshot container. You can expose the container's ports using the `matrix_hookshot_container_http_host_bind_ports` variable. - when: "matrix_hookshot_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_hookshot_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-hookshot/tasks/main.yml b/roles/matrix-bridge-hookshot/tasks/main.yml index 409b6175a..99febe114 100644 --- a/roles/matrix-bridge-hookshot/tasks/main.yml +++ b/roles/matrix-bridge-hookshot/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_hookshot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_hookshot_enabled | bool" tags: - setup-all - setup-hookshot -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_hookshot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_hookshot_enabled | bool" tags: - setup-all - setup-hookshot -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_hookshot_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_hookshot_enabled | bool" tags: - setup-all - setup-hookshot diff --git a/roles/matrix-bridge-hookshot/tasks/setup_install.yml b/roles/matrix-bridge-hookshot/tasks/setup_install.yml index 25f2978cd..0c6bfc34b 100644 --- a/roles/matrix-bridge-hookshot/tasks/setup_install.yml +++ b/roles/matrix-bridge-hookshot/tasks/setup_install.yml @@ -1,9 +1,9 @@ --- -- import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" - name: Ensure hookshot paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -12,7 +12,7 @@ with_items: - {path: "{{ matrix_hookshot_base_path }}", when: true} - {path: "{{ matrix_hookshot_docker_src_files_path }}", when: "{{ matrix_hookshot_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure hookshot image is pulled docker_image: @@ -27,7 +27,7 @@ until: result is not failed - name: Ensure hookshot repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_hookshot_container_image_self_build_repo }}" dest: "{{ matrix_hookshot_docker_src_files_path }}" version: "{{ matrix_hookshot_container_image_self_build_branch }}" @@ -35,7 +35,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_hookshot_git_pull_results - when: "matrix_hookshot_container_image_self_build|bool" + when: "matrix_hookshot_container_image_self_build | bool" - name: Ensure hookshot Docker image is built docker_image: @@ -47,68 +47,70 @@ dockerfile: Dockerfile path: "{{ matrix_hookshot_docker_src_files_path }}" pull: true - when: "matrix_hookshot_container_image_self_build|bool" + when: "matrix_hookshot_container_image_self_build | bool" - name: Check if hookshot passkey exists - stat: + ansible.builtin.stat: path: "{{ matrix_hookshot_base_path }}/passkey.pem" register: hookshot_passkey_file - name: Generate hookshot passkey if it doesn't exist - shell: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_hookshot_base_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096" + ansible.builtin.shell: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_hookshot_base_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096" become: true become_user: "{{ matrix_user_username }}" when: "not hookshot_passkey_file.stat.exists" - name: Ensure hookshot config.yml installed if provided - copy: - content: "{{ matrix_hookshot_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_hookshot_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_hookshot_base_path }}/config.yml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Validate hookshot config.yml - command: | - {{ matrix_host_command_docker }} run - --rm - --name={{ matrix_hookshot_container_url }}-validate - --user={{ matrix_user_uid }}:{{ matrix_user_gid }} - --cap-drop=ALL - -v {{ matrix_hookshot_base_path }}/config.yml:/config.yml - {{ matrix_hookshot_docker_image }} node Config/Config.js /config.yml + ansible.builtin.command: + cmd: | + {{ matrix_host_command_docker }} run + --rm + --name={{ matrix_hookshot_container_url }}-validate + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} + --cap-drop=ALL + -v {{ matrix_hookshot_base_path }}/config.yml:/config.yml + {{ matrix_hookshot_docker_image }} node Config/Config.js /config.yml register: hookshot_config_validation_result + changed_when: false - name: Fail if hookshot config.yml invalid - fail: + ansible.builtin.fail: msg: "Your hookshot configuration did not pass validation:\n{{ hookshot_config_validation_result.stdout }}\n{{ hookshot_config_validation_result.stderr }}" when: "hookshot_config_validation_result.rc > 0" - name: Ensure hookshot registration.yml installed if provided - copy: - content: "{{ matrix_hookshot_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_hookshot_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_hookshot_base_path }}/registration.yml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure hookshot github private key file installed if github is enabled - copy: + ansible.builtin.copy: content: "{{ matrix_hookshot_github_private_key }}" dest: "{{ matrix_hookshot_base_path }}/{{ matrix_hookshot_github_private_key_file }}" mode: 0400 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_hookshot_github_enabled|bool and matrix_hookshot_github_private_key|length > 0 + when: matrix_hookshot_github_enabled | bool and matrix_hookshot_github_private_key|length > 0 - name: Ensure matrix-hookshot.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-hookshot.service.j2" dest: "{{ matrix_systemd_path }}/matrix-hookshot.service" mode: 0644 register: matrix_hookshot_systemd_service_result - name: Ensure systemd reloaded after matrix-hookshot.service installation - service: + ansible.builtin.service: daemon_reload: true when: matrix_hookshot_systemd_service_result.changed diff --git a/roles/matrix-bridge-hookshot/tasks/setup_uninstall.yml b/roles/matrix-bridge-hookshot/tasks/setup_uninstall.yml index d8efbb029..5aba14de6 100644 --- a/roles/matrix-bridge-hookshot/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-hookshot/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-hookshot service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-hookshot.service" register: matrix_hookshot_service_stat - name: Ensure matrix-hookshot is stopped - service: + ansible.builtin.service: name: matrix-hookshot state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_hookshot_service_stat.stat.exists" - name: Ensure matrix-hookshot.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-hookshot.service" state: absent when: "matrix_hookshot_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-hookshot.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_hookshot_service_stat.stat.exists" diff --git a/roles/matrix-bridge-hookshot/tasks/validate_config.yml b/roles/matrix-bridge-hookshot/tasks/validate_config.yml index b96223323..0fbcf53c2 100644 --- a/roles/matrix-bridge-hookshot/tasks/validate_config.yml +++ b/roles/matrix-bridge-hookshot/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -10,7 +10,7 @@ - "matrix_hookshot_homeserver_token" - name: Fail if required GitHub settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to enable GitHub. when: "matrix_hookshot_github_enabled and vars[item] == ''" @@ -19,7 +19,7 @@ - "matrix_hookshot_github_secret" - name: Fail if required GitHub OAuth settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to enable GitHub OAuth. when: "matrix_hookshot_github_oauth_enabled and vars[item] == ''" @@ -28,7 +28,7 @@ - "matrix_hookshot_github_oauth_secret" - name: Fail if required Jira settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to enable Jira. when: "matrix_hookshot_jira_enabled and vars[item] == ''" @@ -36,7 +36,7 @@ - "matrix_hookshot_jira_secret" - name: Fail if required Jira OAuth settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to enable Jira OAuth. when: "matrix_hookshot_jira_oauth_enabled and vars[item] == ''" @@ -45,13 +45,13 @@ - "matrix_hookshot_jira_oauth_secret" - name: Fail if required Figma settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define at least one Figma instance to enable Figma. when: "matrix_hookshot_figma_enabled and matrix_hookshot_figma_instances is undefined" - name: Fail if required provisioning settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to enable provisioning. when: "matrix_hookshot_provisioning_enabled and vars[item] == ''" @@ -59,7 +59,7 @@ - "matrix_hookshot_provisioning_secret" - name: (Deprecation) Catch and report old metrics usage - fail: + ansible.builtin.fail: msg: >- Your configuration contains a variable (`{{ item }}`), which refers to the old metrics collection system for Hookshot, which exposed metrics on `https://stats.DOMAIN/hookshot/metrics`. diff --git a/roles/matrix-bridge-mautrix-facebook/defaults/main.yml b/roles/matrix-bridge-mautrix-facebook/defaults/main.yml index 7993550fa..51b4f357d 100644 --- a/roles/matrix-bridge-mautrix-facebook/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-facebook/defaults/main.yml @@ -110,11 +110,11 @@ matrix_mautrix_facebook_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_facebook_configuration_yaml`. -matrix_mautrix_facebook_configuration_extension: "{{ matrix_mautrix_facebook_configuration_extension_yaml|from_yaml if matrix_mautrix_facebook_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_facebook_configuration_extension: "{{ matrix_mautrix_facebook_configuration_extension_yaml | from_yaml if matrix_mautrix_facebook_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_facebook_configuration_yaml`. -matrix_mautrix_facebook_configuration: "{{ matrix_mautrix_facebook_configuration_yaml|from_yaml|combine(matrix_mautrix_facebook_configuration_extension, recursive=True) }}" +matrix_mautrix_facebook_configuration: "{{ matrix_mautrix_facebook_configuration_yaml | from_yaml | combine(matrix_mautrix_facebook_configuration_extension, recursive=True) }}" matrix_mautrix_facebook_registration_yaml: | id: facebook @@ -123,13 +123,13 @@ matrix_mautrix_facebook_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@facebook_.+:{{ matrix_mautrix_facebook_homeserver_domain|regex_escape }}$' + regex: '^@facebook_.+:{{ matrix_mautrix_facebook_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_facebook_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_facebook_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_facebook_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_facebook_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_facebook_appservice_address }} # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_facebook_appservice_bot_username }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_facebook_registration: "{{ matrix_mautrix_facebook_registration_yaml|from_yaml }}" +matrix_mautrix_facebook_registration: "{{ matrix_mautrix_facebook_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-facebook/tasks/init.yml b/roles/matrix-bridge-mautrix-facebook/tasks/init.yml index f2cd59632..a5debc0b7 100644 --- a/roles/matrix-bridge-mautrix-facebook/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-facebook/tasks/init.yml @@ -2,46 +2,46 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mautrix_facebook_container_image_self_build and matrix_mautrix_facebook_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-facebook.service'] }}" - when: matrix_mautrix_facebook_enabled|bool + when: matrix_mautrix_facebook_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mautrix_facebook_config_path }}/registration.yaml,dst=/matrix-mautrix-facebook-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mautrix-facebook-registration.yaml"] }} - when: matrix_mautrix_facebook_enabled|bool + when: matrix_mautrix_facebook_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Mautrix Facebook'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-facebook role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Mautrix Facebook proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mautrix_facebook_matrix_nginx_proxy_configuration: | location {{ matrix_mautrix_facebook_public_endpoint }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-mautrix-facebook:29319"; @@ -53,24 +53,24 @@ } - name: Register Mautrix Facebook proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mautrix_facebook_matrix_nginx_proxy_configuration] }} - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Mautrix Facebook bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mautrix_facebook_public_endpoint }}` URL endpoint to the matrix-mautrix-facebook container. You can expose the container's port using the `matrix_mautrix_facebook_container_http_host_bind_port` variable. - when: "not matrix_nginx_proxy_enabled|default(False)|bool" + when: "not matrix_nginx_proxy_enabled | default(False) | bool" tags: - always - when: matrix_mautrix_facebook_enabled|bool and matrix_mautrix_facebook_appservice_public_enabled|bool + when: matrix_mautrix_facebook_enabled | bool and matrix_mautrix_facebook_appservice_public_enabled | bool diff --git a/roles/matrix-bridge-mautrix-facebook/tasks/main.yml b/roles/matrix-bridge-mautrix-facebook/tasks/main.yml index b6e65fe28..3ef2cb233 100644 --- a/roles/matrix-bridge-mautrix-facebook/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-facebook/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_facebook_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_facebook_enabled | bool" tags: - setup-all - setup-mautrix-facebook -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_facebook_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_facebook_enabled | bool" tags: - setup-all - setup-mautrix-facebook -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_facebook_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_facebook_enabled | bool" tags: - setup-all - setup-mautrix-facebook diff --git a/roles/matrix-bridge-mautrix-facebook/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-facebook/tasks/setup_install.yml index 699ed88a0..3e7d8f051 100644 --- a/roles/matrix-bridge-mautrix-facebook/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-facebook/tasks/setup_install.yml @@ -3,35 +3,37 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mautrix-facebook role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_facebook_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_facebook_sqlite_database_path_local }}" register: matrix_mautrix_facebook_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mautrix_facebook_sqlite_database_path_local }}" dst: "{{ matrix_mautrix_facebook_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mautrix_facebook_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mautrix-facebook.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mautrix_facebook_requires_restart: true - when: "matrix_mautrix_facebook_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mautrix_facebook_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mautrix_facebook_database_engine == 'postgres'" - name: Ensure Mautrix Facebook image is pulled @@ -47,7 +49,7 @@ until: result is not failed - name: Ensure Mautrix Facebook paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -58,10 +60,10 @@ - {path: "{{ matrix_mautrix_facebook_config_path }}", when: true} - {path: "{{ matrix_mautrix_facebook_data_path }}", when: true} - {path: "{{ matrix_mautrix_facebook_docker_src_files_path }}", when: "{{ matrix_mautrix_facebook_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Mautrix Facebook repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_facebook_container_image_self_build_repo }}" dest: "{{ matrix_mautrix_facebook_docker_src_files_path }}" version: "{{ matrix_mautrix_facebook_docker_image.split(':')[1] }}" @@ -69,7 +71,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_facebook_git_pull_results - when: "matrix_mautrix_facebook_container_image_self_build|bool" + when: "matrix_mautrix_facebook_container_image_self_build | bool" - name: Ensure Mautrix Facebook Docker image is built docker_image: @@ -81,15 +83,15 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_facebook_docker_src_files_path }}" pull: true - when: "matrix_mautrix_facebook_container_image_self_build|bool" + when: "matrix_mautrix_facebook_container_image_self_build | bool" - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_facebook_base_path }}/mautrix-facebook.db" register: matrix_mautrix_facebook_stat_database - name: (Data relocation) Ensure matrix-mautrix-facebook.service is stopped - service: + ansible.builtin.service: name: matrix-mautrix-facebook state: stopped enabled: false @@ -98,39 +100,39 @@ when: "matrix_mautrix_facebook_stat_database.stat.exists" - name: (Data relocation) Move mautrix-facebook database file to ./data directory - command: "mv {{ matrix_mautrix_facebook_base_path }}/mautrix-facebook.db {{ matrix_mautrix_facebook_data_path }}/mautrix-facebook.db" + ansible.builtin.command: "mv {{ matrix_mautrix_facebook_base_path }}/mautrix-facebook.db {{ matrix_mautrix_facebook_data_path }}/mautrix-facebook.db" when: "matrix_mautrix_facebook_stat_database.stat.exists" - name: Ensure mautrix-facebook config.yaml installed - copy: - content: "{{ matrix_mautrix_facebook_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_facebook_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_facebook_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-facebook registration.yaml installed - copy: - content: "{{ matrix_mautrix_facebook_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_facebook_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_facebook_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-facebook.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-facebook.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-facebook.service" mode: 0644 register: matrix_mautrix_facebook_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-facebook.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_facebook_systemd_service_result.changed" - name: Ensure matrix-mautrix-facebook.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-facebook.service" state: restarted - when: "matrix_mautrix_facebook_requires_restart|bool" + when: "matrix_mautrix_facebook_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-facebook/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-facebook/tasks/setup_uninstall.yml index 1c8fbd3b6..2635f1f55 100644 --- a/roles/matrix-bridge-mautrix-facebook/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-facebook/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mautrix-facebook service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-facebook.service" register: matrix_mautrix_facebook_service_stat - name: Ensure matrix-mautrix-facebook is stopped - service: + ansible.builtin.service: name: matrix-mautrix-facebook state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mautrix_facebook_service_stat.stat.exists" - name: Ensure matrix-mautrix-facebook.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-facebook.service" state: absent when: "matrix_mautrix_facebook_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-facebook.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_facebook_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-facebook/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-facebook/tasks/validate_config.yml index 7fcd6bead..4f588b5f5 100644 --- a/roles/matrix-bridge-mautrix-facebook/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-facebook/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -12,10 +12,10 @@ - block: - name: Inject warning if on an old SQLite-supporting version - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your mautrix-facebook bridge is still on SQLite and on the last version that supported it, before support was dropped. Support has been subsequently re-added in v0.3.2, so we advise you to upgrade (by removing your `matrix_mautrix_facebook_docker_image` definition from vars.yml)" diff --git a/roles/matrix-bridge-mautrix-googlechat/defaults/main.yml b/roles/matrix-bridge-mautrix-googlechat/defaults/main.yml index 5b93741a9..85d534e54 100644 --- a/roles/matrix-bridge-mautrix-googlechat/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-googlechat/defaults/main.yml @@ -6,6 +6,7 @@ matrix_mautrix_googlechat_enabled: true matrix_mautrix_googlechat_container_image_self_build: false matrix_mautrix_googlechat_container_image_self_build_repo: "https://github.com/mautrix/googlechat.git" +matrix_mautrix_googlechat_container_image_self_build_repo_version: "{{ 'master' if matrix_mautrix_googlechat_version == 'latest' else matrix_mautrix_googlechat_version }}" matrix_mautrix_googlechat_version: v0.3.3 # See: https://mau.dev/mautrix/googlechat/container_registry @@ -99,11 +100,11 @@ matrix_mautrix_googlechat_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_googlechat_configuration_yaml`. -matrix_mautrix_googlechat_configuration_extension: "{{ matrix_mautrix_googlechat_configuration_extension_yaml|from_yaml if matrix_mautrix_googlechat_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_googlechat_configuration_extension: "{{ matrix_mautrix_googlechat_configuration_extension_yaml | from_yaml if matrix_mautrix_googlechat_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_googlechat_configuration_yaml`. -matrix_mautrix_googlechat_configuration: "{{ matrix_mautrix_googlechat_configuration_yaml|from_yaml|combine(matrix_mautrix_googlechat_configuration_extension, recursive=True) }}" +matrix_mautrix_googlechat_configuration: "{{ matrix_mautrix_googlechat_configuration_yaml | from_yaml | combine(matrix_mautrix_googlechat_configuration_extension, recursive=True) }}" matrix_mautrix_googlechat_registration_yaml: | id: googlechat @@ -112,13 +113,13 @@ matrix_mautrix_googlechat_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@googlechat_.+:{{ matrix_mautrix_googlechat_homeserver_domain|regex_escape }}$' + regex: '^@googlechat_.+:{{ matrix_mautrix_googlechat_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_googlechat_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_googlechat_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_googlechat_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_googlechat_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_googlechat_appservice_address }} # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_googlechat_appservice_bot_username }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_googlechat_registration: "{{ matrix_mautrix_googlechat_registration_yaml|from_yaml }}" +matrix_mautrix_googlechat_registration: "{{ matrix_mautrix_googlechat_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-googlechat/tasks/init.yml b/roles/matrix-bridge-mautrix-googlechat/tasks/init.yml index 27845148e..af1e7d30a 100644 --- a/roles/matrix-bridge-mautrix-googlechat/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-googlechat/tasks/init.yml @@ -2,46 +2,46 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mautrix_googlechat_container_image_self_build and matrix_mautrix_googlechat_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-googlechat.service'] }}" - when: matrix_mautrix_googlechat_enabled|bool + when: matrix_mautrix_googlechat_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mautrix_googlechat_config_path }}/registration.yaml,dst=/matrix-mautrix-googlechat-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mautrix-googlechat-registration.yaml"] }} - when: matrix_mautrix_googlechat_enabled|bool + when: matrix_mautrix_googlechat_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Mautrix googlechat'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-googlechat role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Mautrix googlechat proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mautrix_googlechat_matrix_nginx_proxy_configuration: | location {{ matrix_mautrix_googlechat_public_endpoint }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-mautrix-googlechat:8080"; @@ -52,23 +52,23 @@ {% endif %} } - name: Register Mautrix googlechat proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mautrix_googlechat_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_mautrix_googlechat_enabled|bool + when: matrix_mautrix_googlechat_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Mautrix googlechat bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mautrix_googlechat_public_endpoint }}` URL endpoint to the matrix-mautrix-googlechat container. You can expose the container's port using the `matrix_mautrix_googlechat_container_http_host_bind_port` variable. - when: "matrix_mautrix_googlechat_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_mautrix_googlechat_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-mautrix-googlechat/tasks/main.yml b/roles/matrix-bridge-mautrix-googlechat/tasks/main.yml index 16054e7b5..070abfcd9 100644 --- a/roles/matrix-bridge-mautrix-googlechat/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-googlechat/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_googlechat_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_googlechat_enabled | bool" tags: - setup-all - setup-mautrix-googlechat -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_googlechat_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_googlechat_enabled | bool" tags: - setup-all - setup-mautrix-googlechat -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_googlechat_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_googlechat_enabled | bool" tags: - setup-all - setup-mautrix-googlechat diff --git a/roles/matrix-bridge-mautrix-googlechat/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-googlechat/tasks/setup_install.yml index bf04e834c..f2192a342 100644 --- a/roles/matrix-bridge-mautrix-googlechat/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-googlechat/tasks/setup_install.yml @@ -3,35 +3,37 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mautrix-googlechat role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_googlechat_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}" register: matrix_mautrix_googlechat_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}" dst: "{{ matrix_mautrix_googlechat_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mautrix_googlechat_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mautrix-googlechat.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mautrix_googlechat_requires_restart: true - when: "matrix_mautrix_googlechat_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mautrix_googlechat_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mautrix_googlechat_database_engine == 'postgres'" - name: Ensure Mautrix googlechat image is pulled @@ -47,7 +49,7 @@ until: result is not failed - name: Ensure Mautrix googlechat paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -58,17 +60,18 @@ - {path: "{{ matrix_mautrix_googlechat_config_path }}", when: true} - {path: "{{ matrix_mautrix_googlechat_data_path }}", when: true} - {path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}", when: "{{ matrix_mautrix_googlechat_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Mautrix Hangots repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_googlechat_container_image_self_build_repo }}" + version: "{{ matrix_mautrix_googlechat_container_image_self_build_repo_version }}" dest: "{{ matrix_mautrix_googlechat_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_googlechat_git_pull_results - when: "matrix_mautrix_googlechat_container_image_self_build|bool" + when: "matrix_mautrix_googlechat_container_image_self_build | bool" - name: Ensure Mautrix googlechat Docker image is built docker_image: @@ -80,15 +83,15 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}" pull: true - when: "matrix_mautrix_googlechat_container_image_self_build|bool" + when: "matrix_mautrix_googlechat_container_image_self_build | bool" - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db" register: matrix_mautrix_googlechat_stat_database - name: (Data relocation) Ensure matrix-mautrix-googlechat.service is stopped - service: + ansible.builtin.service: name: matrix-mautrix-googlechat state: stopped enabled: false @@ -97,39 +100,39 @@ when: "matrix_mautrix_googlechat_stat_database.stat.exists" - name: (Data relocation) Move mautrix-googlechat database file to ./data directory - command: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db" + ansible.builtin.command: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db" when: "matrix_mautrix_googlechat_stat_database.stat.exists" - name: Ensure mautrix-googlechat config.yaml installed - copy: - content: "{{ matrix_mautrix_googlechat_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_googlechat_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_googlechat_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-googlechat registration.yaml installed - copy: - content: "{{ matrix_mautrix_googlechat_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_googlechat_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_googlechat_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-googlechat.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-googlechat.service" mode: 0644 register: matrix_mautrix_googlechat_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-googlechat.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_googlechat_systemd_service_result.changed" - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-googlechat.service" state: restarted - when: "matrix_mautrix_googlechat_requires_restart|bool" + when: "matrix_mautrix_googlechat_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-googlechat/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-googlechat/tasks/setup_uninstall.yml index a315c0c84..104e58a5f 100644 --- a/roles/matrix-bridge-mautrix-googlechat/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-googlechat/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mautrix-googlechat service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-googlechat.service" register: matrix_mautrix_googlechat_service_stat - name: Ensure matrix-mautrix-googlechat is stopped - service: + ansible.builtin.service: name: matrix-mautrix-googlechat state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mautrix_googlechat_service_stat.stat.exists" - name: Ensure matrix-mautrix-googlechat.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-googlechat.service" state: absent when: "matrix_mautrix_googlechat_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-googlechat.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_googlechat_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-googlechat/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-googlechat/tasks/validate_config.yml index 083e8d342..fc36472eb 100644 --- a/roles/matrix-bridge-mautrix-googlechat/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-googlechat/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -9,6 +9,6 @@ - "matrix_mautrix_googlechat_public_endpoint" - "matrix_mautrix_googlechat_appservice_token" - "matrix_mautrix_googlechat_homeserver_token" -- debug: +- ansible.builtin.debug: msg: - '`matrix_mautrix_googlechat_homeserver_domain` == {{ matrix_mautrix_googlechat_homeserver_domain }}' diff --git a/roles/matrix-bridge-mautrix-hangouts/defaults/main.yml b/roles/matrix-bridge-mautrix-hangouts/defaults/main.yml index 061fa56ab..fc467871c 100644 --- a/roles/matrix-bridge-mautrix-hangouts/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-hangouts/defaults/main.yml @@ -6,6 +6,7 @@ matrix_mautrix_hangouts_enabled: true matrix_mautrix_hangouts_container_image_self_build: false matrix_mautrix_hangouts_container_image_self_build_repo: "https://github.com/mautrix/hangouts.git" +matrix_mautrix_hangouts_container_image_self_build_repo_version: "{{ 'master' if matrix_mautrix_hangouts_version == 'latest' else matrix_mautrix_googlechat_version }}" matrix_mautrix_hangouts_version: latest # See: https://mau.dev/mautrix/hangouts/container_registry @@ -96,11 +97,11 @@ matrix_mautrix_hangouts_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_hangouts_configuration_yaml`. -matrix_mautrix_hangouts_configuration_extension: "{{ matrix_mautrix_hangouts_configuration_extension_yaml|from_yaml if matrix_mautrix_hangouts_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_hangouts_configuration_extension: "{{ matrix_mautrix_hangouts_configuration_extension_yaml | from_yaml if matrix_mautrix_hangouts_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_hangouts_configuration_yaml`. -matrix_mautrix_hangouts_configuration: "{{ matrix_mautrix_hangouts_configuration_yaml|from_yaml|combine(matrix_mautrix_hangouts_configuration_extension, recursive=True) }}" +matrix_mautrix_hangouts_configuration: "{{ matrix_mautrix_hangouts_configuration_yaml | from_yaml | combine(matrix_mautrix_hangouts_configuration_extension, recursive=True) }}" matrix_mautrix_hangouts_registration_yaml: | id: hangouts @@ -109,13 +110,13 @@ matrix_mautrix_hangouts_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@hangouts_.+:{{ matrix_mautrix_hangouts_homeserver_domain|regex_escape }}$' + regex: '^@hangouts_.+:{{ matrix_mautrix_hangouts_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_hangouts_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_hangouts_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_hangouts_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_hangouts_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_hangouts_appservice_address }} # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_hangouts_appservice_bot_username }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_hangouts_registration: "{{ matrix_mautrix_hangouts_registration_yaml|from_yaml }}" +matrix_mautrix_hangouts_registration: "{{ matrix_mautrix_hangouts_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-hangouts/tasks/init.yml b/roles/matrix-bridge-mautrix-hangouts/tasks/init.yml index d00e52528..28ca1cdbc 100644 --- a/roles/matrix-bridge-mautrix-hangouts/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-hangouts/tasks/init.yml @@ -2,46 +2,46 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mautrix_hangouts_container_image_self_build and matrix_mautrix_hangouts_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-hangouts.service'] }}" - when: matrix_mautrix_hangouts_enabled|bool + when: matrix_mautrix_hangouts_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mautrix_hangouts_config_path }}/registration.yaml,dst=/matrix-mautrix-hangouts-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mautrix-hangouts-registration.yaml"] }} - when: matrix_mautrix_hangouts_enabled|bool + when: matrix_mautrix_hangouts_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Mautrix Hangouts'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-hangouts role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Mautrix Hangouts proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mautrix_hangouts_matrix_nginx_proxy_configuration: | location {{ matrix_mautrix_hangouts_public_endpoint }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-mautrix-hangouts:8080"; @@ -52,23 +52,23 @@ {% endif %} } - name: Register Mautrix Hangouts proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mautrix_hangouts_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_mautrix_hangouts_enabled|bool + when: matrix_mautrix_hangouts_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Mautrix Hangouts bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mautrix_hangouts_public_endpoint }}` URL endpoint to the matrix-mautrix-hangouts container. You can expose the container's port using the `matrix_mautrix_hangouts_container_http_host_bind_port` variable. - when: "matrix_mautrix_hangouts_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_mautrix_hangouts_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-mautrix-hangouts/tasks/main.yml b/roles/matrix-bridge-mautrix-hangouts/tasks/main.yml index b43ff478b..d69136899 100644 --- a/roles/matrix-bridge-mautrix-hangouts/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-hangouts/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_hangouts_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_hangouts_enabled | bool" tags: - setup-all - setup-mautrix-hangouts -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_hangouts_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_hangouts_enabled | bool" tags: - setup-all - setup-mautrix-hangouts -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_hangouts_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_hangouts_enabled | bool" tags: - setup-all - setup-mautrix-hangouts diff --git a/roles/matrix-bridge-mautrix-hangouts/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-hangouts/tasks/setup_install.yml index 6a8808159..4087162e2 100644 --- a/roles/matrix-bridge-mautrix-hangouts/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-hangouts/tasks/setup_install.yml @@ -3,35 +3,37 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mautrix-hangouts role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_hangouts_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_hangouts_sqlite_database_path_local }}" register: matrix_mautrix_hangouts_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mautrix_hangouts_sqlite_database_path_local }}" dst: "{{ matrix_mautrix_hangouts_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mautrix_hangouts_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mautrix-hangouts.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mautrix_hangouts_requires_restart: true - when: "matrix_mautrix_hangouts_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mautrix_hangouts_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mautrix_hangouts_database_engine == 'postgres'" - name: Ensure Mautrix Hangouts image is pulled @@ -47,7 +49,7 @@ until: result is not failed - name: Ensure Mautrix Hangouts paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -58,17 +60,18 @@ - {path: "{{ matrix_mautrix_hangouts_config_path }}", when: true} - {path: "{{ matrix_mautrix_hangouts_data_path }}", when: true} - {path: "{{ matrix_mautrix_hangouts_docker_src_files_path }}", when: "{{ matrix_mautrix_hangouts_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Mautrix Hangots repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_hangouts_container_image_self_build_repo }}" + version: "{{ matrix_mautrix_hangouts_container_image_self_build_repo_version }}" dest: "{{ matrix_mautrix_hangouts_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_hangouts_git_pull_results - when: "matrix_mautrix_hangouts_container_image_self_build|bool" + when: "matrix_mautrix_hangouts_container_image_self_build | bool" - name: Ensure Mautrix Hangouts Docker image is built docker_image: @@ -80,15 +83,15 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_hangouts_docker_src_files_path }}" pull: true - when: "matrix_mautrix_hangouts_container_image_self_build|bool" + when: "matrix_mautrix_hangouts_container_image_self_build | bool" - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_hangouts_base_path }}/mautrix-hangouts.db" register: matrix_mautrix_hangouts_stat_database - name: (Data relocation) Ensure matrix-mautrix-hangouts.service is stopped - service: + ansible.builtin.service: name: matrix-mautrix-hangouts state: stopped enabled: false @@ -97,39 +100,39 @@ when: "matrix_mautrix_hangouts_stat_database.stat.exists" - name: (Data relocation) Move mautrix-hangouts database file to ./data directory - command: "mv {{ matrix_mautrix_hangouts_base_path }}/mautrix-hangouts.db {{ matrix_mautrix_hangouts_data_path }}/mautrix-hangouts.db" + ansible.builtin.command: "mv {{ matrix_mautrix_hangouts_base_path }}/mautrix-hangouts.db {{ matrix_mautrix_hangouts_data_path }}/mautrix-hangouts.db" when: "matrix_mautrix_hangouts_stat_database.stat.exists" - name: Ensure mautrix-hangouts config.yaml installed - copy: - content: "{{ matrix_mautrix_hangouts_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_hangouts_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_hangouts_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-hangouts registration.yaml installed - copy: - content: "{{ matrix_mautrix_hangouts_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_hangouts_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_hangouts_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-hangouts.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-hangouts.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-hangouts.service" mode: 0644 register: matrix_mautrix_hangouts_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-hangouts.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_hangouts_systemd_service_result.changed" - name: Ensure matrix-mautrix-hangouts.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-hangouts.service" state: restarted - when: "matrix_mautrix_hangouts_requires_restart|bool" + when: "matrix_mautrix_hangouts_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-hangouts/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-hangouts/tasks/setup_uninstall.yml index 8ce859c8e..2cb676b5c 100644 --- a/roles/matrix-bridge-mautrix-hangouts/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-hangouts/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mautrix-hangouts service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-hangouts.service" register: matrix_mautrix_hangouts_service_stat - name: Ensure matrix-mautrix-hangouts is stopped - service: + ansible.builtin.service: name: matrix-mautrix-hangouts state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mautrix_hangouts_service_stat.stat.exists" - name: Ensure matrix-mautrix-hangouts.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-hangouts.service" state: absent when: "matrix_mautrix_hangouts_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-hangouts.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_hangouts_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-hangouts/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-hangouts/tasks/validate_config.yml index 0242ef16c..c80586e09 100644 --- a/roles/matrix-bridge-mautrix-hangouts/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-hangouts/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -9,6 +9,6 @@ - "matrix_mautrix_hangouts_public_endpoint" - "matrix_mautrix_hangouts_appservice_token" - "matrix_mautrix_hangouts_homeserver_token" -- debug: +- ansible.builtin.debug: msg: - '`matrix_mautrix_hangouts_homeserver_domain` == {{ matrix_mautrix_hangouts_homeserver_domain }}' diff --git a/roles/matrix-bridge-mautrix-instagram/defaults/main.yml b/roles/matrix-bridge-mautrix-instagram/defaults/main.yml index 5c849cfc7..e31f3f466 100644 --- a/roles/matrix-bridge-mautrix-instagram/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-instagram/defaults/main.yml @@ -6,6 +6,7 @@ matrix_mautrix_instagram_enabled: true matrix_mautrix_instagram_container_image_self_build: false matrix_mautrix_instagram_container_image_self_build_repo: "https://github.com/mautrix/instagram.git" +matrix_mautrix_instagram_container_image_self_build_repo_version: "{{ 'master' if matrix_mautrix_instagram_version == 'latest' else matrix_mautrix_instagram_version }}" matrix_mautrix_instagram_version: v0.1.3 # See: https://mau.dev/tulir/mautrix-instagram/container_registry @@ -89,11 +90,11 @@ matrix_mautrix_instagram_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_instagram_configuration_yaml`. -matrix_mautrix_instagram_configuration_extension: "{{ matrix_mautrix_instagram_configuration_extension_yaml|from_yaml if matrix_mautrix_instagram_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_instagram_configuration_extension: "{{ matrix_mautrix_instagram_configuration_extension_yaml | from_yaml if matrix_mautrix_instagram_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_instagram_configuration_yaml`. -matrix_mautrix_instagram_configuration: "{{ matrix_mautrix_instagram_configuration_yaml|from_yaml|combine(matrix_mautrix_instagram_configuration_extension, recursive=True) }}" +matrix_mautrix_instagram_configuration: "{{ matrix_mautrix_instagram_configuration_yaml | from_yaml | combine(matrix_mautrix_instagram_configuration_extension, recursive=True) }}" matrix_mautrix_instagram_registration_yaml: | id: instagram @@ -102,13 +103,13 @@ matrix_mautrix_instagram_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@instagram_.+:{{ matrix_mautrix_instagram_homeserver_domain|regex_escape }}$' + regex: '^@instagram_.+:{{ matrix_mautrix_instagram_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_instagram_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_instagram_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_instagram_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_instagram_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_instagram_appservice_address }} # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_instagram_appservice_bot_username }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_instagram_registration: "{{ matrix_mautrix_instagram_registration_yaml|from_yaml }}" +matrix_mautrix_instagram_registration: "{{ matrix_mautrix_instagram_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-instagram/tasks/init.yml b/roles/matrix-bridge-mautrix-instagram/tasks/init.yml index 867133809..858e29179 100644 --- a/roles/matrix-bridge-mautrix-instagram/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-instagram/tasks/init.yml @@ -2,27 +2,27 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mautrix_instagram_container_image_self_build and matrix_mautrix_instagram_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-instagram.service'] }}" - when: matrix_mautrix_instagram_enabled|bool + when: matrix_mautrix_instagram_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mautrix_instagram_config_path }}/registration.yaml,dst=/matrix-mautrix-instagram-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mautrix-instagram-registration.yaml"] }} - when: matrix_mautrix_instagram_enabled|bool + when: matrix_mautrix_instagram_enabled | bool diff --git a/roles/matrix-bridge-mautrix-instagram/tasks/main.yml b/roles/matrix-bridge-mautrix-instagram/tasks/main.yml index b6ffcd06a..d5becb6d3 100644 --- a/roles/matrix-bridge-mautrix-instagram/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-instagram/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_instagram_enabled | bool" tags: - setup-all - setup-mautrix-instagram -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_instagram_enabled | bool" tags: - setup-all - setup-mautrix-instagram -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_instagram_enabled | bool" tags: - setup-all - setup-mautrix-instagram diff --git a/roles/matrix-bridge-mautrix-instagram/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-instagram/tasks/setup_install.yml index 5e30adbe4..88b0286e7 100644 --- a/roles/matrix-bridge-mautrix-instagram/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-instagram/tasks/setup_install.yml @@ -2,10 +2,10 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mautrix-instagram role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure Mautrix instagram image is pulled docker_image: @@ -20,7 +20,7 @@ until: result is not failed - name: Ensure Mautrix instagram paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -31,17 +31,18 @@ - {path: "{{ matrix_mautrix_instagram_config_path }}", when: true} - {path: "{{ matrix_mautrix_instagram_data_path }}", when: true} - {path: "{{ matrix_mautrix_instagram_docker_src_files_path }}", when: "{{ matrix_mautrix_instagram_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Mautrix instagram repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_instagram_container_image_self_build_repo }}" + version: "{{ matrix_mautrix_instagram_container_image_self_build_repo_version }}" dest: "{{ matrix_mautrix_instagram_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_instagram_git_pull_results - when: "matrix_mautrix_instagram_container_image_self_build|bool" + when: "matrix_mautrix_instagram_container_image_self_build | bool" - name: Ensure Mautrix instagram Docker image is built docker_image: @@ -53,32 +54,32 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_instagram_docker_src_files_path }}" pull: true - when: "matrix_mautrix_instagram_container_image_self_build|bool" + when: "matrix_mautrix_instagram_container_image_self_build | bool" - name: Ensure mautrix-instagram config.yaml installed - copy: - content: "{{ matrix_mautrix_instagram_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_instagram_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_instagram_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-instagram registration.yaml installed - copy: - content: "{{ matrix_mautrix_instagram_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_instagram_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_instagram_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-instagram.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-instagram.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-instagram.service" mode: 0644 register: matrix_mautrix_instagram_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-instagram.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_instagram_systemd_service_result.changed" diff --git a/roles/matrix-bridge-mautrix-instagram/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-instagram/tasks/setup_uninstall.yml index 2cc0e0e93..55d882d32 100644 --- a/roles/matrix-bridge-mautrix-instagram/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-instagram/tasks/setup_uninstall.yml @@ -1,11 +1,11 @@ --- - name: Check existence of matrix-mautrix-instagram service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-instagram.service" register: matrix_mautrix_instagram_service_stat - name: Ensure matrix-mautrix-instagram is stopped - service: + ansible.builtin.service: name: matrix-mautrix-instagram state: stopped enabled: false @@ -13,12 +13,12 @@ when: "matrix_mautrix_instagram_service_stat.stat.exists" - name: Ensure matrix-mautrix-instagram.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-instagram.service" state: absent when: "matrix_mautrix_instagram_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-instagram.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_instagram_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-instagram/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-instagram/tasks/validate_config.yml index 24992ff56..99f7b0156 100644 --- a/roles/matrix-bridge-mautrix-instagram/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-instagram/tasks/validate_config.yml @@ -1,6 +1,6 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mautrix-signal/defaults/main.yml b/roles/matrix-bridge-mautrix-signal/defaults/main.yml index 3ed92dbcb..84ef38cd5 100644 --- a/roles/matrix-bridge-mautrix-signal/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-signal/defaults/main.yml @@ -6,6 +6,7 @@ matrix_mautrix_signal_enabled: true matrix_mautrix_signal_container_image_self_build: false matrix_mautrix_signal_docker_repo: "https://mau.dev/mautrix/signal.git" +matrix_mautrix_signal_docker_repo_version: "{{ 'master' if matrix_mautrix_signal_version == 'latest' else matrix_mautrix_signal_version }}" matrix_mautrix_signal_docker_src_files_path: "{{ matrix_base_data_path }}/mautrix-signal/docker-src" matrix_mautrix_signal_version: v0.3.0 @@ -16,6 +17,7 @@ matrix_mautrix_signal_docker_image_force_pull: "{{ matrix_mautrix_signal_docker_ matrix_mautrix_signal_daemon_container_image_self_build: false matrix_mautrix_signal_daemon_docker_repo: "https://gitlab.com/signald/signald" +matrix_mautrix_signal_daemon_docker_repo_version: "{{ 'master' if matrix_mautrix_signal_daemon_version == 'latest' else matrix_mautrix_signal_daemon_version }}" matrix_mautrix_signal_daemon_docker_src_files_path: "{{ matrix_base_data_path }}/mautrix-signald/docker-src" matrix_mautrix_signal_daemon_docker_image: "docker.io/signald/signald:{{ matrix_mautrix_signal_daemon_docker_image_tag }}" @@ -124,15 +126,15 @@ matrix_mautrix_signal_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_signal_configuration_yaml`. -matrix_mautrix_signal_configuration_extension: "{{ matrix_mautrix_signal_configuration_extension_yaml|from_yaml if matrix_mautrix_signal_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_signal_configuration_extension: "{{ matrix_mautrix_signal_configuration_extension_yaml | from_yaml if matrix_mautrix_signal_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_signal_configuration_yaml`. -matrix_mautrix_signal_configuration: "{{ matrix_mautrix_signal_configuration_yaml|from_yaml|combine(matrix_mautrix_signal_configuration_extension, recursive=True) }}" +matrix_mautrix_signal_configuration: "{{ matrix_mautrix_signal_configuration_yaml | from_yaml | combine(matrix_mautrix_signal_configuration_extension, recursive=True) }}" matrix_mautrix_signal_registration_yaml: "{{ lookup('template', 'templates/registration.yaml.j2') }}" -matrix_mautrix_signal_registration: "{{ matrix_mautrix_signal_registration_yaml|from_yaml }}" +matrix_mautrix_signal_registration: "{{ matrix_mautrix_signal_registration_yaml | from_yaml }}" matrix_mautrix_signal_log_level: 'DEBUG' diff --git a/roles/matrix-bridge-mautrix-signal/tasks/init.yml b/roles/matrix-bridge-mautrix-signal/tasks/init.yml index b9b698c57..c96fe596d 100644 --- a/roles/matrix-bridge-mautrix-signal/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-signal/tasks/init.yml @@ -1,22 +1,22 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-signal.service', 'matrix-mautrix-signal-daemon.service'] }}" - when: matrix_mautrix_signal_enabled|bool + when: matrix_mautrix_signal_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mautrix_signal_config_path }}/registration.yaml,dst=/matrix-mautrix-signal-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mautrix-signal-registration.yaml"] }} - when: matrix_mautrix_signal_enabled|bool + when: matrix_mautrix_signal_enabled | bool diff --git a/roles/matrix-bridge-mautrix-signal/tasks/main.yml b/roles/matrix-bridge-mautrix-signal/tasks/main.yml index 643b94c9c..54bdafcda 100644 --- a/roles/matrix-bridge-mautrix-signal/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-signal/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_signal_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_signal_enabled | bool" tags: - setup-all - setup-mautrix-signal -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_signal_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_signal_enabled | bool" tags: - setup-all - setup-mautrix-signal -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_signal_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_signal_enabled | bool" tags: - setup-all - setup-mautrix-signal diff --git a/roles/matrix-bridge-mautrix-signal/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-signal/tasks/setup_install.yml index 06f77348b..3a7ad508d 100644 --- a/roles/matrix-bridge-mautrix-signal/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-signal/tasks/setup_install.yml @@ -3,10 +3,10 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mautrix-signal role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure Mautrix Signal image is pulled docker_image: @@ -14,7 +14,7 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mautrix_signal_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_mautrix_signal_docker_image_force_pull }}" - when: "not matrix_mautrix_signal_container_image_self_build|bool" + when: "not matrix_mautrix_signal_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" @@ -22,14 +22,15 @@ - name: Ensure Mautrix Signal repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_signal_docker_repo }}" + version: "{{ matrix_mautrix_signal_docker_repo_version }}" dest: "{{ matrix_mautrix_signal_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_signal_git_pull_results - when: "matrix_mautrix_signal_container_image_self_build|bool" + when: "matrix_mautrix_signal_container_image_self_build | bool" - name: Ensure Mautrix Signal image is built docker_image: @@ -41,7 +42,7 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_signal_docker_src_files_path }}" pull: true - when: "matrix_mautrix_signal_container_image_self_build|bool" + when: "matrix_mautrix_signal_container_image_self_build | bool" - name: Ensure Mautrix Signal Daemon image is pulled @@ -50,18 +51,19 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mautrix_signal_daemon_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_mautrix_signal_daemon_docker_image_force_pull }}" - when: matrix_mautrix_signal_enabled and not matrix_mautrix_signal_daemon_container_image_self_build|bool + when: matrix_mautrix_signal_enabled and not matrix_mautrix_signal_daemon_container_image_self_build | bool register: matrix_mautrix_signal_daemon_pull_results - name: Ensure Mautrix Signal Daemon repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_signal_daemon_docker_repo }}" + version: "{{ matrix_mautrix_signal_daemon_docker_repo_version }}" dest: "{{ matrix_mautrix_signal_daemon_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_signal_daemon_git_pull_results - when: "matrix_mautrix_signal_daemon_container_image_self_build|bool" + when: "matrix_mautrix_signal_daemon_container_image_self_build | bool" - name: Ensure Mautrix Signal Daemon image is built docker_image: @@ -73,10 +75,10 @@ dockerfile: Containerfile path: "{{ matrix_mautrix_signal_daemon_docker_src_files_path }}" pull: true - when: "matrix_mautrix_signal_daemon_container_image_self_build|bool" + when: "matrix_mautrix_signal_daemon_container_image_self_build | bool" - name: Ensure Mautrix Signal paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -91,36 +93,36 @@ - "{{ matrix_mautrix_signal_daemon_path }}/data" - name: Ensure mautrix-signal config.yaml installed - copy: - content: "{{ matrix_mautrix_signal_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_signal_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_signal_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-signal registration.yaml installed - copy: - content: "{{ matrix_mautrix_signal_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_signal_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_signal_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-signal-daemon.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-signal-daemon.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-signal-daemon.service" mode: 0644 register: matrix_mautrix_signal_daemon_systemd_service_result - name: Ensure matrix-mautrix-signal.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-signal.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-signal.service" mode: 0644 register: matrix_mautrix_signal_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-signal.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_signal_systemd_service_result.changed or matrix_mautrix_signal_daemon_systemd_service_result.changed" diff --git a/roles/matrix-bridge-mautrix-signal/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-signal/tasks/setup_uninstall.yml index 8ca2be3fe..befbcbec2 100644 --- a/roles/matrix-bridge-mautrix-signal/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-signal/tasks/setup_uninstall.yml @@ -2,12 +2,12 @@ # Signal daemon service - name: Check existence of matrix-mautrix-signal-daemon service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-signal-daemon.service" register: matrix_mautrix_signal_daemon_service_stat - name: Ensure matrix-mautrix-signal-daemon is stopped - service: + ansible.builtin.service: name: matrix-mautrix-signal-daemon state: stopped enabled: false @@ -15,19 +15,19 @@ when: "matrix_mautrix_signal_daemon_service_stat.stat.exists" - name: Ensure matrix-mautrix-signal-daemon.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-signal-daemon.service" state: absent when: "matrix_mautrix_signal_daemon_service_stat.stat.exists" # Bridge service - name: Check existence of matrix-mautrix-signal service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-signal.service" register: matrix_mautrix_signal_service_stat - name: Ensure matrix-mautrix-signal is stopped - service: + ansible.builtin.service: name: matrix-mautrix-signal state: stopped enabled: false @@ -35,13 +35,13 @@ when: "matrix_mautrix_signal_service_stat.stat.exists" - name: Ensure matrix-mautrix-signal.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-signal.service" state: absent when: "matrix_mautrix_signal_service_stat.stat.exists" # All services - name: Ensure systemd reloaded after matrix-mautrix-signal_X.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_signal_service_stat.stat.exists or matrix_mautrix_signal_daemon_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-signal/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-signal/tasks/validate_config.yml index 108ac044d..01a02c2f3 100644 --- a/roles/matrix-bridge-mautrix-signal/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-signal/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -12,7 +12,7 @@ - "matrix_mautrix_signal_appservice_token" - name: (Deprecation) Catch and report renamed Signal variables - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-bridge-mautrix-signal/templates/registration.yaml.j2 b/roles/matrix-bridge-mautrix-signal/templates/registration.yaml.j2 index 32e913a19..5d6da2c44 100644 --- a/roles/matrix-bridge-mautrix-signal/templates/registration.yaml.j2 +++ b/roles/matrix-bridge-mautrix-signal/templates/registration.yaml.j2 @@ -5,12 +5,12 @@ hs_token: "{{ matrix_mautrix_signal_homeserver_token }}" namespaces: users: - exclusive: true - regex: '^@signal_.+:{{ matrix_mautrix_signal_homeserver_domain|regex_escape }}$' + regex: '^@signal_.+:{{ matrix_mautrix_signal_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_signal_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_signal_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_signal_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_signal_homeserver_domain | regex_escape }}$' aliases: - exclusive: true - regex: '^#signal_.+:{{ matrix_mautrix_signal_homeserver_domain|regex_escape }}$' + regex: '^#signal_.+:{{ matrix_mautrix_signal_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_signal_appservice_address }} # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_signal_appservice_bot_username }} diff --git a/roles/matrix-bridge-mautrix-telegram/defaults/main.yml b/roles/matrix-bridge-mautrix-telegram/defaults/main.yml index 97ba2bc97..2ac9fe04f 100644 --- a/roles/matrix-bridge-mautrix-telegram/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-telegram/defaults/main.yml @@ -7,11 +7,13 @@ matrix_mautrix_telegram_enabled: true matrix_telegram_lottieconverter_container_image_self_build: false matrix_telegram_lottieconverter_container_image_self_build_mask_arch: false matrix_telegram_lottieconverter_docker_repo: "https://mau.dev/tulir/lottieconverter.git" +matrix_telegram_lottieconverter_docker_repo_version: "master" matrix_telegram_lottieconverter_docker_src_files_path: "{{ matrix_base_data_path }}/lotticonverter/docker-src" matrix_telegram_lottieconverter_docker_image: "dock.mau.dev/tulir/lottieconverter:alpine-3.15" # needs to be ajusted according to FROM clause of Dockerfile of mautrix-telegram matrix_mautrix_telegram_container_image_self_build: false matrix_mautrix_telegram_docker_repo: "https://mau.dev/mautrix/telegram.git" +matrix_mautrix_telegram_docker_repo_version: "{{ 'master' if matrix_mautrix_telegram_version == 'latest' else matrix_mautrix_telegram_version }}" matrix_mautrix_telegram_docker_src_files_path: "{{ matrix_base_data_path }}/mautrix-telegram/docker-src" matrix_mautrix_telegram_version: v0.11.3 @@ -117,11 +119,11 @@ matrix_mautrix_telegram_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_telegram_configuration_yaml`. -matrix_mautrix_telegram_configuration_extension: "{{ matrix_mautrix_telegram_configuration_extension_yaml|from_yaml if matrix_mautrix_telegram_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_telegram_configuration_extension: "{{ matrix_mautrix_telegram_configuration_extension_yaml | from_yaml if matrix_mautrix_telegram_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_telegram_configuration_yaml`. -matrix_mautrix_telegram_configuration: "{{ matrix_mautrix_telegram_configuration_yaml|from_yaml|combine(matrix_mautrix_telegram_configuration_extension, recursive=True) }}" +matrix_mautrix_telegram_configuration: "{{ matrix_mautrix_telegram_configuration_yaml | from_yaml | combine(matrix_mautrix_telegram_configuration_extension, recursive=True) }}" matrix_mautrix_telegram_registration_yaml: | id: telegram @@ -130,19 +132,19 @@ matrix_mautrix_telegram_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@telegram_.+:{{ matrix_mautrix_telegram_homeserver_domain|regex_escape }}$' + regex: '^@telegram_.+:{{ matrix_mautrix_telegram_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_telegram_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_telegram_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_telegram_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_telegram_homeserver_domain | regex_escape }}$' aliases: - exclusive: true - regex: '^#telegram_.+:{{ matrix_mautrix_telegram_homeserver_domain|regex_escape }}$' + regex: '^#telegram_.+:{{ matrix_mautrix_telegram_homeserver_domain | regex_escape }}$' # See https://github.com/mautrix/signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_telegram_appservice_bot_username }} url: {{ matrix_mautrix_telegram_appservice_address }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_telegram_registration: "{{ matrix_mautrix_telegram_registration_yaml|from_yaml }}" +matrix_mautrix_telegram_registration: "{{ matrix_mautrix_telegram_registration_yaml | from_yaml }}" # Templates for defining MXID's and displaynames for users and rooms. matrix_mautrix_telegram_username_template: 'telegram_{userid}' diff --git a/roles/matrix-bridge-mautrix-telegram/tasks/init.yml b/roles/matrix-bridge-mautrix-telegram/tasks/init.yml index 93b4d9f85..e83bc6631 100644 --- a/roles/matrix-bridge-mautrix-telegram/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-telegram/tasks/init.yml @@ -2,46 +2,46 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mautrix_telegram_container_image_self_build and matrix_mautrix_telegram_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-telegram.service'] }}" - when: matrix_mautrix_telegram_enabled|bool + when: matrix_mautrix_telegram_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mautrix_telegram_config_path }}/registration.yaml,dst=/matrix-mautrix-telegram-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mautrix-telegram-registration.yaml"] }} - when: matrix_mautrix_telegram_enabled|bool + when: matrix_mautrix_telegram_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Mautrix Telegram'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 + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Mautrix Telegram proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mautrix_telegram_matrix_nginx_proxy_configuration: | location {{ matrix_mautrix_telegram_public_endpoint }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-mautrix-telegram:8080"; @@ -53,23 +53,23 @@ } - name: Register Mautrix Telegram proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mautrix_telegram_matrix_nginx_proxy_configuration] }} - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Mautrix Telegram bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mautrix_telegram_public_endpoint }}` URL endpoint to the matrix-mautrix-telegram container. You can expose the container's port using the `matrix_mautrix_telegram_container_http_host_bind_port` variable. - when: "not matrix_nginx_proxy_enabled|default(False)|bool" + when: "not matrix_nginx_proxy_enabled | default(False) | bool" tags: - always - when: matrix_mautrix_telegram_enabled|bool and matrix_mautrix_telegram_appservice_public_enabled|bool + when: matrix_mautrix_telegram_enabled | bool and matrix_mautrix_telegram_appservice_public_enabled | bool diff --git a/roles/matrix-bridge-mautrix-telegram/tasks/main.yml b/roles/matrix-bridge-mautrix-telegram/tasks/main.yml index 018b30da4..471f0cf13 100644 --- a/roles/matrix-bridge-mautrix-telegram/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-telegram/tasks/main.yml @@ -1,22 +1,22 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_telegram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_telegram_enabled | bool" tags: - setup-all - setup-mautrix-telegram -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_telegram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_telegram_enabled | bool" tags: - setup-all - setup-mautrix-telegram -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_telegram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_telegram_enabled | bool" tags: - setup-all - setup-mautrix-telegram diff --git a/roles/matrix-bridge-mautrix-telegram/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-telegram/tasks/setup_install.yml index 55e7d016f..6ce396573 100644 --- a/roles/matrix-bridge-mautrix-telegram/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-telegram/tasks/setup_install.yml @@ -3,39 +3,41 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mautrix-telegram role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_telegram_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_telegram_sqlite_database_path_local }}" register: matrix_mautrix_telegram_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mautrix_telegram_sqlite_database_path_local }}" dst: "{{ matrix_mautrix_telegram_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mautrix_telegram_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mautrix-telegram.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mautrix_telegram_requires_restart: true - when: "matrix_mautrix_telegram_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mautrix_telegram_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mautrix_telegram_database_engine == 'postgres'" - name: Ensure Mautrix Telegram paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -46,7 +48,7 @@ - {path: "{{ matrix_mautrix_telegram_config_path }}", when: true} - {path: "{{ matrix_mautrix_telegram_data_path }}", when: true} - {path: "{{ matrix_mautrix_telegram_docker_src_files_path }}", when: "{{ matrix_mautrix_telegram_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Mautrix Telegram image is pulled docker_image: @@ -54,21 +56,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mautrix_telegram_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_mautrix_telegram_docker_image_force_pull }}" - when: "not matrix_mautrix_telegram_container_image_self_build|bool" + when: "not matrix_mautrix_telegram_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure lottieconverter is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_telegram_lottieconverter_docker_repo }}" + version: "{{ matrix_telegram_lottieconverter_docker_repo_version }}" dest: "{{ matrix_telegram_lottieconverter_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_telegram_lottieconverter_git_pull_results - when: "matrix_telegram_lottieconverter_container_image_self_build|bool and matrix_mautrix_telegram_container_image_self_build|bool" + when: "matrix_telegram_lottieconverter_container_image_self_build | bool and matrix_mautrix_telegram_container_image_self_build | bool" - name: Ensure lottieconverter Docker image is built docker_image: @@ -80,17 +83,18 @@ dockerfile: Dockerfile path: "{{ matrix_telegram_lottieconverter_docker_src_files_path }}" pull: true - when: "matrix_telegram_lottieconverter_container_image_self_build|bool and matrix_telegram_lottieconverter_git_pull_results.changed and matrix_mautrix_telegram_container_image_self_build|bool" + when: "matrix_telegram_lottieconverter_container_image_self_build | bool and matrix_telegram_lottieconverter_git_pull_results.changed and matrix_mautrix_telegram_container_image_self_build | bool" - name: Ensure matrix-mautrix-telegram repository is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_telegram_docker_repo }}" + version: "{{ matrix_mautrix_telegram_docker_repo_version }}" dest: "{{ matrix_mautrix_telegram_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_telegram_git_pull_results - when: "matrix_mautrix_telegram_container_image_self_build|bool" + when: "matrix_mautrix_telegram_container_image_self_build | bool" - name: Ensure matrix-mautrix-telegram Docker image is built docker_image: @@ -101,18 +105,18 @@ build: dockerfile: Dockerfile path: "{{ matrix_mautrix_telegram_docker_src_files_path }}" - pull: "{{ not matrix_telegram_lottieconverter_container_image_self_build_mask_arch|bool }}" + pull: "{{ not matrix_telegram_lottieconverter_container_image_self_build_mask_arch | bool }}" args: TARGETARCH: "" - when: "matrix_mautrix_telegram_container_image_self_build|bool and matrix_mautrix_telegram_git_pull_results.changed" + when: "matrix_mautrix_telegram_container_image_self_build | bool and matrix_mautrix_telegram_git_pull_results.changed" - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db" register: matrix_mautrix_telegram_stat_database - name: (Data relocation) Ensure matrix-mautrix-telegram.service is stopped - service: + ansible.builtin.service: name: matrix-mautrix-telegram state: stopped enabled: false @@ -121,39 +125,39 @@ when: "matrix_mautrix_telegram_stat_database.stat.exists" - name: (Data relocation) Move mautrix-telegram database file to ./data directory - command: "mv {{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db {{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db" + ansible.builtin.command: "mv {{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db {{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db" when: "matrix_mautrix_telegram_stat_database.stat.exists" - name: Ensure mautrix-telegram config.yaml installed - copy: - content: "{{ matrix_mautrix_telegram_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_telegram_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_telegram_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-telegram registration.yaml installed - copy: - content: "{{ matrix_mautrix_telegram_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_telegram_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_telegram_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-telegram.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-telegram.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-telegram.service" mode: 0644 register: matrix_mautrix_telegram_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-telegram.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_telegram_systemd_service_result.changed" - name: Ensure matrix-mautrix-telegram.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-telegram.service" state: restarted - when: "matrix_mautrix_telegram_requires_restart|bool" + when: "matrix_mautrix_telegram_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-telegram/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-telegram/tasks/setup_uninstall.yml index a713898b9..f4a5f5690 100644 --- a/roles/matrix-bridge-mautrix-telegram/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-telegram/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mautrix-telegram service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-telegram.service" register: matrix_mautrix_telegram_service_stat - name: Ensure matrix-mautrix-telegram is stopped - service: + ansible.builtin.service: name: matrix-mautrix-telegram state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mautrix_telegram_service_stat.stat.exists" - name: Ensure matrix-mautrix-telegram.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-telegram.service" state: absent when: "matrix_mautrix_telegram_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-telegram.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_telegram_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-telegram/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-telegram/tasks/validate_config.yml index 2067b97b0..9711448bf 100644 --- a/roles/matrix-bridge-mautrix-telegram/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-telegram/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -13,7 +13,7 @@ - "matrix_mautrix_telegram_homeserver_token" - name: (Deprecation) Catch and report renamed Telegram variables - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-bridge-mautrix-twitter/defaults/main.yml b/roles/matrix-bridge-mautrix-twitter/defaults/main.yml index 150b5b4dc..512195cb3 100644 --- a/roles/matrix-bridge-mautrix-twitter/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-twitter/defaults/main.yml @@ -6,6 +6,7 @@ matrix_mautrix_twitter_enabled: true matrix_mautrix_twitter_container_image_self_build: false matrix_mautrix_twitter_container_image_self_build_repo: "https://github.com/mautrix/twitter.git" +matrix_mautrix_twitter_container_image_self_build_repo_version: "{{ 'master' if matrix_mautrix_twitter_version == 'latest' else matrix_mautrix_twitter_version }}" matrix_mautrix_twitter_version: v0.1.4 # See: https://mau.dev/tulir/mautrix-twitter/container_registry @@ -87,11 +88,11 @@ matrix_mautrix_twitter_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_twitter_configuration_yaml`. -matrix_mautrix_twitter_configuration_extension: "{{ matrix_mautrix_twitter_configuration_extension_yaml|from_yaml if matrix_mautrix_twitter_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_twitter_configuration_extension: "{{ matrix_mautrix_twitter_configuration_extension_yaml | from_yaml if matrix_mautrix_twitter_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_twitter_configuration_yaml`. -matrix_mautrix_twitter_configuration: "{{ matrix_mautrix_twitter_configuration_yaml|from_yaml|combine(matrix_mautrix_twitter_configuration_extension, recursive=True) }}" +matrix_mautrix_twitter_configuration: "{{ matrix_mautrix_twitter_configuration_yaml | from_yaml | combine(matrix_mautrix_twitter_configuration_extension, recursive=True) }}" matrix_mautrix_twitter_registration_yaml: | id: twitter @@ -100,13 +101,13 @@ matrix_mautrix_twitter_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@twitter_.+:{{ matrix_mautrix_twitter_homeserver_domain|regex_escape }}$' + regex: '^@twitter_.+:{{ matrix_mautrix_twitter_homeserver_domain | regex_escape }}$' - exclusive: true - regex: '^@{{ matrix_mautrix_twitter_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_twitter_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_twitter_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_twitter_homeserver_domain | regex_escape }}$' url: {{ matrix_mautrix_twitter_appservice_address }} # See https://github.com/tulir/mautrix-signal/issues/43 sender_localpart: _bot_{{ matrix_mautrix_twitter_appservice_bot_username }} rate_limited: false de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_twitter_registration: "{{ matrix_mautrix_twitter_registration_yaml|from_yaml }}" +matrix_mautrix_twitter_registration: "{{ matrix_mautrix_twitter_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-twitter/tasks/init.yml b/roles/matrix-bridge-mautrix-twitter/tasks/init.yml index 34f4ebde2..75a60ffa1 100644 --- a/roles/matrix-bridge-mautrix-twitter/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-twitter/tasks/init.yml @@ -1,29 +1,29 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-twitter.service'] }}" - when: matrix_mautrix_twitter_enabled|bool + when: matrix_mautrix_twitter_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mautrix_twitter_config_path }}/registration.yaml,dst=/matrix-mautrix-twitter-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mautrix-twitter-registration.yaml"] }} - when: matrix_mautrix_twitter_enabled|bool + when: matrix_mautrix_twitter_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: + ansible.builtin.fail: msg: "To self build Mautrix Twitter 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_mautrix_twitter_container_image_self_build" diff --git a/roles/matrix-bridge-mautrix-twitter/tasks/main.yml b/roles/matrix-bridge-mautrix-twitter/tasks/main.yml index 6c0abe4f5..2f0c39b2a 100644 --- a/roles/matrix-bridge-mautrix-twitter/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-twitter/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_twitter_enabled | bool" tags: - setup-all - setup-mautrix-twitter -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mautrix_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mautrix_twitter_enabled | bool" tags: - setup-all - setup-mautrix-twitter -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mautrix_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mautrix_twitter_enabled | bool" tags: - setup-all - setup-mautrix-twitter diff --git a/roles/matrix-bridge-mautrix-twitter/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-twitter/tasks/setup_install.yml index 552c9d525..05887c6d7 100644 --- a/roles/matrix-bridge-mautrix-twitter/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-twitter/tasks/setup_install.yml @@ -3,12 +3,12 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mautrix-twitter role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_twitter_requires_restart: false - name: Ensure Mautrix Twitter image is pulled @@ -17,14 +17,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mautrix_twitter_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_mautrix_twitter_docker_image_force_pull }}" - when: matrix_mautrix_twitter_enabled|bool and not matrix_mautrix_twitter_container_image_self_build + when: matrix_mautrix_twitter_enabled | bool and not matrix_mautrix_twitter_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Mautrix Twitter paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -35,18 +35,18 @@ - {path: "{{ matrix_mautrix_twitter_config_path }}", when: true} - {path: "{{ matrix_mautrix_twitter_data_path }}", when: true} - {path: "{{ matrix_mautrix_twitter_docker_src_files_path }}", when: "{{ matrix_mautrix_twitter_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Mautrix Twitter repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_twitter_container_image_self_build_repo }}" + version: "{{ matrix_mautrix_twitter_container_image_self_build_repo_version }}" dest: "{{ matrix_mautrix_twitter_docker_src_files_path }}" - # version: "{{ matrix_coturn_docker_image.split(':')[1] }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_twitter_git_pull_results - when: "matrix_mautrix_twitter_enabled|bool and matrix_mautrix_twitter_container_image_self_build" + when: "matrix_mautrix_twitter_enabled | bool and matrix_mautrix_twitter_container_image_self_build" - name: Ensure Mautrix Twitter Docker image is built docker_image: @@ -57,38 +57,38 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_twitter_docker_src_files_path }}" pull: true - when: "matrix_mautrix_twitter_enabled|bool and matrix_mautrix_twitter_container_image_self_build|bool" + when: "matrix_mautrix_twitter_enabled | bool and matrix_mautrix_twitter_container_image_self_build | bool" - name: Ensure mautrix-twitter config.yaml installed - copy: - content: "{{ matrix_mautrix_twitter_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_twitter_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_twitter_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-twitter registration.yaml installed - copy: - content: "{{ matrix_mautrix_twitter_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_twitter_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_twitter_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-twitter.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-twitter.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-twitter.service" mode: 0644 register: matrix_mautrix_twitter_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-twitter.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_twitter_systemd_service_result.changed" - name: Ensure matrix-mautrix-twitter.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-twitter.service" state: restarted - when: "matrix_mautrix_twitter_requires_restart|bool" + when: "matrix_mautrix_twitter_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-twitter/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-twitter/tasks/setup_uninstall.yml index 024603e71..5ce64906c 100644 --- a/roles/matrix-bridge-mautrix-twitter/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-twitter/tasks/setup_uninstall.yml @@ -1,24 +1,24 @@ --- - name: Check existence of matrix-mautrix-twitter service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-twitter.service" register: matrix_mautrix_twitter_service_stat - name: Ensure matrix-mautrix-twitter is stopped - service: + ansible.builtin.service: name: matrix-mautrix-twitter state: stopped daemon_reload: true when: "matrix_mautrix_twitter_service_stat.stat.exists" - name: Ensure matrix-mautrix-twitter.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-twitter.service" state: absent when: "matrix_mautrix_twitter_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-twitter.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_twitter_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-twitter/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-twitter/tasks/validate_config.yml index 5b6e3d020..326dca83a 100644 --- a/roles/matrix-bridge-mautrix-twitter/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-twitter/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mautrix-whatsapp/defaults/main.yml b/roles/matrix-bridge-mautrix-whatsapp/defaults/main.yml index e7f027091..7a511651e 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/defaults/main.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/defaults/main.yml @@ -106,11 +106,11 @@ matrix_mautrix_whatsapp_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mautrix_whatsapp_configuration_yaml`. -matrix_mautrix_whatsapp_configuration_extension: "{{ matrix_mautrix_whatsapp_configuration_extension_yaml|from_yaml if matrix_mautrix_whatsapp_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mautrix_whatsapp_configuration_extension: "{{ matrix_mautrix_whatsapp_configuration_extension_yaml | from_yaml if matrix_mautrix_whatsapp_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mautrix_whatsapp_configuration_yaml`. -matrix_mautrix_whatsapp_configuration: "{{ matrix_mautrix_whatsapp_configuration_yaml|from_yaml|combine(matrix_mautrix_whatsapp_configuration_extension, recursive=True) }}" +matrix_mautrix_whatsapp_configuration: "{{ matrix_mautrix_whatsapp_configuration_yaml | from_yaml | combine(matrix_mautrix_whatsapp_configuration_extension, recursive=True) }}" matrix_mautrix_whatsapp_registration_yaml: | id: whatsapp @@ -122,13 +122,13 @@ matrix_mautrix_whatsapp_registration_yaml: | rate_limited: false namespaces: users: - - regex: '^@whatsapp_[0-9]+:{{ matrix_mautrix_whatsapp_homeserver_domain|regex_escape }}$' + - regex: '^@whatsapp_[0-9]+:{{ matrix_mautrix_whatsapp_homeserver_domain | regex_escape }}$' exclusive: true - exclusive: true - regex: '^@{{ matrix_mautrix_whatsapp_appservice_bot_username|regex_escape }}:{{ matrix_mautrix_whatsapp_homeserver_domain|regex_escape }}$' + regex: '^@{{ matrix_mautrix_whatsapp_appservice_bot_username | regex_escape }}:{{ matrix_mautrix_whatsapp_homeserver_domain | regex_escape }}$' de.sorunome.msc2409.push_ephemeral: true -matrix_mautrix_whatsapp_registration: "{{ matrix_mautrix_whatsapp_registration_yaml|from_yaml }}" +matrix_mautrix_whatsapp_registration: "{{ matrix_mautrix_whatsapp_registration_yaml | from_yaml }}" # Enable End-to-bridge encryption matrix_mautrix_whatsapp_bridge_encryption_allow: false diff --git a/roles/matrix-bridge-mautrix-whatsapp/tasks/init.yml b/roles/matrix-bridge-mautrix-whatsapp/tasks/init.yml index d4fb82218..ab10a5303 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/tasks/init.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/tasks/init.yml @@ -1,21 +1,21 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-whatsapp.service'] }}" - when: matrix_mautrix_whatsapp_enabled|bool + when: matrix_mautrix_whatsapp_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mautrix_whatsapp_config_path }}/registration.yaml,dst=/matrix-mautrix-whatsapp-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mautrix-whatsapp-registration.yaml"] }} - when: matrix_mautrix_whatsapp_enabled|bool + when: matrix_mautrix_whatsapp_enabled | bool diff --git a/roles/matrix-bridge-mautrix-whatsapp/tasks/main.yml b/roles/matrix-bridge-mautrix-whatsapp/tasks/main.yml index 0a963eb24..4df6fd23b 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/tasks/main.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/tasks/main.yml @@ -1,21 +1,21 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mautrix_whatsapp_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mautrix_whatsapp_enabled | bool" tags: - setup-all - setup-mautrix-whatsapp -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" when: "run_setup and matrix_mautrix_whatsapp_enabled" tags: - setup-all - setup-mautrix-whatsapp -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" when: "run_setup and not matrix_mautrix_whatsapp_enabled" tags: - setup-all diff --git a/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_install.yml index f47675b58..c3edd6a75 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_install.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_install.yml @@ -3,41 +3,43 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mautrix-whatsapp role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mautrix_whatsapp_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_whatsapp_sqlite_database_path_local }}" register: matrix_mautrix_whatsapp_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mautrix_whatsapp_sqlite_database_path_local }}" dst: "{{ matrix_mautrix_whatsapp_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mautrix_whatsapp_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mautrix-whatsapp.service'] pgloader_options: ['--with "quote identifiers"'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mautrix_whatsapp_requires_restart: true - when: "matrix_mautrix_whatsapp_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mautrix_whatsapp_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mautrix_whatsapp_database_engine == 'postgres'" - name: Ensure Mautrix Whatsapp paths exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -48,7 +50,7 @@ - {path: "{{ matrix_mautrix_whatsapp_config_path }}", when: true} - {path: "{{ matrix_mautrix_whatsapp_data_path }}", when: true} - {path: "{{ matrix_mautrix_whatsapp_docker_src_files_path }}", when: "{{ matrix_mautrix_whatsapp_container_image_self_build }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Mautrix Whatsapp image is pulled docker_image: @@ -63,7 +65,7 @@ until: result is not failed - name: Ensure Mautrix Whatsapp repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mautrix_whatsapp_container_image_self_build_repo }}" dest: "{{ matrix_mautrix_whatsapp_docker_src_files_path }}" version: "{{ matrix_mautrix_whatsapp_container_image_self_build_branch }}" @@ -71,7 +73,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_mautrix_whatsapp_git_pull_results - when: "matrix_mautrix_whatsapp_container_image_self_build|bool" + when: "matrix_mautrix_whatsapp_container_image_self_build | bool" - name: Ensure Mautrix Whatsapp Docker image is built docker_image: @@ -83,20 +85,20 @@ dockerfile: Dockerfile path: "{{ matrix_mautrix_whatsapp_docker_src_files_path }}" pull: true - when: "matrix_mautrix_whatsapp_container_image_self_build|bool" + when: "matrix_mautrix_whatsapp_container_image_self_build | bool" - name: Check if an old database file exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_whatsapp_base_path }}/mautrix-whatsapp.db" register: matrix_mautrix_whatsapp_stat_database - name: Check if an old matrix state file exists - stat: + ansible.builtin.stat: path: "{{ matrix_mautrix_whatsapp_base_path }}/mx-state.json" register: matrix_mautrix_whatsapp_stat_mx_state - name: (Data relocation) Ensure matrix-mautrix-whatsapp.service is stopped - service: + ansible.builtin.service: name: matrix-mautrix-whatsapp state: stopped enabled: false @@ -105,43 +107,43 @@ when: "matrix_mautrix_whatsapp_stat_database.stat.exists" - name: (Data relocation) Move mautrix-whatsapp database file to ./data directory - command: "mv {{ matrix_mautrix_whatsapp_base_path }}/mautrix-whatsapp.db {{ matrix_mautrix_whatsapp_data_path }}/mautrix-whatsapp.db" + ansible.builtin.command: "mv {{ matrix_mautrix_whatsapp_base_path }}/mautrix-whatsapp.db {{ matrix_mautrix_whatsapp_data_path }}/mautrix-whatsapp.db" when: "matrix_mautrix_whatsapp_stat_database.stat.exists" - name: (Data relocation) Move mautrix-whatsapp mx-state file to ./data directory - command: "mv {{ matrix_mautrix_whatsapp_base_path }}/mx-state.json {{ matrix_mautrix_whatsapp_data_path }}/mx-state.json" + ansible.builtin.command: "mv {{ matrix_mautrix_whatsapp_base_path }}/mx-state.json {{ matrix_mautrix_whatsapp_data_path }}/mx-state.json" when: "matrix_mautrix_whatsapp_stat_mx_state.stat.exists" - name: Ensure mautrix-whatsapp config.yaml installed - copy: - content: "{{ matrix_mautrix_whatsapp_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_whatsapp_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_whatsapp_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mautrix-whatsapp registration.yaml installed - copy: - content: "{{ matrix_mautrix_whatsapp_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mautrix_whatsapp_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mautrix_whatsapp_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mautrix-whatsapp.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mautrix-whatsapp.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mautrix-whatsapp.service" mode: 0644 register: matrix_mautrix_whatsapp_systemd_service_result - name: Ensure systemd reloaded after matrix-mautrix-whatsapp.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_whatsapp_systemd_service_result.changed" - name: Ensure matrix-mautrix-whatsapp.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mautrix-whatsapp.service" state: restarted - when: "matrix_mautrix_whatsapp_requires_restart|bool" + when: "matrix_mautrix_whatsapp_requires_restart | bool" diff --git a/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_uninstall.yml index 3884f9e7e..c531b530e 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mautrix-whatsapp service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mautrix-whatsapp.service" register: matrix_mautrix_whatsapp_service_stat - name: Ensure matrix-mautrix-whatsapp is stopped - service: + ansible.builtin.service: name: matrix-mautrix-whatsapp state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mautrix_whatsapp_service_stat.stat.exists" - name: Ensure matrix-mautrix-whatsapp.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mautrix-whatsapp.service" state: absent when: "matrix_mautrix_whatsapp_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mautrix-whatsapp.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mautrix_whatsapp_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-whatsapp/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-whatsapp/tasks/validate_config.yml index 9b0a725c9..863dc926f 100644 --- a/roles/matrix-bridge-mautrix-whatsapp/tasks/validate_config.yml +++ b/roles/matrix-bridge-mautrix-whatsapp/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -11,7 +11,7 @@ - name: (Deprecation) Catch and report renamed settings - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-bridge-mx-puppet-discord/defaults/main.yml b/roles/matrix-bridge-mx-puppet-discord/defaults/main.yml index 4d297f25f..771af9922 100644 --- a/roles/matrix-bridge-mx-puppet-discord/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-discord/defaults/main.yml @@ -30,13 +30,13 @@ matrix_mx_puppet_discord_homeserver_address: "{{ matrix_homeserver_container_url matrix_mx_puppet_discord_homeserver_domain: '{{ matrix_domain }}' matrix_mx_puppet_discord_appservice_address: 'http://matrix-mx-puppet-discord:{{ matrix_mx_puppet_discord_appservice_port }}' -matrix_mx_puppet_discord_bridge_mediaUrl: "https://{{ matrix_server_fqn_matrix }}" +matrix_mx_puppet_discord_bridge_mediaUrl: "https://{{ matrix_server_fqn_matrix }}" # noqa var-naming # "@user:server.com" to allow specific user # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_discord_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -88,11 +88,11 @@ matrix_mx_puppet_discord_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_discord_configuration_yaml`. -matrix_mx_puppet_discord_configuration_extension: "{{ matrix_mx_puppet_discord_configuration_extension_yaml|from_yaml if matrix_mx_puppet_discord_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_discord_configuration_extension: "{{ matrix_mx_puppet_discord_configuration_extension_yaml | from_yaml if matrix_mx_puppet_discord_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_discord_configuration_yaml`. -matrix_mx_puppet_discord_configuration: "{{ matrix_mx_puppet_discord_configuration_yaml|from_yaml|combine(matrix_mx_puppet_discord_configuration_extension, recursive=True) }}" +matrix_mx_puppet_discord_configuration: "{{ matrix_mx_puppet_discord_configuration_yaml | from_yaml | combine(matrix_mx_puppet_discord_configuration_extension, recursive=True) }}" matrix_mx_puppet_discord_registration_yaml: | as_token: "{{ matrix_mx_puppet_discord_appservice_token }}" @@ -101,15 +101,15 @@ matrix_mx_puppet_discord_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_discordpuppet_.*:{{ matrix_mx_puppet_discord_homeserver_domain|regex_escape }}' + regex: '@_discordpuppet_.*:{{ matrix_mx_puppet_discord_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#_discordpuppet_.*:{{ matrix_mx_puppet_discord_homeserver_domain|regex_escape }}' + regex: '#_discordpuppet_.*:{{ matrix_mx_puppet_discord_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: _discordpuppet_bot url: {{ matrix_mx_puppet_discord_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_discord_registration: "{{ matrix_mx_puppet_discord_registration_yaml|from_yaml }}" +matrix_mx_puppet_discord_registration: "{{ matrix_mx_puppet_discord_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-discord/tasks/init.yml b/roles/matrix-bridge-mx-puppet-discord/tasks/init.yml index 115ccf353..1a821d7d8 100644 --- a/roles/matrix-bridge-mx-puppet-discord/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-discord/tasks/init.yml @@ -2,27 +2,27 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mx_puppet_discord_container_image_self_build and matrix_mx_puppet_discord_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-discord.service'] }}" - when: matrix_mx_puppet_discord_enabled|bool + when: matrix_mx_puppet_discord_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mx_puppet_discord_config_path }}/registration.yaml,dst=/matrix-mx-puppet-discord-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mx-puppet-discord-registration.yaml"] }} - when: matrix_mx_puppet_discord_enabled|bool + when: matrix_mx_puppet_discord_enabled | bool diff --git a/roles/matrix-bridge-mx-puppet-discord/tasks/main.yml b/roles/matrix-bridge-mx-puppet-discord/tasks/main.yml index e11a2db04..281092e1a 100644 --- a/roles/matrix-bridge-mx-puppet-discord/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-discord/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_discord_enabled | bool" tags: - setup-all - setup-mx-puppet-discord -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_discord_enabled | bool" tags: - setup-all - setup-mx-puppet-discord -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_discord_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_discord_enabled | bool" tags: - setup-all - setup-mx-puppet-discord diff --git a/roles/matrix-bridge-mx-puppet-discord/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-discord/tasks/setup_install.yml index 3ddfa39d5..d60f73f9f 100644 --- a/roles/matrix-bridge-mx-puppet-discord/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-discord/tasks/setup_install.yml @@ -3,13 +3,13 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mx-puppet-discord role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure MX Puppet Discord paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -20,49 +20,54 @@ - {path: "{{ matrix_mx_puppet_discord_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_discord_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_discord_docker_src_files_path }}", when: "{{ matrix_mx_puppet_discord_container_image_self_build }}"} - when: matrix_mx_puppet_discord_enabled|bool and item.when|bool + when: matrix_mx_puppet_discord_enabled | bool and item.when | bool - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_discord_base_path }}/database.db" register: matrix_mx_puppet_discord_stat_database - block: - name: (Data relocation) Ensure matrix-mx-puppet-discord.service is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-discord state: stopped daemon_reload: true failed_when: false - name: (Data relocation) Move mx-puppet-discord database file to ./data directory - command: "mv {{ matrix_mx_puppet_discord_base_path }}/database.db {{ matrix_mx_puppet_discord_data_path }}/database.db" + ansible.builtin.command: + cmd: "mv {{ matrix_mx_puppet_discord_base_path }}/database.db {{ matrix_mx_puppet_discord_data_path }}/database.db" + register: matrix_mx_puppet_discord_relocate_database_result + changed_when: matrix_mx_puppet_discord_relocate_database_result.rc == 0 when: "matrix_mx_puppet_discord_stat_database.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_discord_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_discord_sqlite_database_path_local }}" register: matrix_mx_puppet_discord_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_discord_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_discord_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_discord_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-discord.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_discord_requires_restart: true - when: "matrix_mx_puppet_discord_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_discord_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_discord_database_engine == 'postgres'" - name: Ensure MX Puppet Discord image is pulled @@ -71,14 +76,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_discord_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_mx_puppet_discord_docker_image_force_pull }}" - when: matrix_mx_puppet_discord_enabled|bool and not matrix_mx_puppet_discord_container_image_self_build + when: matrix_mx_puppet_discord_enabled | bool and not matrix_mx_puppet_discord_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure MX Puppet Discord repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_discord_container_image_self_build_repo }}" dest: "{{ matrix_mx_puppet_discord_docker_src_files_path }}" force: "yes" @@ -86,7 +91,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_discord_git_pull_results - when: "matrix_mx_puppet_discord_enabled|bool and matrix_mx_puppet_discord_container_image_self_build" + when: "matrix_mx_puppet_discord_enabled | bool and matrix_mx_puppet_discord_container_image_self_build" - name: Ensure MX Puppet Discord Docker image is built docker_image: @@ -98,38 +103,38 @@ dockerfile: "{{ matrix_mx_puppet_discord_container_image_self_build_dockerfile_path }}" path: "{{ matrix_mx_puppet_discord_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_discord_enabled|bool and matrix_mx_puppet_discord_container_image_self_build|bool" + when: "matrix_mx_puppet_discord_enabled | bool and matrix_mx_puppet_discord_container_image_self_build | bool" - name: Ensure mx-puppet-discord config.yaml installed - copy: - content: "{{ matrix_mx_puppet_discord_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_discord_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_discord_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-discord discord-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_discord_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_discord_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_discord_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-discord.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-discord.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-discord.service" mode: 0644 register: matrix_mx_puppet_discord_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-discord.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_discord_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-discord.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-discord.service" state: restarted - when: "matrix_mx_puppet_discord_requires_restart|bool" + when: "matrix_mx_puppet_discord_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-discord/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-discord/tasks/setup_uninstall.yml index b3ab8e39e..585c6c856 100644 --- a/roles/matrix-bridge-mx-puppet-discord/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-discord/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-discord service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-discord.service" register: matrix_mx_puppet_discord_service_stat - name: Ensure matrix-mx-puppet-discord is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-discord state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_discord_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-discord.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-discord.service" state: absent when: "matrix_mx_puppet_discord_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-discord.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_discord_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-discord/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-discord/tasks/validate_config.yml index c253eda29..e73a868a5 100644 --- a/roles/matrix-bridge-mx-puppet-discord/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-discord/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mx-puppet-groupme/defaults/main.yml b/roles/matrix-bridge-mx-puppet-groupme/defaults/main.yml index 696380ed1..a7016b303 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/defaults/main.yml @@ -6,6 +6,7 @@ matrix_mx_puppet_groupme_enabled: true matrix_mx_puppet_groupme_container_image_self_build: false matrix_mx_puppet_groupme_container_image_self_build_repo: "https://gitlab.com/robintown/mx-puppet-groupme" +matrix_mx_puppet_groupme_container_image_self_build_repo_version: "{{ 'main' if matrix_mx_puppet_groupme_version == 'latest' else matrix_mx_puppet_groupme_version }}" # Controls whether the mx-puppet-groupme container exposes its HTTP port (tcp/8437 in the container). # @@ -32,7 +33,7 @@ matrix_mx_puppet_groupme_appservice_address: 'http://matrix-mx-puppet-groupme:{{ # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_groupme_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -83,11 +84,11 @@ matrix_mx_puppet_groupme_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_groupme_configuration_yaml`. -matrix_mx_puppet_groupme_configuration_extension: "{{ matrix_mx_puppet_groupme_configuration_extension_yaml|from_yaml if matrix_mx_puppet_groupme_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_groupme_configuration_extension: "{{ matrix_mx_puppet_groupme_configuration_extension_yaml | from_yaml if matrix_mx_puppet_groupme_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_groupme_configuration_yaml`. -matrix_mx_puppet_groupme_configuration: "{{ matrix_mx_puppet_groupme_configuration_yaml|from_yaml|combine(matrix_mx_puppet_groupme_configuration_extension, recursive=True) }}" +matrix_mx_puppet_groupme_configuration: "{{ matrix_mx_puppet_groupme_configuration_yaml | from_yaml | combine(matrix_mx_puppet_groupme_configuration_extension, recursive=True) }}" matrix_mx_puppet_groupme_registration_yaml: | as_token: "{{ matrix_mx_puppet_groupme_appservice_token }}" @@ -96,15 +97,15 @@ matrix_mx_puppet_groupme_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_groupmepuppet_.*:{{ matrix_mx_puppet_groupme_homeserver_domain|regex_escape }}' + regex: '@_groupmepuppet_.*:{{ matrix_mx_puppet_groupme_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#_groupmepuppet_.*:{{ matrix_mx_puppet_groupme_homeserver_domain|regex_escape }}' + regex: '#_groupmepuppet_.*:{{ matrix_mx_puppet_groupme_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: _groupmepuppet_bot url: {{ matrix_mx_puppet_groupme_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_groupme_registration: "{{ matrix_mx_puppet_groupme_registration_yaml|from_yaml }}" +matrix_mx_puppet_groupme_registration: "{{ matrix_mx_puppet_groupme_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-groupme/tasks/init.yml b/roles/matrix-bridge-mx-puppet-groupme/tasks/init.yml index 9bada5d87..92f041d40 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/tasks/init.yml @@ -2,27 +2,27 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mx_puppet_groupme_container_image_self_build and matrix_mx_puppet_groupme_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-groupme.service'] }}" - when: matrix_mx_puppet_groupme_enabled|bool + when: matrix_mx_puppet_groupme_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mx_puppet_groupme_config_path }}/registration.yaml,dst=/matrix-mx-puppet-groupme-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mx-puppet-groupme-registration.yaml"] }} - when: matrix_mx_puppet_groupme_enabled|bool + when: matrix_mx_puppet_groupme_enabled | bool diff --git a/roles/matrix-bridge-mx-puppet-groupme/tasks/main.yml b/roles/matrix-bridge-mx-puppet-groupme/tasks/main.yml index 070f920b5..8cc557592 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_groupme_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_groupme_enabled | bool" tags: - setup-all - setup-mx-puppet-groupme -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_groupme_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_groupme_enabled | bool" tags: - setup-all - setup-mx-puppet-groupme -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_groupme_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_groupme_enabled | bool" tags: - setup-all - setup-mx-puppet-groupme diff --git a/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_install.yml index 286c5611c..497f0109b 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_install.yml @@ -3,13 +3,13 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mx-puppet-groupme role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure MX Puppet Groupme paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -20,15 +20,15 @@ - {path: "{{ matrix_mx_puppet_groupme_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_groupme_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_groupme_docker_src_files_path }}", when: "{{ matrix_mx_puppet_groupme_container_image_self_build }}"} - when: matrix_mx_puppet_groupme_enabled|bool and item.when|bool + when: matrix_mx_puppet_groupme_enabled | bool and item.when | bool - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_groupme_base_path }}/database.db" register: matrix_mx_puppet_groupme_stat_database - name: (Data relocation) Ensure matrix-mx-puppet-groupme.service is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-groupme state: stopped enabled: false @@ -37,33 +37,35 @@ when: "matrix_mx_puppet_groupme_stat_database.stat.exists" - name: (Data relocation) Move mx-puppet-groupme database file to ./data directory - command: "mv {{ matrix_mx_puppet_groupme_base_path }}/database.db {{ matrix_mx_puppet_groupme_data_path }}/database.db" + ansible.builtin.command: "mv {{ matrix_mx_puppet_groupme_base_path }}/database.db {{ matrix_mx_puppet_groupme_data_path }}/database.db" when: "matrix_mx_puppet_groupme_stat_database.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_groupme_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_groupme_sqlite_database_path_local }}" register: matrix_mx_puppet_groupme_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_groupme_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_groupme_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_groupme_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-groupme.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_groupme_requires_restart: true - when: "matrix_mx_puppet_groupme_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_groupme_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_groupme_database_engine == 'postgres'" - name: Ensure MX Puppet Groupme image is pulled @@ -72,21 +74,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_groupme_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_mx_puppet_groupme_docker_image_force_pull }}" - when: matrix_mx_puppet_groupme_enabled|bool and not matrix_mx_puppet_groupme_container_image_self_build + when: matrix_mx_puppet_groupme_enabled | bool and not matrix_mx_puppet_groupme_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure MX Puppet Groupme repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_groupme_container_image_self_build_repo }}" + version: "{{ matrix_mx_puppet_groupme_container_image_self_build_repo_version }}" dest: "{{ matrix_mx_puppet_groupme_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_groupme_git_pull_results - when: "matrix_mx_puppet_groupme_enabled|bool and matrix_mx_puppet_groupme_container_image_self_build" + when: "matrix_mx_puppet_groupme_enabled | bool and matrix_mx_puppet_groupme_container_image_self_build" - name: Ensure MX Puppet Groupme Docker image is built docker_image: @@ -98,38 +101,38 @@ dockerfile: Dockerfile path: "{{ matrix_mx_puppet_groupme_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_groupme_enabled|bool and matrix_mx_puppet_groupme_container_image_self_build" + when: "matrix_mx_puppet_groupme_enabled | bool and matrix_mx_puppet_groupme_container_image_self_build" - name: Ensure mx-puppet-groupme config.yaml installed - copy: - content: "{{ matrix_mx_puppet_groupme_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_groupme_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_groupme_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-groupme groupme-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_groupme_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_groupme_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_groupme_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-groupme.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-groupme.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-groupme.service" mode: 0644 register: matrix_mx_puppet_groupme_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-groupme.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_groupme_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-groupme.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-groupme.service" state: restarted - when: "matrix_mx_puppet_groupme_requires_restart|bool" + when: "matrix_mx_puppet_groupme_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_uninstall.yml index 24daf7be8..5ded61070 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-groupme service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-groupme.service" register: matrix_mx_puppet_groupme_service_stat - name: Ensure matrix-mx-puppet-groupme is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-groupme state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_groupme_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-groupme.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-groupme.service" state: absent when: "matrix_mx_puppet_groupme_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-groupme.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_groupme_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-groupme/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-groupme/tasks/validate_config.yml index 5c5463ce9..d091de6dc 100644 --- a/roles/matrix-bridge-mx-puppet-groupme/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-groupme/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mx-puppet-instagram/defaults/main.yml b/roles/matrix-bridge-mx-puppet-instagram/defaults/main.yml index c7c86e3c5..aae6eb5a7 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/defaults/main.yml @@ -6,6 +6,7 @@ matrix_mx_puppet_instagram_enabled: true matrix_mx_puppet_instagram_container_image_self_build: false matrix_mx_puppet_instagram_container_image_self_build_repo: "https://github.com/Sorunome/mx-puppet-instagram.git" +matrix_mx_puppet_instagram_container_image_self_build_repo_version: "{{ 'master' if matrix_mx_puppet_instagram_version == 'latest' else matrix_mx_puppet_instagram_version }}" matrix_mx_puppet_instagram_version: latest matrix_mx_puppet_instagram_docker_image: "{{ matrix_mx_puppet_instagram_docker_image_name_prefix }}sorunome/mx-puppet-instagram:{{ matrix_mx_puppet_instagram_version }}" @@ -26,7 +27,7 @@ matrix_mx_puppet_instagram_appservice_address: 'http://matrix-mx-puppet-instagra # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_instagram_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -77,11 +78,11 @@ matrix_mx_puppet_instagram_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_instagram_configuration_yaml`. -matrix_mx_puppet_instagram_configuration_extension: "{{ matrix_mx_puppet_instagram_configuration_extension_yaml|from_yaml if matrix_mx_puppet_instagram_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_instagram_configuration_extension: "{{ matrix_mx_puppet_instagram_configuration_extension_yaml | from_yaml if matrix_mx_puppet_instagram_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_instagram_configuration_yaml`. -matrix_mx_puppet_instagram_configuration: "{{ matrix_mx_puppet_instagram_configuration_yaml|from_yaml|combine(matrix_mx_puppet_instagram_configuration_extension, recursive=True) }}" +matrix_mx_puppet_instagram_configuration: "{{ matrix_mx_puppet_instagram_configuration_yaml | from_yaml | combine(matrix_mx_puppet_instagram_configuration_extension, recursive=True) }}" matrix_mx_puppet_instagram_registration_yaml: | as_token: "{{ matrix_mx_puppet_instagram_appservice_token }}" @@ -90,15 +91,15 @@ matrix_mx_puppet_instagram_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_instagrampuppet_.*:{{ matrix_mx_puppet_instagram_homeserver_domain|regex_escape }}' + regex: '@_instagrampuppet_.*:{{ matrix_mx_puppet_instagram_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#_instagrampuppet_.*:{{ matrix_mx_puppet_instagram_homeserver_domain|regex_escape }}' + regex: '#_instagrampuppet_.*:{{ matrix_mx_puppet_instagram_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: _instagrampuppet_bot url: {{ matrix_mx_puppet_instagram_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_instagram_registration: "{{ matrix_mx_puppet_instagram_registration_yaml|from_yaml }}" +matrix_mx_puppet_instagram_registration: "{{ matrix_mx_puppet_instagram_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-instagram/tasks/init.yml b/roles/matrix-bridge-mx-puppet-instagram/tasks/init.yml index ae6302b30..5e89275cf 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/tasks/init.yml @@ -2,27 +2,27 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mx_puppet_instagram_container_image_self_build and matrix_mx_puppet_instagram_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-instagram.service'] }}" - when: matrix_mx_puppet_instagram_enabled|bool + when: matrix_mx_puppet_instagram_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mx_puppet_instagram_config_path }}/registration.yaml,dst=/matrix-mx-puppet-instagram-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mx-puppet-instagram-registration.yaml"] }} - when: matrix_mx_puppet_instagram_enabled|bool + when: matrix_mx_puppet_instagram_enabled | bool diff --git a/roles/matrix-bridge-mx-puppet-instagram/tasks/main.yml b/roles/matrix-bridge-mx-puppet-instagram/tasks/main.yml index 6abb281fc..978577cc3 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_instagram_enabled | bool" tags: - setup-all - setup-mx-puppet-instagram -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_instagram_enabled | bool" tags: - setup-all - setup-mx-puppet-instagram -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_instagram_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_instagram_enabled | bool" tags: - setup-all - setup-mx-puppet-instagram diff --git a/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_install.yml index 2e74c059e..7695d88ec 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_install.yml @@ -3,36 +3,38 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mx-puppet-instagram role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_instagram_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_instagram_sqlite_database_path_local }}" register: matrix_mx_puppet_instagram_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_instagram_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_instagram_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_instagram_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-instagram.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_instagram_requires_restart: true - when: "matrix_mx_puppet_instagram_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_instagram_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_instagram_database_engine == 'postgres'" - name: Ensure mx-puppet-instagram image is pulled @@ -41,14 +43,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_instagram_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_mx_puppet_instagram_docker_image_force_pull }}" - when: matrix_mx_puppet_instagram_enabled|bool and not matrix_mx_puppet_instagram_container_image_self_build + when: matrix_mx_puppet_instagram_enabled | bool and not matrix_mx_puppet_instagram_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure mx-puppet-instagram paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -59,17 +61,18 @@ - {path: "{{ matrix_mx_puppet_instagram_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_instagram_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_instagram_docker_src_files_path }}", when: "{{ matrix_mx_puppet_instagram_container_image_self_build }}"} - when: matrix_mx_puppet_instagram_enabled|bool and item.when|bool + when: matrix_mx_puppet_instagram_enabled | bool and item.when | bool - name: Ensure mx-puppet-instagram repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_instagram_container_image_self_build_repo }}" + version: "{{ matrix_mx_puppet_instagram_container_image_self_build_repo_version }}" dest: "{{ matrix_mx_puppet_instagram_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_instagram_git_pull_results - when: "matrix_mx_puppet_instagram_enabled|bool and matrix_mx_puppet_instagram_container_image_self_build|bool" + when: "matrix_mx_puppet_instagram_enabled | bool and matrix_mx_puppet_instagram_container_image_self_build | bool" - name: Ensure mx-puppet-instagram Docker image is built docker_image: @@ -81,38 +84,38 @@ dockerfile: Dockerfile path: "{{ matrix_mx_puppet_instagram_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_instagram_enabled|bool and matrix_mx_puppet_instagram_container_image_self_build|bool" + when: "matrix_mx_puppet_instagram_enabled | bool and matrix_mx_puppet_instagram_container_image_self_build | bool" - name: Ensure mx-puppet-instagram config.yaml installed - copy: - content: "{{ matrix_mx_puppet_instagram_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_instagram_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_instagram_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-instagram-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_instagram_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_instagram_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_instagram_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-instagram.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-instagram.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-instagram.service" mode: 0644 register: matrix_mx_puppet_instagram_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-instagram.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_instagram_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-instagram.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-instagram.service" state: restarted - when: "matrix_mx_puppet_instagram_requires_restart|bool" + when: "matrix_mx_puppet_instagram_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_uninstall.yml index e4435a3e8..2d5a98aa4 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-instagram service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-instagram.service" register: matrix_mx_puppet_instagram_service_stat - name: Ensure matrix-mx-puppet-instagram is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-instagram state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_instagram_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-instagram.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-instagram.service" state: absent when: "matrix_mx_puppet_instagram_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-instagram.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_instagram_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-instagram/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-instagram/tasks/validate_config.yml index b6d9d994e..383fe5021 100644 --- a/roles/matrix-bridge-mx-puppet-instagram/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-instagram/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mx-puppet-slack/defaults/main.yml b/roles/matrix-bridge-mx-puppet-slack/defaults/main.yml index 294b18cf7..eae0b933b 100644 --- a/roles/matrix-bridge-mx-puppet-slack/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-slack/defaults/main.yml @@ -40,7 +40,7 @@ matrix_mx_puppet_slack_redirect_uri: 'https://{{ matrix_server_fqn_matrix }}{{ m # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_slack_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -92,11 +92,11 @@ matrix_mx_puppet_slack_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_slack_configuration_yaml`. -matrix_mx_puppet_slack_configuration_extension: "{{ matrix_mx_puppet_slack_configuration_extension_yaml|from_yaml if matrix_mx_puppet_slack_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_slack_configuration_extension: "{{ matrix_mx_puppet_slack_configuration_extension_yaml | from_yaml if matrix_mx_puppet_slack_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_slack_configuration_yaml`. -matrix_mx_puppet_slack_configuration: "{{ matrix_mx_puppet_slack_configuration_yaml|from_yaml|combine(matrix_mx_puppet_slack_configuration_extension, recursive=True) }}" +matrix_mx_puppet_slack_configuration: "{{ matrix_mx_puppet_slack_configuration_yaml | from_yaml | combine(matrix_mx_puppet_slack_configuration_extension, recursive=True) }}" matrix_mx_puppet_slack_registration_yaml: | as_token: "{{ matrix_mx_puppet_slack_appservice_token }}" @@ -105,15 +105,15 @@ matrix_mx_puppet_slack_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_slackpuppet_.*:{{ matrix_mx_puppet_slack_homeserver_domain|regex_escape }}' + regex: '@_slackpuppet_.*:{{ matrix_mx_puppet_slack_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#_slackpuppet_.*:{{ matrix_mx_puppet_slack_homeserver_domain|regex_escape }}' + regex: '#_slackpuppet_.*:{{ matrix_mx_puppet_slack_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: _slackpuppet_bot url: {{ matrix_mx_puppet_slack_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_slack_registration: "{{ matrix_mx_puppet_slack_registration_yaml|from_yaml }}" +matrix_mx_puppet_slack_registration: "{{ matrix_mx_puppet_slack_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-slack/tasks/init.yml b/roles/matrix-bridge-mx-puppet-slack/tasks/init.yml index ed6753a2f..fd9d62ae4 100644 --- a/roles/matrix-bridge-mx-puppet-slack/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-slack/tasks/init.yml @@ -2,46 +2,46 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mx_puppet_slack_container_image_self_build and matrix_mx_puppet_slack_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-slack.service'] }}" - when: matrix_mx_puppet_slack_enabled|bool + when: matrix_mx_puppet_slack_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mx_puppet_slack_config_path }}/registration.yaml,dst=/matrix-mx-puppet-slack-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mx-puppet-slack-registration.yaml"] }} - when: matrix_mx_puppet_slack_enabled|bool + when: matrix_mx_puppet_slack_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Slack Appservice'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-mx-puppet-slack role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Matrix MX Puppet Slack proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mx_puppet_slack_matrix_nginx_proxy_configuration: | location {{ matrix_mx_puppet_slack_redirect_path }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_mx_puppet_slack_appservice_address }}"; @@ -53,23 +53,23 @@ } - name: Register Slack Appservice proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mx_puppet_slack_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_mx_puppet_slack_enabled|bool + when: matrix_mx_puppet_slack_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Matrix Slack bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mx_puppet_slack_redirect_path }}` URL endpoint to the matrix-mx-puppet-slack container. You can expose the container's port using the `matrix_appservice_slack_container_http_host_bind_port` variable. - when: "matrix_mx_puppet_slack_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_mx_puppet_slack_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-mx-puppet-slack/tasks/main.yml b/roles/matrix-bridge-mx-puppet-slack/tasks/main.yml index 0e886d452..869afc497 100644 --- a/roles/matrix-bridge-mx-puppet-slack/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-slack/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_slack_enabled | bool" tags: - setup-all - setup-mx-puppet-slack -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_slack_enabled | bool" tags: - setup-all - setup-mx-puppet-slack -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_slack_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_slack_enabled | bool" tags: - setup-all - setup-mx-puppet-slack diff --git a/roles/matrix-bridge-mx-puppet-slack/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-slack/tasks/setup_install.yml index 3a7dfb409..70dac9ace 100644 --- a/roles/matrix-bridge-mx-puppet-slack/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-slack/tasks/setup_install.yml @@ -3,13 +3,13 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mx-puppet-slack role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure MX Puppet Slack paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -20,15 +20,15 @@ - {path: "{{ matrix_mx_puppet_slack_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_slack_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_slack_docker_src_files_path }}", when: "{{ matrix_mx_puppet_slack_container_image_self_build }}"} - when: matrix_mx_puppet_slack_enabled|bool and item.when|bool + when: matrix_mx_puppet_slack_enabled | bool and item.when | bool - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_slack_base_path }}/database.db" register: matrix_mx_puppet_slack_stat_database - name: (Data relocation) Ensure matrix-mx-puppet-slack.service is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-slack state: stopped enabled: false @@ -36,30 +36,32 @@ failed_when: false when: "matrix_mx_puppet_slack_stat_database.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_slack_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_slack_sqlite_database_path_local }}" register: matrix_mx_puppet_slack_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_slack_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_slack_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_slack_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-slack.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_slack_requires_restart: true - when: "matrix_mx_puppet_slack_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_slack_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_slack_database_engine == 'postgres'" - name: Ensure MX Puppet Slack image is pulled @@ -68,14 +70,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_slack_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_mx_puppet_slack_docker_image_force_pull }}" - when: matrix_mx_puppet_slack_enabled|bool and not matrix_mx_puppet_slack_container_image_self_build + when: matrix_mx_puppet_slack_enabled | bool and not matrix_mx_puppet_slack_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure MX Puppet Slack repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_slack_container_image_self_build_repo }}" dest: "{{ matrix_mx_puppet_slack_docker_src_files_path }}" force: "yes" @@ -83,7 +85,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_slack_git_pull_results - when: "matrix_mx_puppet_slack_enabled|bool and matrix_mx_puppet_slack_container_image_self_build" + when: "matrix_mx_puppet_slack_enabled | bool and matrix_mx_puppet_slack_container_image_self_build" - name: Ensure MX Puppet Slack Docker image is built docker_image: @@ -95,42 +97,42 @@ dockerfile: "{{ matrix_mx_puppet_slack_container_image_self_build_dockerfile_path }}" path: "{{ matrix_mx_puppet_slack_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_slack_enabled|bool and matrix_mx_puppet_slack_container_image_self_build" + when: "matrix_mx_puppet_slack_enabled | bool and matrix_mx_puppet_slack_container_image_self_build" - name: (Data relocation) Move mx-puppet-slack database file to ./data directory - command: "mv {{ matrix_mx_puppet_slack_base_path }}/database.db {{ matrix_mx_puppet_slack_data_path }}/database.db" + ansible.builtin.command: "mv {{ matrix_mx_puppet_slack_base_path }}/database.db {{ matrix_mx_puppet_slack_data_path }}/database.db" when: "matrix_mx_puppet_slack_stat_database.stat.exists" - name: Ensure mx-puppet-slack config.yaml installed - copy: - content: "{{ matrix_mx_puppet_slack_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_slack_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_slack_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-slack slack-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_slack_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_slack_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_slack_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-slack.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-slack.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-slack.service" mode: 0644 register: matrix_mx_puppet_slack_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-slack.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_slack_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-slack.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-slack.service" state: restarted - when: "matrix_mx_puppet_slack_requires_restart|bool" + when: "matrix_mx_puppet_slack_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-slack/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-slack/tasks/setup_uninstall.yml index 3a119267e..3f91b467b 100644 --- a/roles/matrix-bridge-mx-puppet-slack/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-slack/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-slack service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-slack.service" register: matrix_mx_puppet_slack_service_stat - name: Ensure matrix-mx-puppet-slack is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-slack state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_slack_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-slack.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-slack.service" state: absent when: "matrix_mx_puppet_slack_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-slack.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_slack_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-slack/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-slack/tasks/validate_config.yml index 3a0bca111..ea917f97e 100644 --- a/roles/matrix-bridge-mx-puppet-slack/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-slack/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mx-puppet-steam/defaults/main.yml b/roles/matrix-bridge-mx-puppet-steam/defaults/main.yml index 430dc90f1..895411624 100644 --- a/roles/matrix-bridge-mx-puppet-steam/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-steam/defaults/main.yml @@ -6,6 +6,7 @@ matrix_mx_puppet_steam_enabled: true matrix_mx_puppet_steam_container_image_self_build: false matrix_mx_puppet_steam_container_image_self_build_repo: "https://github.com/icewind1991/mx-puppet-steam.git" +matrix_mx_puppet_steam_container_image_self_build_repo_version: "{{ 'master' if matrix_mx_puppet_steam_version == 'latest' else matrix_mx_puppet_steam_version }}" # Controls whether the mx-puppet-steam container exposes its HTTP port (tcp/8432 in the container). # @@ -32,7 +33,7 @@ matrix_mx_puppet_steam_appservice_address: 'http://matrix-mx-puppet-steam:{{ mat # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_steam_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -83,11 +84,11 @@ matrix_mx_puppet_steam_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_steam_configuration_yaml`. -matrix_mx_puppet_steam_configuration_extension: "{{ matrix_mx_puppet_steam_configuration_extension_yaml|from_yaml if matrix_mx_puppet_steam_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_steam_configuration_extension: "{{ matrix_mx_puppet_steam_configuration_extension_yaml | from_yaml if matrix_mx_puppet_steam_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_steam_configuration_yaml`. -matrix_mx_puppet_steam_configuration: "{{ matrix_mx_puppet_steam_configuration_yaml|from_yaml|combine(matrix_mx_puppet_steam_configuration_extension, recursive=True) }}" +matrix_mx_puppet_steam_configuration: "{{ matrix_mx_puppet_steam_configuration_yaml | from_yaml | combine(matrix_mx_puppet_steam_configuration_extension, recursive=True) }}" matrix_mx_puppet_steam_registration_yaml: | as_token: "{{ matrix_mx_puppet_steam_appservice_token }}" @@ -96,15 +97,15 @@ matrix_mx_puppet_steam_registration_yaml: | namespaces: users: - exclusive: true - regex: '@_steampuppet_.*:{{ matrix_mx_puppet_steam_homeserver_domain|regex_escape }}' + regex: '@_steampuppet_.*:{{ matrix_mx_puppet_steam_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#_steampuppet_.*:{{ matrix_mx_puppet_steam_homeserver_domain|regex_escape }}' + regex: '#_steampuppet_.*:{{ matrix_mx_puppet_steam_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: _steampuppet_bot url: {{ matrix_mx_puppet_steam_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_steam_registration: "{{ matrix_mx_puppet_steam_registration_yaml|from_yaml }}" +matrix_mx_puppet_steam_registration: "{{ matrix_mx_puppet_steam_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-steam/tasks/init.yml b/roles/matrix-bridge-mx-puppet-steam/tasks/init.yml index 9a171af79..6c9a9a4fe 100644 --- a/roles/matrix-bridge-mx-puppet-steam/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-steam/tasks/init.yml @@ -2,27 +2,27 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mx_puppet_steam_container_image_self_build and matrix_mx_puppet_steam_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-steam.service'] }}" - when: matrix_mx_puppet_steam_enabled|bool + when: matrix_mx_puppet_steam_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mx_puppet_steam_config_path }}/registration.yaml,dst=/matrix-mx-puppet-steam-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mx-puppet-steam-registration.yaml"] }} - when: matrix_mx_puppet_steam_enabled|bool + when: matrix_mx_puppet_steam_enabled | bool diff --git a/roles/matrix-bridge-mx-puppet-steam/tasks/main.yml b/roles/matrix-bridge-mx-puppet-steam/tasks/main.yml index 733cfa909..236a7009f 100644 --- a/roles/matrix-bridge-mx-puppet-steam/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-steam/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_steam_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_steam_enabled | bool" tags: - setup-all - setup-mx-puppet-steam -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_steam_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_steam_enabled | bool" tags: - setup-all - setup-mx-puppet-steam -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_steam_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_steam_enabled | bool" tags: - setup-all - setup-mx-puppet-steam diff --git a/roles/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml index ac2a2fda9..804876303 100644 --- a/roles/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml @@ -3,13 +3,13 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mx-puppet-steam role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure MX Puppet Steam paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -20,15 +20,15 @@ - {path: "{{ matrix_mx_puppet_steam_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_steam_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_steam_docker_src_files_path }}", when: "{{ matrix_mx_puppet_steam_container_image_self_build }}"} - when: matrix_mx_puppet_steam_enabled|bool and item.when|bool + when: matrix_mx_puppet_steam_enabled | bool and item.when | bool - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_steam_base_path }}/database.db" register: matrix_mx_puppet_steam_stat_database - name: (Data relocation) Ensure matrix-mx-puppet-steam.service is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-steam state: stopped enabled: false @@ -37,33 +37,35 @@ when: "matrix_mx_puppet_steam_stat_database.stat.exists" - name: (Data relocation) Move mx-puppet-steam database file to ./data directory - command: "mv {{ matrix_mx_puppet_steam_base_path }}/database.db {{ matrix_mx_puppet_steam_data_path }}/database.db" + ansible.builtin.command: "mv {{ matrix_mx_puppet_steam_base_path }}/database.db {{ matrix_mx_puppet_steam_data_path }}/database.db" when: "matrix_mx_puppet_steam_stat_database.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_steam_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_steam_sqlite_database_path_local }}" register: matrix_mx_puppet_steam_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_steam_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_steam_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_steam_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-steam.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_steam_requires_restart: true - when: "matrix_mx_puppet_steam_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_steam_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_steam_database_engine == 'postgres'" - name: Ensure MX Puppet Steam image is pulled @@ -72,21 +74,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_steam_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_mx_puppet_steam_docker_image_force_pull }}" - when: matrix_mx_puppet_steam_enabled|bool and not matrix_mx_puppet_steam_container_image_self_build + when: matrix_mx_puppet_steam_enabled | bool and not matrix_mx_puppet_steam_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure MX Puppet Steam repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_steam_container_image_self_build_repo }}" + version: "{{ matrix_mx_puppet_steam_container_image_self_build_repo_version }}" dest: "{{ matrix_mx_puppet_steam_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_steam_git_pull_results - when: "matrix_mx_puppet_steam_enabled|bool and matrix_mx_puppet_steam_container_image_self_build" + when: "matrix_mx_puppet_steam_enabled | bool and matrix_mx_puppet_steam_container_image_self_build" - name: Ensure MX Puppet Steam Docker image is built docker_image: @@ -98,38 +101,38 @@ dockerfile: Dockerfile path: "{{ matrix_mx_puppet_steam_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_steam_enabled|bool and matrix_mx_puppet_steam_container_image_self_build" + when: "matrix_mx_puppet_steam_enabled | bool and matrix_mx_puppet_steam_container_image_self_build" - name: Ensure mx-puppet-steam config.yaml installed - copy: - content: "{{ matrix_mx_puppet_steam_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_steam_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_steam_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-steam steam-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_steam_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_steam_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_steam_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-steam.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-steam.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-steam.service" mode: 0644 register: matrix_mx_puppet_steam_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-steam.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_steam_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-steam.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-steam.service" state: restarted - when: "matrix_mx_puppet_steam_requires_restart|bool" + when: "matrix_mx_puppet_steam_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-steam/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-steam/tasks/setup_uninstall.yml index 2e152ef67..d88e54722 100644 --- a/roles/matrix-bridge-mx-puppet-steam/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-steam/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-steam service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-steam.service" register: matrix_mx_puppet_steam_service_stat - name: Ensure matrix-mx-puppet-steam is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-steam state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_steam_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-steam.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-steam.service" state: absent when: "matrix_mx_puppet_steam_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-steam.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_steam_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml index a8bc6a420..2e54d6ffa 100644 --- a/roles/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-mx-puppet-twitter/defaults/main.yml b/roles/matrix-bridge-mx-puppet-twitter/defaults/main.yml index c1b460713..73674220f 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/defaults/main.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/defaults/main.yml @@ -41,7 +41,7 @@ matrix_mx_puppet_twitter_webhook_url: 'https://{{ matrix_server_fqn_matrix }}{{ # "@.*:yourserver.com" to allow users on a specific homeserver # "@.*" to allow anyone matrix_mx_puppet_twitter_provisioning_whitelist: - - "@.*:{{ matrix_domain|regex_escape }}" + - "@.*:{{ matrix_domain | regex_escape }}" # Leave empty to disable blacklist # "@user:server.com" disallow a specific user @@ -93,11 +93,11 @@ matrix_mx_puppet_twitter_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_mx_puppet_twitter_configuration_yaml`. -matrix_mx_puppet_twitter_configuration_extension: "{{ matrix_mx_puppet_twitter_configuration_extension_yaml|from_yaml if matrix_mx_puppet_twitter_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_mx_puppet_twitter_configuration_extension: "{{ matrix_mx_puppet_twitter_configuration_extension_yaml | from_yaml if matrix_mx_puppet_twitter_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_mx_puppet_twitter_configuration_yaml`. -matrix_mx_puppet_twitter_configuration: "{{ matrix_mx_puppet_twitter_configuration_yaml|from_yaml|combine(matrix_mx_puppet_twitter_configuration_extension, recursive=True) }}" +matrix_mx_puppet_twitter_configuration: "{{ matrix_mx_puppet_twitter_configuration_yaml | from_yaml | combine(matrix_mx_puppet_twitter_configuration_extension, recursive=True) }}" # The prefix for user IDs and aliases matrix_mx_puppet_twitter_namespace_prefix: _twitterpuppet_ @@ -110,15 +110,15 @@ matrix_mx_puppet_twitter_registration_yaml: | namespaces: users: - exclusive: true - regex: '@{{ matrix_mx_puppet_twitter_namespace_prefix|regex_escape }}.*:{{ matrix_mx_puppet_twitter_homeserver_domain|regex_escape }}' + regex: '@{{ matrix_mx_puppet_twitter_namespace_prefix | regex_escape }}.*:{{ matrix_mx_puppet_twitter_homeserver_domain | regex_escape }}' rooms: [] aliases: - exclusive: true - regex: '#{{ matrix_mx_puppet_twitter_namespace_prefix|regex_escape }}.*:{{ matrix_mx_puppet_twitter_homeserver_domain|regex_escape }}' + regex: '#{{ matrix_mx_puppet_twitter_namespace_prefix | regex_escape }}.*:{{ matrix_mx_puppet_twitter_homeserver_domain | regex_escape }}' protocols: [] rate_limited: false sender_localpart: "{{ matrix_mx_puppet_twitter_bot_localpart }}" url: {{ matrix_mx_puppet_twitter_appservice_address }} de.sorunome.msc2409.push_ephemeral: true -matrix_mx_puppet_twitter_registration: "{{ matrix_mx_puppet_twitter_registration_yaml|from_yaml }}" +matrix_mx_puppet_twitter_registration: "{{ matrix_mx_puppet_twitter_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-mx-puppet-twitter/tasks/init.yml b/roles/matrix-bridge-mx-puppet-twitter/tasks/init.yml index d774de159..3667ebc75 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/tasks/init.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/tasks/init.yml @@ -2,46 +2,46 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mx_puppet_twitter_container_image_self_build and matrix_mx_puppet_twitter_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mx-puppet-twitter.service'] }}" - when: matrix_mx_puppet_twitter_enabled|bool + when: matrix_mx_puppet_twitter_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_mx_puppet_twitter_config_path }}/registration.yaml,dst=/matrix-mx-puppet-twitter-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-mx-puppet-twitter-registration.yaml"] }} - when: matrix_mx_puppet_twitter_enabled|bool + when: matrix_mx_puppet_twitter_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Twitter Appservice'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-mx-puppet-twitter role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Matrix MX Puppet Twitter proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_mx_puppet_twitter_matrix_nginx_proxy_configuration: | location {{ matrix_mx_puppet_twitter_webhook_path }} { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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_mx_puppet_twitter_appservice_address }}"; @@ -53,23 +53,23 @@ } - name: Register Twitter Appservice proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_mx_puppet_twitter_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_mx_puppet_twitter_enabled|bool + when: matrix_mx_puppet_twitter_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Matrix Twitter bridge but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_mx_puppet_twitter_redirect_path }}` URL endpoint to the matrix-mx-puppet-twitter container. You can expose the container's port using the `matrix_mx_puppet_twitter_container_http_host_bind_port` variable. - when: "matrix_mx_puppet_twitter_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_mx_puppet_twitter_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-bridge-mx-puppet-twitter/tasks/main.yml b/roles/matrix-bridge-mx-puppet-twitter/tasks/main.yml index 7d65257c9..20e4f6862 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/tasks/main.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_mx_puppet_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_mx_puppet_twitter_enabled | bool" tags: - setup-all - setup-mx-puppet-twitter -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_mx_puppet_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_mx_puppet_twitter_enabled | bool" tags: - setup-all - setup-mx-puppet-twitter -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_mx_puppet_twitter_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_mx_puppet_twitter_enabled | bool" tags: - setup-all - setup-mx-puppet-twitter diff --git a/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_install.yml b/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_install.yml index 6336b0a08..305cd5dea 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_install.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_install.yml @@ -3,13 +3,13 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-bridge-mx-puppet-twitter role needs to execute before the matrix-synapse role. - when: "matrix_synapse_role_executed|default(False)" + when: "matrix_synapse_role_executed | default(False)" - name: Ensure MX Puppet Twitter paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -20,15 +20,15 @@ - {path: "{{ matrix_mx_puppet_twitter_config_path }}", when: true} - {path: "{{ matrix_mx_puppet_twitter_data_path }}", when: true} - {path: "{{ matrix_mx_puppet_twitter_docker_src_files_path }}", when: "{{ matrix_mx_puppet_twitter_container_image_self_build }}"} - when: matrix_mx_puppet_twitter_enabled|bool and item.when|bool + when: matrix_mx_puppet_twitter_enabled | bool and item.when | bool - name: Check if an old database file already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_twitter_base_path }}/database.db" register: matrix_mx_puppet_twitter_stat_database - name: (Data relocation) Ensure matrix-mx-puppet-twitter.service is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-twitter state: stopped enabled: false @@ -37,33 +37,35 @@ when: "matrix_mx_puppet_twitter_stat_database.stat.exists" - name: (Data relocation) Move mx-puppet-twitter database file to ./data directory - command: "mv {{ matrix_mx_puppet_twitter_base_path }}/database.db {{ matrix_mx_puppet_twitter_data_path }}/database.db" + ansible.builtin.command: "mv {{ matrix_mx_puppet_twitter_base_path }}/database.db {{ matrix_mx_puppet_twitter_data_path }}/database.db" when: "matrix_mx_puppet_twitter_stat_database.stat.exists" -- set_fact: +- ansible.builtin.set_fact: matrix_mx_puppet_twitter_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_mx_puppet_twitter_sqlite_database_path_local }}" register: matrix_mx_puppet_twitter_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_mx_puppet_twitter_sqlite_database_path_local }}" dst: "{{ matrix_mx_puppet_twitter_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_mx_puppet_twitter_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-mx-puppet-twitter.service'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_mx_puppet_twitter_requires_restart: true - when: "matrix_mx_puppet_twitter_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mx_puppet_twitter_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_mx_puppet_twitter_database_engine == 'postgres'" - name: Ensure MX Puppet Twitter image is pulled @@ -72,21 +74,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mx_puppet_twitter_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_mx_puppet_twitter_docker_image_force_pull }}" - when: matrix_mx_puppet_twitter_enabled|bool and not matrix_mx_puppet_twitter_container_image_self_build + when: matrix_mx_puppet_twitter_enabled | bool and not matrix_mx_puppet_twitter_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure MX Puppet Twitter repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_mx_puppet_twitter_container_image_self_build_repo }}" + version: master dest: "{{ matrix_mx_puppet_twitter_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_mx_puppet_twitter_git_pull_results - when: "matrix_mx_puppet_twitter_enabled|bool and matrix_mx_puppet_twitter_container_image_self_build" + when: "matrix_mx_puppet_twitter_enabled | bool and matrix_mx_puppet_twitter_container_image_self_build" - name: Ensure MX Puppet Twitter Docker image is built docker_image: @@ -98,38 +101,38 @@ dockerfile: Dockerfile path: "{{ matrix_mx_puppet_twitter_docker_src_files_path }}" pull: true - when: "matrix_mx_puppet_twitter_enabled|bool and matrix_mx_puppet_twitter_container_image_self_build" + when: "matrix_mx_puppet_twitter_enabled | bool and matrix_mx_puppet_twitter_container_image_self_build" - name: Ensure mx-puppet-twitter config.yaml installed - copy: - content: "{{ matrix_mx_puppet_twitter_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_twitter_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_twitter_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure mx-puppet-twitter twitter-registration.yaml installed - copy: - content: "{{ matrix_mx_puppet_twitter_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_mx_puppet_twitter_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_mx_puppet_twitter_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-mx-puppet-twitter.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-twitter.service.j2" dest: "/etc/systemd/system/matrix-mx-puppet-twitter.service" mode: 0644 register: matrix_mx_puppet_twitter_systemd_service_result - name: Ensure systemd reloaded after matrix-mx-puppet-twitter.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_twitter_systemd_service_result.changed" - name: Ensure matrix-mx-puppet-twitter.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-mx-puppet-twitter.service" state: restarted - when: "matrix_mx_puppet_twitter_requires_restart|bool" + when: "matrix_mx_puppet_twitter_requires_restart | bool" diff --git a/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_uninstall.yml b/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_uninstall.yml index 56dcd9ce0..6db13de08 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-mx-puppet-twitter service - stat: + ansible.builtin.stat: path: "/etc/systemd/system/matrix-mx-puppet-twitter.service" register: matrix_mx_puppet_twitter_service_stat - name: Ensure matrix-mx-puppet-twitter is stopped - service: + ansible.builtin.service: name: matrix-mx-puppet-twitter state: stopped enabled: false @@ -14,12 +14,12 @@ when: "matrix_mx_puppet_twitter_service_stat.stat.exists" - name: Ensure matrix-mx-puppet-twitter.service doesn't exist - file: + ansible.builtin.file: path: "/etc/systemd/system/matrix-mx-puppet-twitter.service" state: absent when: "matrix_mx_puppet_twitter_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mx-puppet-twitter.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mx_puppet_twitter_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mx-puppet-twitter/tasks/validate_config.yml b/roles/matrix-bridge-mx-puppet-twitter/tasks/validate_config.yml index d13a39e1e..b5b7ef5b7 100644 --- a/roles/matrix-bridge-mx-puppet-twitter/tasks/validate_config.yml +++ b/roles/matrix-bridge-mx-puppet-twitter/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-bridge-sms/defaults/main.yml b/roles/matrix-bridge-sms/defaults/main.yml index 8a640f862..b4755d71d 100644 --- a/roles/matrix-bridge-sms/defaults/main.yml +++ b/roles/matrix-bridge-sms/defaults/main.yml @@ -104,9 +104,9 @@ matrix_sms_bridge_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_sms_bridge_configuration_yaml`. -matrix_sms_bridge_configuration_extension: "{{ matrix_sms_bridge_configuration_extension_yaml|from_yaml if matrix_sms_bridge_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_sms_bridge_configuration_extension: "{{ matrix_sms_bridge_configuration_extension_yaml | from_yaml if matrix_sms_bridge_configuration_extension_yaml | from_yaml is mapping else {} }}" -matrix_sms_bridge_configuration: "{{ matrix_sms_bridge_configuration_yaml|from_yaml|combine(matrix_sms_bridge_configuration_extension, recursive=True) }}" +matrix_sms_bridge_configuration: "{{ matrix_sms_bridge_configuration_yaml | from_yaml | combine(matrix_sms_bridge_configuration_extension, recursive=True) }}" matrix_sms_bridge_registration_yaml: | id: sms @@ -115,12 +115,12 @@ matrix_sms_bridge_registration_yaml: | namespaces: users: - exclusive: true - regex: '^@sms_.+:{{ matrix_sms_bridge_homserver_domain|regex_escape }}$' + regex: '^@sms_.+:{{ matrix_sms_bridge_homserver_domain | regex_escape }}$' aliases: - exclusive: true - regex: '^#sms_.+:{{ matrix_sms_bridge_homserver_domain|regex_escape }}$' + regex: '^#sms_.+:{{ matrix_sms_bridge_homserver_domain | regex_escape }}$' url: {{ matrix_sms_bridge_appservice_url }} sender_localpart: smsbot rate_limited: false -matrix_sms_bridge_registration: "{{ matrix_sms_bridge_registration_yaml|from_yaml }}" +matrix_sms_bridge_registration: "{{ matrix_sms_bridge_registration_yaml | from_yaml }}" diff --git a/roles/matrix-bridge-sms/tasks/init.yml b/roles/matrix-bridge-sms/tasks/init.yml index 9ee96b3eb..85684b81a 100644 --- a/roles/matrix-bridge-sms/tasks/init.yml +++ b/roles/matrix-bridge-sms/tasks/init.yml @@ -3,28 +3,28 @@ # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. # We don't want to fail in such cases. - name: Fail if matrix-synapse role already executed - fail: + ansible.builtin.fail: msg: >- The matrix-sms-bridge role needs to execute before the matrix-synapse role. - when: "matrix_sms_bridge_enabled and matrix_synapse_role_executed|default(False)" + when: "matrix_sms_bridge_enabled and matrix_synapse_role_executed | default(False)" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-sms-bridge.service'] }}" - when: matrix_sms_bridge_enabled|bool + when: matrix_sms_bridge_enabled | bool # If the matrix-synapse role is not used, these variables may not exist. -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_sms_bridge_config_path }}/registration.yaml,dst=/matrix-sms-bridge-registration.yaml,ro"] }} matrix_synapse_app_service_config_files: > {{ - matrix_synapse_app_service_config_files|default([]) + matrix_synapse_app_service_config_files | default([]) + ["/matrix-sms-bridge-registration.yaml"] }} - when: matrix_sms_bridge_enabled|bool + when: matrix_sms_bridge_enabled | bool diff --git a/roles/matrix-bridge-sms/tasks/main.yml b/roles/matrix-bridge-sms/tasks/main.yml index b06e1a548..1a6b964ba 100644 --- a/roles/matrix-bridge-sms/tasks/main.yml +++ b/roles/matrix-bridge-sms/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_sms_bridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_sms_bridge_enabled | bool" tags: - setup-all - setup-matrix-sms-bridge -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_sms_bridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_sms_bridge_enabled | bool" tags: - setup-all - setup-matrix-sms-bridge -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_sms_bridge_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_sms_bridge_enabled | bool" tags: - setup-all - setup-matrix-sms-bridge diff --git a/roles/matrix-bridge-sms/tasks/setup_install.yml b/roles/matrix-bridge-sms/tasks/setup_install.yml index 412c26feb..dcc317ba2 100644 --- a/roles/matrix-bridge-sms/tasks/setup_install.yml +++ b/roles/matrix-bridge-sms/tasks/setup_install.yml @@ -10,7 +10,7 @@ until: result is not failed - name: Ensure matrix-sms-bridge paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -22,23 +22,23 @@ - "{{ matrix_sms_bridge_data_path }}" - name: Ensure matrix-sms-bridge application.yml installed - copy: - content: "{{ matrix_sms_bridge_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_sms_bridge_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_sms_bridge_config_path }}/application.yml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-sms-bridge registration.yaml installed - copy: - content: "{{ matrix_sms_bridge_registration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_sms_bridge_registration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_sms_bridge_config_path }}/registration.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure android-sms-gateway-server cert installed - copy: + ansible.builtin.copy: src: "{{ matrix_sms_bridge_provider_android_truststore_local_path }}" dest: "{{ matrix_sms_bridge_config_path }}/matrix-sms-gateway-server.p12" mode: 0644 @@ -47,13 +47,13 @@ when: matrix_sms_bridge_provider_android_truststore_local_path != "" - name: Ensure matrix-sms-bridge.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-sms-bridge.service.j2" dest: "{{ matrix_systemd_path }}/matrix-sms-bridge.service" mode: 0644 register: matrix_sms_bridge_systemd_service_result - name: Ensure systemd reloaded after matrix-sms-bridge.service installation - service: + ansible.builtin.service: daemon_reload: true when: matrix_sms_bridge_systemd_service_result.changed diff --git a/roles/matrix-bridge-sms/tasks/setup_uninstall.yml b/roles/matrix-bridge-sms/tasks/setup_uninstall.yml index d74476ebe..322190f91 100644 --- a/roles/matrix-bridge-sms/tasks/setup_uninstall.yml +++ b/roles/matrix-bridge-sms/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-sms-bridge service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-sms-bridge.service" register: matrix_sms_bridge_service_stat - name: Ensure matrix-sms-bridge is stopped - service: + ansible.builtin.service: name: matrix-sms-bridge state: stopped enabled: false @@ -14,7 +14,7 @@ when: "matrix_sms_bridge_service_stat.stat.exists" - name: Ensure matrix-sms-bridge.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-sms-bridge.service" state: absent when: "matrix_sms_bridge_service_stat.stat.exists" diff --git a/roles/matrix-bridge-sms/tasks/validate_config.yml b/roles/matrix-bridge-sms/tasks/validate_config.yml index 96e41755b..fa7dcfbdd 100644 --- a/roles/matrix-bridge-sms/tasks/validate_config.yml +++ b/roles/matrix-bridge-sms/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-client-cinny/defaults/main.yml b/roles/matrix-client-cinny/defaults/main.yml index 277f6e0cf..efd880104 100644 --- a/roles/matrix-client-cinny/defaults/main.yml +++ b/roles/matrix-client-cinny/defaults/main.yml @@ -50,8 +50,8 @@ matrix_client_cinny_configuration_default: "{{ lookup('template', 'templates/con # completely redefining `matrix_client_cinny_configuration_default`. matrix_client_cinny_configuration_extension_json: '{}' -matrix_client_cinny_configuration_extension: "{{ matrix_client_cinny_configuration_extension_json|from_json if matrix_client_cinny_configuration_extension_json|from_json is mapping else {} }}" +matrix_client_cinny_configuration_extension: "{{ matrix_client_cinny_configuration_extension_json | from_json if matrix_client_cinny_configuration_extension_json | from_json is mapping else {} }}" # Holds the final cinny configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_client_cinny_configuration_default`. -matrix_client_cinny_configuration: "{{ matrix_client_cinny_configuration_default|combine(matrix_client_cinny_configuration_extension, recursive=True) }}" +matrix_client_cinny_configuration: "{{ matrix_client_cinny_configuration_default | combine(matrix_client_cinny_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-client-cinny/tasks/init.yml b/roles/matrix-client-cinny/tasks/init.yml index 04fbd8a20..00e46dc82 100644 --- a/roles/matrix-client-cinny/tasks/init.yml +++ b/roles/matrix-client-cinny/tasks/init.yml @@ -2,10 +2,10 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Cinny 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_client_cinny_container_image_self_build and matrix_client_cinny_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-client-cinny.service'] }}" - when: matrix_client_cinny_enabled|bool + when: matrix_client_cinny_enabled | bool diff --git a/roles/matrix-client-cinny/tasks/main.yml b/roles/matrix-client-cinny/tasks/main.yml index 5c37d38e5..9eb007810 100644 --- a/roles/matrix-client-cinny/tasks/main.yml +++ b/roles/matrix-client-cinny/tasks/main.yml @@ -1,30 +1,30 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_client_cinny_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_client_cinny_enabled | bool" tags: - setup-all - setup-client-cinny -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_client_cinny_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_client_cinny_enabled | bool" tags: - setup-all - setup-client-cinny -- import_tasks: "{{ role_path }}/tasks/self_check.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check.yml" delegate_to: 127.0.0.1 become: false - when: "run_self_check|bool and matrix_client_cinny_enabled|bool" + when: "run_self_check | bool and matrix_client_cinny_enabled | bool" tags: - self-check -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_client_cinny_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_client_cinny_enabled | bool" tags: - setup-all - setup-client-cinny diff --git a/roles/matrix-client-cinny/tasks/self_check.yml b/roles/matrix-client-cinny/tasks/self_check.yml index d00408da9..e0f9bfc1e 100644 --- a/roles/matrix-client-cinny/tasks/self_check.yml +++ b/roles/matrix-client-cinny/tasks/self_check.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_client_cinny_url_endpoint_public: "https://{{ matrix_server_fqn_cinny }}/config.json" - name: Check Cinny - uri: + ansible.builtin.uri: url: "{{ matrix_client_cinny_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_client_cinny_self_check_validate_certificates }}" @@ -13,10 +13,10 @@ ignore_errors: true - name: Fail if Cinny not working - fail: + ansible.builtin.fail: msg: "Failed checking Cinny is up at `{{ matrix_server_fqn_cinny }}` (checked endpoint: `{{ matrix_client_cinny_url_endpoint_public }}`). Is Cinny running? Is port 443 open in your firewall? Full error: {{ matrix_client_cinny_self_check_result }}" when: "matrix_client_cinny_self_check_result.failed or 'json' not in matrix_client_cinny_self_check_result" - name: Report working Cinny - debug: + ansible.builtin.debug: msg: "Cinny at `{{ matrix_server_fqn_cinny }}` is working (checked endpoint: `{{ matrix_client_cinny_url_endpoint_public }}`)" diff --git a/roles/matrix-client-cinny/tasks/setup_install.yml b/roles/matrix-client-cinny/tasks/setup_install.yml index da979f565..755b872fd 100644 --- a/roles/matrix-client-cinny/tasks/setup_install.yml +++ b/roles/matrix-client-cinny/tasks/setup_install.yml @@ -1,6 +1,6 @@ --- - name: Ensure Cinny paths exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -9,7 +9,7 @@ with_items: - {path: "{{ matrix_client_cinny_data_path }}", when: true} - {path: "{{ matrix_client_cinny_docker_src_files_path }}", when: "{{ matrix_client_cinny_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Cinny Docker image is pulled docker_image: @@ -17,14 +17,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_client_cinny_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_client_cinny_docker_image_force_pull }}" - when: "not matrix_client_cinny_container_image_self_build|bool" + when: "not matrix_client_cinny_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Cinny repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_client_cinny_container_image_self_build_repo }}" dest: "{{ matrix_client_cinny_docker_src_files_path }}" version: "{{ matrix_client_cinny_docker_image.split(':')[1] }}" @@ -32,18 +32,18 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_client_cinny_git_pull_results - when: "matrix_client_cinny_container_image_self_build|bool" + when: "matrix_client_cinny_container_image_self_build | bool" - name: Ensure Cinny configuration installed - copy: - content: "{{ matrix_client_cinny_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_client_cinny_configuration | to_nice_json }}" dest: "{{ matrix_client_cinny_data_path }}/config.json" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Cinny additional config files installed - template: + ansible.builtin.template: src: "{{ item.src }}" dest: "{{ matrix_client_cinny_data_path }}/{{ item.name }}" mode: 0644 @@ -62,16 +62,16 @@ dockerfile: Dockerfile path: "{{ matrix_client_cinny_docker_src_files_path }}" pull: true - when: "matrix_client_cinny_container_image_self_build|bool" + when: "matrix_client_cinny_container_image_self_build | bool" - name: Ensure matrix-client-cinny.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-client-cinny.service.j2" dest: "{{ matrix_systemd_path }}/matrix-client-cinny.service" mode: 0644 register: matrix_client_cinny_systemd_service_result - name: Ensure systemd reloaded after matrix-client-cinny.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_cinny_systemd_service_result.changed|bool" + when: "matrix_client_cinny_systemd_service_result.changed | bool" diff --git a/roles/matrix-client-cinny/tasks/setup_uninstall.yml b/roles/matrix-client-cinny/tasks/setup_uninstall.yml index 507c5d70e..e6f71b0bc 100644 --- a/roles/matrix-client-cinny/tasks/setup_uninstall.yml +++ b/roles/matrix-client-cinny/tasks/setup_uninstall.yml @@ -1,31 +1,31 @@ --- - name: Check existence of matrix-client-cinny.service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-client-cinny.service" register: matrix_client_cinny_service_stat - name: Ensure matrix-client-cinny is stopped - service: + ansible.builtin.service: name: matrix-client-cinny state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_client_cinny_service_stat.stat.exists|bool" + when: "matrix_client_cinny_service_stat.stat.exists | bool" - name: Ensure matrix-client-cinny.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-client-cinny.service" state: absent - when: "matrix_client_cinny_service_stat.stat.exists|bool" + when: "matrix_client_cinny_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-client-cinny.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_cinny_service_stat.stat.exists|bool" + when: "matrix_client_cinny_service_stat.stat.exists | bool" - name: Ensure Cinny paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_client_cinny_data_path }}" state: absent diff --git a/roles/matrix-client-cinny/tasks/validate_config.yml b/roles/matrix-client-cinny/tasks/validate_config.yml index d8e804c5e..10f64fee1 100644 --- a/roles/matrix-client-cinny/tasks/validate_config.yml +++ b/roles/matrix-client-cinny/tasks/validate_config.yml @@ -1,6 +1,6 @@ --- - name: Fail if required Cinny settings not defined - fail: + ansible.builtin.fail: msg: > You need to define a required configuration setting (`{{ item }}`) to use Cinny. when: "vars[item] == '' or vars[item] is none" diff --git a/roles/matrix-client-cinny/templates/config.json.j2 b/roles/matrix-client-cinny/templates/config.json.j2 index 9731a3722..0da710acc 100644 --- a/roles/matrix-client-cinny/templates/config.json.j2 +++ b/roles/matrix-client-cinny/templates/config.json.j2 @@ -1,6 +1,6 @@ { "defaultHomeserver": 0, "homeserverList": [ - {{ matrix_client_cinny_default_hs_url|string|to_json }} + {{ matrix_client_cinny_default_hs_url | string|to_json }} ] } diff --git a/roles/matrix-client-element/defaults/main.yml b/roles/matrix-client-element/defaults/main.yml index e93b2c7c5..119f31a2e 100644 --- a/roles/matrix-client-element/defaults/main.yml +++ b/roles/matrix-client-element/defaults/main.yml @@ -39,9 +39,9 @@ matrix_client_element_integrations_ui_url: "https://scalar.vector.im/" matrix_client_element_integrations_rest_url: "https://scalar.vector.im/api" matrix_client_element_integrations_widgets_urls: ["https://scalar.vector.im/api"] matrix_client_element_integrations_jitsi_widget_url: "https://scalar.vector.im/api/widgets/jitsi.html" -matrix_client_element_permalinkPrefix: "https://matrix.to" +matrix_client_element_permalinkPrefix: "https://matrix.to" # noqa var-naming matrix_client_element_bug_report_endpoint_url: "https://element.io/bugreports/submit" -matrix_client_element_showLabsSettings: true +matrix_client_element_showLabsSettings: true # noqa var-naming # Element public room directory server(s) matrix_client_element_roomdir_servers: ['matrix.org'] matrix_client_element_welcome_user_id: ~ @@ -59,13 +59,13 @@ matrix_client_element_welcome_text: "_t('Decentralised, encrypted chat & col # Links, shown in footer of welcome page: # [{"text": "Link text", "url": "https://link.target"}, {"text": "Other link"}] -matrix_client_element_branding_authFooterLinks: ~ +matrix_client_element_branding_authFooterLinks: ~ # noqa var-naming # URL to image, shown during Login -matrix_client_element_branding_authHeaderLogoUrl: "{{ matrix_client_element_welcome_logo }}" +matrix_client_element_branding_authHeaderLogoUrl: "{{ matrix_client_element_welcome_logo }}" # noqa var-naming # URL to Wallpaper, shown in background of welcome page -matrix_client_element_branding_welcomeBackgroundUrl: ~ +matrix_client_element_branding_welcomeBackgroundUrl: ~ # noqa var-naming matrix_client_element_page_template_welcome_path: "{{ role_path }}/templates/welcome.html.j2" @@ -73,7 +73,7 @@ matrix_client_element_page_template_welcome_path: "{{ role_path }}/templates/wel # point this to a `home.html` template file on your local filesystem. matrix_client_element_embedded_pages_home_path: ~ -matrix_client_element_jitsi_preferredDomain: '' +matrix_client_element_jitsi_preferredDomain: '' # noqa var-naming # Controls whether the self-check feature should validate SSL certificates. matrix_client_element_self_check_validate_certificates: true @@ -89,6 +89,7 @@ matrix_client_element_enable_presence_by_hs_url: ~ # will be installed and enabled automatically. matrix_client_element_themes_enabled: false matrix_client_element_themes_repository_url: https://github.com/aaronraimist/element-themes +matrix_client_element_themes_repository_version: master # Controls the default theme matrix_client_element_default_theme: 'light' @@ -100,7 +101,7 @@ matrix_client_element_default_theme: 'light' # If you define your own themes here and set `matrix_client_element_themes_enabled: true`, your themes will be preserved as well. # # Note that for a custom theme to work well, all Element instances that you use must have the same theme installed. -matrix_client_element_settingDefaults_custom_themes: [] +matrix_client_element_settingDefaults_custom_themes: [] # noqa var-naming # Default Element configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. @@ -129,8 +130,8 @@ matrix_client_element_configuration_default: "{{ lookup('template', 'templates/c # } matrix_client_element_configuration_extension_json: '{}' -matrix_client_element_configuration_extension: "{{ matrix_client_element_configuration_extension_json|from_json if matrix_client_element_configuration_extension_json|from_json is mapping else {} }}" +matrix_client_element_configuration_extension: "{{ matrix_client_element_configuration_extension_json | from_json if matrix_client_element_configuration_extension_json | from_json is mapping else {} }}" # Holds the final Element configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_client_element_configuration_default`. -matrix_client_element_configuration: "{{ matrix_client_element_configuration_default|combine(matrix_client_element_configuration_extension, recursive=True) }}" +matrix_client_element_configuration: "{{ matrix_client_element_configuration_default | combine(matrix_client_element_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-client-element/tasks/init.yml b/roles/matrix-client-element/tasks/init.yml index cb1df0b52..7bdad9e1a 100644 --- a/roles/matrix-client-element/tasks/init.yml +++ b/roles/matrix-client-element/tasks/init.yml @@ -1,12 +1,12 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-client-element.service'] }}" - when: matrix_client_element_enabled|bool + when: matrix_client_element_enabled | bool # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_client_element_container_image_self_build and matrix_client_element_enabled" diff --git a/roles/matrix-client-element/tasks/main.yml b/roles/matrix-client-element/tasks/main.yml index 28e23e8a5..53a25afb9 100644 --- a/roles/matrix-client-element/tasks/main.yml +++ b/roles/matrix-client-element/tasks/main.yml @@ -1,42 +1,42 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_client_element_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_client_element_enabled | bool" tags: - setup-all - setup-client-element -- import_tasks: "{{ role_path }}/tasks/prepare_themes.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/prepare_themes.yml" + when: run_setup | bool tags: - setup-all - setup-client-element -- import_tasks: "{{ role_path }}/tasks/migrate_riot_web.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_riot_web.yml" + when: run_setup | bool tags: - setup-all - setup-client-element -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_client_element_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_client_element_enabled | bool" tags: - setup-all - setup-client-element -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_client_element_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_client_element_enabled | bool" tags: - setup-all - setup-client-element -- import_tasks: "{{ role_path }}/tasks/self_check.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check.yml" delegate_to: 127.0.0.1 become: false - when: "run_self_check|bool and matrix_client_element_enabled|bool" + when: "run_self_check | bool and matrix_client_element_enabled | bool" tags: - self-check diff --git a/roles/matrix-client-element/tasks/migrate_riot_web.yml b/roles/matrix-client-element/tasks/migrate_riot_web.yml index ee0fd4460..23011e93b 100644 --- a/roles/matrix-client-element/tasks/migrate_riot_web.yml +++ b/roles/matrix-client-element/tasks/migrate_riot_web.yml @@ -1,37 +1,37 @@ --- - name: Check existence of matrix-riot-web.service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-riot-web.service" register: matrix_client_riot_web_service_stat - when: "matrix_client_element_enabled|bool" + when: "matrix_client_element_enabled | bool" - name: Ensure matrix-riot-web is stopped - service: + ansible.builtin.service: name: matrix-riot-web state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_client_element_enabled|bool and matrix_client_riot_web_service_stat.stat.exists" + when: "matrix_client_element_enabled | bool and matrix_client_riot_web_service_stat.stat.exists" - name: Ensure matrix-riot-web.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-riot-web.service" state: absent - when: "matrix_client_element_enabled|bool and matrix_client_riot_web_service_stat.stat.exists" + when: "matrix_client_element_enabled | bool and matrix_client_riot_web_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-riot-web.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_element_enabled|bool and matrix_client_riot_web_service_stat.stat.exists" + when: "matrix_client_element_enabled | bool and matrix_client_riot_web_service_stat.stat.exists" - name: Check existence of /matrix/riot-web - stat: + ansible.builtin.stat: path: "/matrix/riot-web" register: matrix_client_riot_web_dir_stat - when: "matrix_client_element_enabled|bool" + when: "matrix_client_element_enabled | bool" - name: Relocate /matrix/riot-web to /matrix/client-element - command: "mv /matrix/riot-web /matrix/client-element" - when: "matrix_client_element_enabled|bool and matrix_client_riot_web_dir_stat.stat.exists" + ansible.builtin.command: "mv /matrix/riot-web /matrix/client-element" + when: "matrix_client_element_enabled | bool and matrix_client_riot_web_dir_stat.stat.exists" diff --git a/roles/matrix-client-element/tasks/prepare_themes.yml b/roles/matrix-client-element/tasks/prepare_themes.yml index bfb9837bc..8185122c6 100644 --- a/roles/matrix-client-element/tasks/prepare_themes.yml +++ b/roles/matrix-client-element/tasks/prepare_themes.yml @@ -6,32 +6,33 @@ - block: - name: Ensure Element themes repository is pulled - git: + ansible.builtin.git: repo: "{{ matrix_client_element_themes_repository_url }}" + version: "{{ matrix_client_element_themes_repository_version }}" dest: "{{ role_path }}/files/scratchpad/themes" - name: Find all Element theme files - find: + ansible.builtin.find: paths: "{{ role_path }}/files/scratchpad/themes" patterns: "*.json" recurse: true register: matrix_client_element_theme_file_list - name: Read Element theme - slurp: + ansible.builtin.slurp: path: "{{ item.path }}" register: "matrix_client_element_theme_file_contents" with_items: "{{ matrix_client_element_theme_file_list.files }}" - name: Load Element theme - set_fact: - matrix_client_element_settingDefaults_custom_themes: "{{ matrix_client_element_settingDefaults_custom_themes + [item['content'] | b64decode | from_json] }}" + ansible.builtin.set_fact: + matrix_client_element_settingDefaults_custom_themes: "{{ matrix_client_element_settingDefaults_custom_themes + [item['content'] | b64decode | from_json] }}" # noqa var-naming with_items: "{{ matrix_client_element_theme_file_contents.results }}" run_once: true delegate_to: 127.0.0.1 become: false - when: matrix_client_element_themes_enabled|bool + when: matrix_client_element_themes_enabled | bool # @@ -39,10 +40,10 @@ # - name: Ensure Element themes repository is removed - file: + ansible.builtin.file: path: "{{ role_path }}/files/scratchpad/themes" state: absent run_once: true delegate_to: 127.0.0.1 become: false - when: "not matrix_client_element_themes_enabled|bool" + when: "not matrix_client_element_themes_enabled | bool" diff --git a/roles/matrix-client-element/tasks/self_check.yml b/roles/matrix-client-element/tasks/self_check.yml index d05644c80..031bb5f90 100644 --- a/roles/matrix-client-element/tasks/self_check.yml +++ b/roles/matrix-client-element/tasks/self_check.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_client_element_url_endpoint_public: "https://{{ matrix_server_fqn_element }}/config.json" - name: Check Element - uri: + ansible.builtin.uri: url: "{{ matrix_client_element_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_client_element_self_check_validate_certificates }}" @@ -13,10 +13,10 @@ ignore_errors: true - name: Fail if Element not working - fail: + ansible.builtin.fail: msg: "Failed checking Element is up at `{{ matrix_server_fqn_element }}` (checked endpoint: `{{ matrix_client_element_url_endpoint_public }}`). Is Element running? Is port 443 open in your firewall? Full error: {{ matrix_client_element_self_check_result }}" when: "matrix_client_element_self_check_result.failed or 'json' not in matrix_client_element_self_check_result" - name: Report working Element - debug: + ansible.builtin.debug: msg: "Element at `{{ matrix_server_fqn_element }}` is working (checked endpoint: `{{ matrix_client_element_url_endpoint_public }}`)" diff --git a/roles/matrix-client-element/tasks/setup_install.yml b/roles/matrix-client-element/tasks/setup_install.yml index 4d0af82d6..5fa34fa6e 100644 --- a/roles/matrix-client-element/tasks/setup_install.yml +++ b/roles/matrix-client-element/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure Element paths exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -10,7 +10,7 @@ with_items: - {path: "{{ matrix_client_element_data_path }}", when: true} - {path: "{{ matrix_client_element_docker_src_files_path }}", when: "{{ matrix_client_element_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Element Docker image is pulled docker_image: @@ -18,14 +18,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_client_element_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_client_element_docker_image_force_pull }}" - when: "not matrix_client_element_container_image_self_build|bool" + when: "not matrix_client_element_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Element repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_client_element_container_image_self_build_repo }}" dest: "{{ matrix_client_element_docker_src_files_path }}" version: "{{ matrix_client_element_docker_image.split(':')[1] }}" @@ -33,21 +33,21 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_client_element_git_pull_results - when: "matrix_client_element_container_image_self_build|bool" + when: "matrix_client_element_container_image_self_build | bool" # See: # - https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1357 # - https://github.com/vector-im/element-web/issues/19544 - name: Patch webpack.config.js to support building on low-memory (<4G RAM) devices - lineinfile: + ansible.builtin.lineinfile: path: "{{ matrix_client_element_docker_src_files_path }}/webpack.config.js" regexp: '(\s+)splitChunks: \{' line: '\1splitChunks: { maxSize: 100000,' backrefs: true owner: root - group: root + ansible.builtin.group: root mode: '0644' - when: "matrix_client_element_container_image_self_build|bool and matrix_client_element_container_image_self_build_low_memory_system_patch_enabled|bool" + when: "matrix_client_element_container_image_self_build | bool and matrix_client_element_container_image_self_build_low_memory_system_patch_enabled | bool" - name: Ensure Element Docker image is built docker_image: @@ -59,18 +59,18 @@ dockerfile: Dockerfile path: "{{ matrix_client_element_docker_src_files_path }}" pull: true - when: "matrix_client_element_container_image_self_build|bool" + when: "matrix_client_element_container_image_self_build | bool" - name: Ensure Element configuration installed - copy: - content: "{{ matrix_client_element_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_client_element_configuration | to_nice_json }}" dest: "{{ matrix_client_element_data_path }}/config.json" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Element config files installed - template: + ansible.builtin.template: src: "{{ item.src }}" dest: "{{ matrix_client_element_data_path }}/{{ item.name }}" mode: 0644 @@ -83,7 +83,7 @@ when: "item.src is not none" - name: Ensure Element config files removed - file: + ansible.builtin.file: path: "{{ matrix_client_element_data_path }}/{{ item.name }}" state: absent with_items: @@ -91,13 +91,13 @@ when: "item.src is none" - name: Ensure matrix-client-element.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-client-element.service.j2" dest: "{{ matrix_systemd_path }}/matrix-client-element.service" mode: 0644 register: matrix_client_element_systemd_service_result - name: Ensure systemd reloaded after matrix-client-element.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_element_systemd_service_result.changed|bool" + when: "matrix_client_element_systemd_service_result.changed | bool" diff --git a/roles/matrix-client-element/tasks/setup_uninstall.yml b/roles/matrix-client-element/tasks/setup_uninstall.yml index 55bc20d6a..b3cdd05e5 100644 --- a/roles/matrix-client-element/tasks/setup_uninstall.yml +++ b/roles/matrix-client-element/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-client-element.service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-client-element.service" register: matrix_client_element_service_stat - name: Ensure matrix-client-element is stopped - service: + ansible.builtin.service: name: matrix-client-element state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_client_element_service_stat.stat.exists|bool" + when: "matrix_client_element_service_stat.stat.exists | bool" - name: Ensure matrix-client-element.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-client-element.service" state: absent - when: "matrix_client_element_service_stat.stat.exists|bool" + when: "matrix_client_element_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-client-element.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_element_service_stat.stat.exists|bool" + when: "matrix_client_element_service_stat.stat.exists | bool" - name: Ensure Element paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_client_element_data_path }}" state: absent diff --git a/roles/matrix-client-element/tasks/validate_config.yml b/roles/matrix-client-element/tasks/validate_config.yml index d246b612a..fdf74f07d 100644 --- a/roles/matrix-client-element/tasks/validate_config.yml +++ b/roles/matrix-client-element/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required Element settings not defined - fail: + ansible.builtin.fail: msg: > You need to define a required configuration setting (`{{ item }}`) for using Element. when: "vars[item] == ''" @@ -9,7 +9,7 @@ - "matrix_client_element_default_hs_url" - name: (Deprecation) Catch and report riot-web variables - fail: + ansible.builtin.fail: msg: >- Riot has been renamed to Element (https://element.io/blog/welcome-to-element/). The playbook will migrate your existing configuration and data automatically, but you need to adjust variable names. diff --git a/roles/matrix-client-element/templates/config.json.j2 b/roles/matrix-client-element/templates/config.json.j2 index e87907e43..e34773981 100644 --- a/roles/matrix-client-element/templates/config.json.j2 +++ b/roles/matrix-client-element/templates/config.json.j2 @@ -1,25 +1,25 @@ { "default_server_config": { "m.homeserver": { - "base_url": {{ matrix_client_element_default_hs_url|string|to_json }}, - "server_name": {{ matrix_client_element_default_server_name|string|to_json }} + "base_url": {{ matrix_client_element_default_hs_url | string|to_json }}, + "server_name": {{ matrix_client_element_default_server_name | string|to_json }} }, "m.identity_server": { - "base_url": {{ matrix_client_element_default_is_url|string|to_json }} + "base_url": {{ matrix_client_element_default_is_url | string|to_json }} } }, "settingDefaults": { "custom_themes": {{ matrix_client_element_settingDefaults_custom_themes|to_json }} }, - "default_theme": {{ matrix_client_element_default_theme|string|to_json }}, - "permalinkPrefix": {{ matrix_client_element_permalinkPrefix|string|to_json }}, + "default_theme": {{ matrix_client_element_default_theme | string|to_json }}, + "permalinkPrefix": {{ matrix_client_element_permalinkPrefix | string|to_json }}, "disable_custom_urls": {{ matrix_client_element_disable_custom_urls|to_json }}, "disable_guests": {{ matrix_client_element_disable_guests|to_json }}, "brand": {{ matrix_client_element_brand|to_json }}, - "integrations_ui_url": {{ matrix_client_element_integrations_ui_url|string|to_json }}, - "integrations_rest_url": {{ matrix_client_element_integrations_rest_url|string|to_json }}, + "integrations_ui_url": {{ matrix_client_element_integrations_ui_url | string|to_json }}, + "integrations_rest_url": {{ matrix_client_element_integrations_rest_url | string|to_json }}, "integrations_widgets_urls": {{ matrix_client_element_integrations_widgets_urls|to_json }}, - "integrations_jitsi_widget_url": {{ matrix_client_element_integrations_jitsi_widget_url|string|to_json }}, + "integrations_jitsi_widget_url": {{ matrix_client_element_integrations_jitsi_widget_url | string|to_json }}, "bug_report_endpoint_url": {{ matrix_client_element_bug_report_endpoint_url|to_json }}, "showLabsSettings": {{ matrix_client_element_showLabsSettings|to_json }}, "roomDirectory": { @@ -30,7 +30,7 @@ "enable_presence_by_hs_url": {{ matrix_client_element_enable_presence_by_hs_url|to_json }}, {% endif %} "embeddedPages": { - "homeUrl": {{ matrix_client_element_embedded_pages_home_url|string|to_json }} + "homeUrl": {{ matrix_client_element_embedded_pages_home_url | string|to_json }} }, {% if matrix_client_element_jitsi_preferredDomain %} "jitsi": { diff --git a/roles/matrix-client-hydrogen/defaults/main.yml b/roles/matrix-client-hydrogen/defaults/main.yml index 8171fc120..1baccdd30 100644 --- a/roles/matrix-client-hydrogen/defaults/main.yml +++ b/roles/matrix-client-hydrogen/defaults/main.yml @@ -64,8 +64,8 @@ matrix_client_hydrogen_configuration_default: "{{ lookup('template', 'templates/ # } matrix_client_hydrogen_configuration_extension_json: '{}' -matrix_client_hydrogen_configuration_extension: "{{ matrix_client_hydrogen_configuration_extension_json|from_json if matrix_client_hydrogen_configuration_extension_json|from_json is mapping else {} }}" +matrix_client_hydrogen_configuration_extension: "{{ matrix_client_hydrogen_configuration_extension_json | from_json if matrix_client_hydrogen_configuration_extension_json | from_json is mapping else {} }}" # Holds the final Hydrogen configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_client_hydrogen_configuration_default`. -matrix_client_hydrogen_configuration: "{{ matrix_client_hydrogen_configuration_default|combine(matrix_client_hydrogen_configuration_extension, recursive=True) }}" +matrix_client_hydrogen_configuration: "{{ matrix_client_hydrogen_configuration_default | combine(matrix_client_hydrogen_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-client-hydrogen/tasks/init.yml b/roles/matrix-client-hydrogen/tasks/init.yml index c6801e517..561018e1a 100644 --- a/roles/matrix-client-hydrogen/tasks/init.yml +++ b/roles/matrix-client-hydrogen/tasks/init.yml @@ -2,10 +2,10 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Hydrogen 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_client_hydrogen_container_image_self_build and matrix_client_hydrogen_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-client-hydrogen.service'] }}" - when: matrix_client_hydrogen_enabled|bool + when: matrix_client_hydrogen_enabled | bool diff --git a/roles/matrix-client-hydrogen/tasks/main.yml b/roles/matrix-client-hydrogen/tasks/main.yml index d027fe660..89133364e 100644 --- a/roles/matrix-client-hydrogen/tasks/main.yml +++ b/roles/matrix-client-hydrogen/tasks/main.yml @@ -1,30 +1,30 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_client_hydrogen_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_client_hydrogen_enabled | bool" tags: - setup-all - setup-client-hydrogen -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_client_hydrogen_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_client_hydrogen_enabled | bool" tags: - setup-all - setup-client-hydrogen -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_client_hydrogen_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_client_hydrogen_enabled | bool" tags: - setup-all - setup-client-hydrogen -- import_tasks: "{{ role_path }}/tasks/self_check.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check.yml" delegate_to: 127.0.0.1 become: false - when: "run_self_check|bool and matrix_client_hydrogen_enabled|bool" + when: "run_self_check | bool and matrix_client_hydrogen_enabled | bool" tags: - self-check diff --git a/roles/matrix-client-hydrogen/tasks/self_check.yml b/roles/matrix-client-hydrogen/tasks/self_check.yml index 0c6642318..978e531f2 100644 --- a/roles/matrix-client-hydrogen/tasks/self_check.yml +++ b/roles/matrix-client-hydrogen/tasks/self_check.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_client_hydrogen_url_endpoint_public: "https://{{ matrix_server_fqn_hydrogen }}/config.json" - name: Check Hydrogen - uri: + ansible.builtin.uri: url: "{{ matrix_client_hydrogen_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_client_hydrogen_self_check_validate_certificates }}" @@ -13,10 +13,10 @@ ignore_errors: true - name: Fail if Hydrogen not working - fail: + ansible.builtin.fail: msg: "Failed checking Hydrogen is up at `{{ matrix_server_fqn_hydrogen }}` (checked endpoint: `{{ matrix_client_hydrogen_url_endpoint_public }}`). Is Hydrogen running? Is port 443 open in your firewall? Full error: {{ matrix_client_hydrogen_self_check_result }}" when: "matrix_client_hydrogen_self_check_result.failed or 'json' not in matrix_client_hydrogen_self_check_result" - name: Report working Hydrogen - debug: + ansible.builtin.debug: msg: "Hydrogen at `{{ matrix_server_fqn_hydrogen }}` is working (checked endpoint: `{{ matrix_client_hydrogen_url_endpoint_public }}`)" diff --git a/roles/matrix-client-hydrogen/tasks/setup_install.yml b/roles/matrix-client-hydrogen/tasks/setup_install.yml index db866178e..4cd445d01 100644 --- a/roles/matrix-client-hydrogen/tasks/setup_install.yml +++ b/roles/matrix-client-hydrogen/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure Hydrogen paths exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -10,7 +10,7 @@ with_items: - {path: "{{ matrix_client_hydrogen_data_path }}", when: true} - {path: "{{ matrix_client_hydrogen_docker_src_files_path }}", when: "{{ matrix_client_hydrogen_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Hydrogen Docker image is pulled docker_image: @@ -18,14 +18,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_client_hydrogen_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_client_hydrogen_docker_image_force_pull }}" - when: "not matrix_client_hydrogen_container_image_self_build|bool" + when: "not matrix_client_hydrogen_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Hydrogen repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_client_hydrogen_container_image_self_build_repo }}" dest: "{{ matrix_client_hydrogen_docker_src_files_path }}" version: "{{ matrix_client_hydrogen_docker_image.split(':')[1] }}" @@ -33,19 +33,19 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_client_hydrogen_git_pull_results - when: "matrix_client_hydrogen_container_image_self_build|bool" + when: "matrix_client_hydrogen_container_image_self_build | bool" - name: Ensure Hydrogen configuration installed - copy: - content: "{{ matrix_client_hydrogen_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_client_hydrogen_configuration | to_nice_json }}" dest: "{{ matrix_client_hydrogen_docker_src_files_path }}/src/platform/web/assets/config.json" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: "matrix_client_hydrogen_container_image_self_build|bool" + when: "matrix_client_hydrogen_container_image_self_build | bool" - name: Ensure Hydrogen additional config files installed - template: + ansible.builtin.template: src: "{{ item.src }}" dest: "{{ matrix_client_hydrogen_data_path }}/{{ item.name }}" mode: 0644 @@ -66,16 +66,16 @@ dockerfile: Dockerfile path: "{{ matrix_client_hydrogen_docker_src_files_path }}" pull: true - when: "matrix_client_hydrogen_container_image_self_build|bool" + when: "matrix_client_hydrogen_container_image_self_build | bool" - name: Ensure matrix-client-hydrogen.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-client-hydrogen.service.j2" dest: "{{ matrix_systemd_path }}/matrix-client-hydrogen.service" mode: 0644 register: matrix_client_hydrogen_systemd_service_result - name: Ensure systemd reloaded after matrix-client-hydrogen.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_hydrogen_systemd_service_result.changed|bool" + when: "matrix_client_hydrogen_systemd_service_result.changed | bool" diff --git a/roles/matrix-client-hydrogen/tasks/setup_uninstall.yml b/roles/matrix-client-hydrogen/tasks/setup_uninstall.yml index 7aff2916f..d543cbb32 100644 --- a/roles/matrix-client-hydrogen/tasks/setup_uninstall.yml +++ b/roles/matrix-client-hydrogen/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-client-hydrogen.service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-client-hydrogen.service" register: matrix_client_hydrogen_service_stat - name: Ensure matrix-client-hydrogen is stopped - service: + ansible.builtin.service: name: matrix-client-hydrogen state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_client_hydrogen_service_stat.stat.exists|bool" + when: "matrix_client_hydrogen_service_stat.stat.exists | bool" - name: Ensure matrix-client-hydrogen.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-client-hydrogen.service" state: absent - when: "matrix_client_hydrogen_service_stat.stat.exists|bool" + when: "matrix_client_hydrogen_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-client-hydrogen.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_client_hydrogen_service_stat.stat.exists|bool" + when: "matrix_client_hydrogen_service_stat.stat.exists | bool" - name: Ensure Hydrogen paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_client_hydrogen_data_path }}" state: absent diff --git a/roles/matrix-client-hydrogen/tasks/validate_config.yml b/roles/matrix-client-hydrogen/tasks/validate_config.yml index d3b9a709b..65b0e14f6 100644 --- a/roles/matrix-client-hydrogen/tasks/validate_config.yml +++ b/roles/matrix-client-hydrogen/tasks/validate_config.yml @@ -1,9 +1,9 @@ --- - name: Fail if required Hydrogen settings not defined - fail: + ansible.builtin.fail: msg: > You need to define a required configuration setting (`{{ item }}`) to use Hydrogen. - when: "(vars[item] == '' or vars[item] is none) and matrix_client_hydrogen_container_image_self_build|bool" + when: "(vars[item] == '' or vars[item] is none) and matrix_client_hydrogen_container_image_self_build | bool" with_items: - "matrix_client_hydrogen_default_hs_url" diff --git a/roles/matrix-client-hydrogen/templates/config.json.j2 b/roles/matrix-client-hydrogen/templates/config.json.j2 index 3e5563546..0c4331b60 100644 --- a/roles/matrix-client-hydrogen/templates/config.json.j2 +++ b/roles/matrix-client-hydrogen/templates/config.json.j2 @@ -4,7 +4,7 @@ "gatewayUrl": "https://matrix.org", "applicationServerKey": "BC-gpSdVHEXhvHSHS0AzzWrQoukv2BE7KzpoPO_FfPacqOo3l1pdqz7rSgmB04pZCWaHPz7XRe6fjLaC-WPDopM" }, - "defaultHomeServer": {{ matrix_client_hydrogen_default_hs_url|string|to_json }}, + "defaultHomeServer": {{ matrix_client_hydrogen_default_hs_url | string|to_json }}, "bugReportEndpointUrl": "https://element.io/bugreports/submit", "themeManifests": [ "assets/theme-Element.json" diff --git a/roles/matrix-common-after/tasks/dump_runtime_results.yml b/roles/matrix-common-after/tasks/dump_runtime_results.yml index 44ae1a308..4074a625d 100644 --- a/roles/matrix-common-after/tasks/dump_runtime_results.yml +++ b/roles/matrix-common-after/tasks/dump_runtime_results.yml @@ -1,7 +1,7 @@ --- # Ansible outputs the message in the `item=` field. # It's unnecessary to output it again in the actual message, so we don't. -- debug: +- ansible.builtin.debug: msg: "" with_items: "{{ matrix_playbook_runtime_results }}" when: "matrix_playbook_runtime_results is defined and matrix_playbook_runtime_results|length > 0" diff --git a/roles/matrix-common-after/tasks/main.yml b/roles/matrix-common-after/tasks/main.yml index f3ccf3a52..1b360698d 100644 --- a/roles/matrix-common-after/tasks/main.yml +++ b/roles/matrix-common-after/tasks/main.yml @@ -1,19 +1,19 @@ --- -- import_tasks: "{{ role_path }}/tasks/start.yml" - when: run_start|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/start.yml" + when: run_start | bool tags: - start -- import_tasks: "{{ role_path }}/tasks/stop.yml" - when: run_stop|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/stop.yml" + when: run_stop | bool tags: - stop -- import_tasks: "{{ role_path }}/tasks/dump_runtime_results.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/dump_runtime_results.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/run_docker_prune.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/run_docker_prune.yml" tags: - run-docker-prune diff --git a/roles/matrix-common-after/tasks/run_docker_prune.yml b/roles/matrix-common-after/tasks/run_docker_prune.yml index a7e35a03b..02dfadc5c 100644 --- a/roles/matrix-common-after/tasks/run_docker_prune.yml +++ b/roles/matrix-common-after/tasks/run_docker_prune.yml @@ -1,4 +1,7 @@ --- - name: Run Docker System Prune - command: "{{ matrix_host_command_docker }} system prune -a -f" + ansible.builtin.command: + cmd: "{{ matrix_host_command_docker }} system prune -a -f" + register: matrix_common_after_docker_prune_result + changed_when: matrix_common_after_docker_prune_result.rc == 0 diff --git a/roles/matrix-common-after/tasks/start.yml b/roles/matrix-common-after/tasks/start.yml index 02fa672e3..890eabfab 100644 --- a/roles/matrix-common-after/tasks/start.yml +++ b/roles/matrix-common-after/tasks/start.yml @@ -1,22 +1,22 @@ --- - name: Determine whether we should make services autostart - set_fact: - matrix_services_autostart_enabled_bool: "{{ true if matrix_services_autostart_enabled|default('') == '' else matrix_services_autostart_enabled|bool }}" + ansible.builtin.set_fact: + matrix_services_autostart_enabled_bool: "{{ true if matrix_services_autostart_enabled | default('') == '' else matrix_services_autostart_enabled | bool }}" - name: Ensure systemd is reloaded - service: + ansible.builtin.service: daemon_reload: true - name: Ensure Matrix services are stopped - service: + ansible.builtin.service: name: "{{ item }}" state: stopped with_items: "{{ matrix_systemd_services_list }}" when: not ansible_check_mode - name: Ensure Matrix services are started - service: + ansible.builtin.service: name: "{{ item }}" enabled: "{{ matrix_services_autostart_enabled_bool }}" state: started @@ -29,17 +29,17 @@ # Waiting too long (30s) may not work for a similar reason, # as we may run into systemd's automatic restart logic retrying the service. - name: Wait a bit, so that services can start (or fail) - wait_for: + ansible.builtin.wait_for: timeout: "{{ matrix_common_after_systemd_service_start_wait_for_timeout_seconds }}" delegate_to: 127.0.0.1 become: false - block: - name: Populate service facts - service_facts: + ansible.builtin.service_facts: - name: Fail if service isn't detected to be running - fail: + ansible.builtin.fail: msg: >- {{ item }} was not detected to be running. It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.). @@ -57,13 +57,13 @@ # service_facts is not collecting the data successfully. # Therefore iterating here manually - name: Fetch systemd information - systemd: + ansible.builtin.systemd: name: "{{ item }}" register: systemdstatus with_items: "{{ matrix_systemd_services_list }}" - name: Fail if service isn't detected to be running - fail: + ansible.builtin.fail: msg: >- {{ item.item }} was not detected to be running. It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.). diff --git a/roles/matrix-common-after/tasks/stop.yml b/roles/matrix-common-after/tasks/stop.yml index 5ae0afbba..a343999c6 100644 --- a/roles/matrix-common-after/tasks/stop.yml +++ b/roles/matrix-common-after/tasks/stop.yml @@ -1,7 +1,7 @@ --- - name: Ensure Matrix services stopped - service: + ansible.builtin.service: name: "{{ item }}" state: stopped with_items: "{{ matrix_systemd_services_list }}" diff --git a/roles/matrix-corporal/defaults/main.yml b/roles/matrix-corporal/defaults/main.yml index 1aa512eec..bb1b8fa19 100644 --- a/roles/matrix-corporal/defaults/main.yml +++ b/roles/matrix-corporal/defaults/main.yml @@ -100,8 +100,8 @@ matrix_corporal_configuration_default: "{{ lookup('template', 'templates/config. # } matrix_corporal_configuration_extension_json: '{}' -matrix_corporal_configuration_extension: "{{ matrix_corporal_configuration_extension_json|from_json if matrix_corporal_configuration_extension_json|from_json is mapping else {} }}" +matrix_corporal_configuration_extension: "{{ matrix_corporal_configuration_extension_json | from_json if matrix_corporal_configuration_extension_json | from_json is mapping else {} }}" # Holds the final Corporal configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_corporal_configuration_default`. -matrix_corporal_configuration: "{{ matrix_corporal_configuration_default|combine(matrix_corporal_configuration_extension, recursive=True) }}" +matrix_corporal_configuration: "{{ matrix_corporal_configuration_default | combine(matrix_corporal_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-corporal/tasks/init.yml b/roles/matrix-corporal/tasks/init.yml index b2f50e939..c6686a37f 100644 --- a/roles/matrix-corporal/tasks/init.yml +++ b/roles/matrix-corporal/tasks/init.yml @@ -2,10 +2,10 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_corporal_container_image_self_build and matrix_corporal_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-corporal.service'] }}" - when: matrix_corporal_enabled|bool + when: matrix_corporal_enabled | bool diff --git a/roles/matrix-corporal/tasks/main.yml b/roles/matrix-corporal/tasks/main.yml index 7ff359d0c..1699262b1 100644 --- a/roles/matrix-corporal/tasks/main.yml +++ b/roles/matrix-corporal/tasks/main.yml @@ -1,24 +1,24 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_corporal_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_corporal_enabled | bool" tags: - setup-all - setup-corporal -- import_tasks: "{{ role_path }}/tasks/setup_corporal.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_corporal.yml" + when: run_setup | bool tags: - setup-all - setup-corporal -- import_tasks: "{{ role_path }}/tasks/self_check_corporal.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_corporal.yml" delegate_to: 127.0.0.1 become: false - when: "run_self_check|bool and matrix_corporal_enabled|bool" + when: "run_self_check | bool and matrix_corporal_enabled | bool" tags: - self-check diff --git a/roles/matrix-corporal/tasks/self_check_corporal.yml b/roles/matrix-corporal/tasks/self_check_corporal.yml index b702c00f1..3ddda8e04 100644 --- a/roles/matrix-corporal/tasks/self_check_corporal.yml +++ b/roles/matrix-corporal/tasks/self_check_corporal.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: corporal_client_api_url_endpoint_public: "https://{{ matrix_server_fqn_matrix }}/_matrix/client/corporal" - name: Check Matrix Corporal HTTP gateway - uri: + ansible.builtin.uri: url: "{{ corporal_client_api_url_endpoint_public }}" follow_redirects: none return_content: true @@ -13,10 +13,10 @@ ignore_errors: true - name: Fail if Matrix Corporal HTTP gateway not working - fail: + ansible.builtin.fail: msg: "Failed checking Matrix Corporal is fronting the Matrix Client API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ corporal_client_api_url_endpoint_public }}`). Is matrix-corporal running? Is port 443 open in your firewall? Full error: {{ result_corporal_client_api }}" when: "result_corporal_client_api.failed or 'Matrix Client-Server API protected by Matrix Corporal' not in result_corporal_client_api.content" - name: Report working Matrix Corporal HTTP gateway - debug: + ansible.builtin.debug: msg: "Matrix Corporal is fronting the Matrix Client API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ corporal_client_api_url_endpoint_public }}`)" diff --git a/roles/matrix-corporal/tasks/setup_corporal.yml b/roles/matrix-corporal/tasks/setup_corporal.yml index a3582592c..583c27eba 100644 --- a/roles/matrix-corporal/tasks/setup_corporal.yml +++ b/roles/matrix-corporal/tasks/setup_corporal.yml @@ -5,7 +5,7 @@ # - name: Ensure Matrix Corporal paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -15,10 +15,10 @@ - "{{ matrix_corporal_config_dir_path }}" - "{{ matrix_corporal_cache_dir_path }}" - "{{ matrix_corporal_var_dir_path }}" - when: matrix_corporal_enabled|bool + when: matrix_corporal_enabled | bool - name: Ensure Matrix Corporal repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_corporal_container_image_self_build_repo }}" dest: "{{ matrix_corporal_container_src_files_path }}" version: "{{ matrix_corporal_docker_image.split(':')[1] }}" @@ -26,7 +26,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_corporal_git_pull_results - when: "matrix_corporal_enabled|bool and matrix_corporal_container_image_self_build|bool" + when: "matrix_corporal_enabled | bool and matrix_corporal_container_image_self_build | bool" - name: Ensure Matrix Corporal Docker image is built docker_image: @@ -38,7 +38,7 @@ dockerfile: etc/docker/Dockerfile path: "{{ matrix_corporal_container_src_files_path }}" pull: true - when: "matrix_corporal_enabled|bool and matrix_corporal_container_image_self_build|bool" + when: "matrix_corporal_enabled | bool and matrix_corporal_container_image_self_build | bool" - name: Ensure Matrix Corporal Docker image is pulled docker_image: @@ -46,33 +46,33 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_corporal_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_corporal_docker_image_force_pull }}" - when: "matrix_corporal_enabled|bool and not matrix_corporal_container_image_self_build|bool" + when: "matrix_corporal_enabled | bool and not matrix_corporal_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Matrix Corporal config installed - copy: - content: "{{ matrix_corporal_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_corporal_configuration | to_nice_json }}" dest: "{{ matrix_corporal_config_dir_path }}/config.json" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_corporal_enabled|bool + when: matrix_corporal_enabled | bool - name: Ensure matrix-corporal.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-corporal.service.j2" dest: "{{ matrix_systemd_path }}/matrix-corporal.service" mode: 0644 register: matrix_corporal_systemd_service_result - when: matrix_corporal_enabled|bool + when: matrix_corporal_enabled | bool - name: Ensure systemd reloaded after matrix-corporal.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_corporal_enabled|bool and matrix_corporal_systemd_service_result.changed" + when: "matrix_corporal_enabled | bool and matrix_corporal_systemd_service_result.changed" # @@ -80,42 +80,42 @@ # - name: Check existence of matrix-corporal service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-corporal.service" register: matrix_corporal_service_stat - when: "not matrix_corporal_enabled|bool" + when: "not matrix_corporal_enabled | bool" - name: Ensure matrix-corporal is stopped - service: + ansible.builtin.service: name: matrix-corporal state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_corporal_enabled|bool and matrix_corporal_service_stat.stat.exists" + when: "not matrix_corporal_enabled | bool and matrix_corporal_service_stat.stat.exists" - name: Ensure matrix-corporal.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-corporal.service" state: absent - when: "not matrix_corporal_enabled|bool and matrix_corporal_service_stat.stat.exists" + when: "not matrix_corporal_enabled | bool and matrix_corporal_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-corporal.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_corporal_enabled|bool and matrix_corporal_service_stat.stat.exists" + when: "not matrix_corporal_enabled | bool and matrix_corporal_service_stat.stat.exists" - name: Ensure matrix-corporal files don't exist - file: + ansible.builtin.file: path: "{{ item }}" state: absent with_items: - "{{ matrix_systemd_path }}/matrix-corporal.service" - "{{ matrix_corporal_config_dir_path }}/config.json" - when: "not matrix_corporal_enabled|bool" + when: "not matrix_corporal_enabled | bool" - name: Ensure Matrix Corporal Docker image doesn't exist docker_image: name: "{{ matrix_corporal_docker_image }}" state: absent - when: "not matrix_corporal_enabled|bool" + when: "not matrix_corporal_enabled | bool" diff --git a/roles/matrix-corporal/tasks/validate_config.yml b/roles/matrix-corporal/tasks/validate_config.yml index a8930e7ed..26d16c6df 100644 --- a/roles/matrix-corporal/tasks/validate_config.yml +++ b/roles/matrix-corporal/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required matrix-corporal settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) for using matrix-corporal. when: "vars[item] == ''" @@ -12,12 +12,12 @@ - "matrix_corporal_policy_provider_config" - name: Fail if HTTP API enabled, but no token set - fail: + ansible.builtin.fail: msg: "The Matrix Corporal HTTP API is enabled (`matrix_corporal_http_api_enabled`), but no auth token has been set in `matrix_corporal_http_api_auth_token`" - when: "matrix_corporal_http_api_enabled|bool and matrix_corporal_http_api_auth_token == ''" + when: "matrix_corporal_http_api_enabled | bool and matrix_corporal_http_api_auth_token == ''" - name: (Deprecation) Catch and report renamed corporal variables - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-coturn/tasks/init.yml b/roles/matrix-coturn/tasks/init.yml index 93e4fa3a2..60a772647 100644 --- a/roles/matrix-coturn/tasks/init.yml +++ b/roles/matrix-coturn/tasks/init.yml @@ -2,14 +2,14 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_coturn_container_image_self_build and matrix_coturn_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-coturn.service'] }}" - when: matrix_coturn_enabled|bool + when: matrix_coturn_enabled | bool -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-coturn-reload.timer'] }}" - when: "matrix_coturn_enabled|bool and matrix_coturn_tls_enabled|bool" + when: "matrix_coturn_enabled | bool and matrix_coturn_tls_enabled | bool" diff --git a/roles/matrix-coturn/tasks/main.yml b/roles/matrix-coturn/tasks/main.yml index 76352df12..78f712f01 100644 --- a/roles/matrix-coturn/tasks/main.yml +++ b/roles/matrix-coturn/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_coturn_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_coturn_enabled | bool" tags: - setup-all - setup-coturn -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_coturn_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_coturn_enabled | bool" tags: - setup-all - setup-coturn -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_coturn_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_coturn_enabled | bool" tags: - setup-all - setup-coturn diff --git a/roles/matrix-coturn/tasks/setup_install.yml b/roles/matrix-coturn/tasks/setup_install.yml index a721f186b..2a1af7310 100644 --- a/roles/matrix-coturn/tasks/setup_install.yml +++ b/roles/matrix-coturn/tasks/setup_install.yml @@ -2,12 +2,12 @@ # This is a cleanup/migration task. It can be removed some time in the future. - name: (Migration) Remove deprecated cronjob - file: + ansible.builtin.file: path: "{{ matrix_cron_path }}/matrix-coturn-ssl-reload" state: absent - name: Ensure Matrix Coturn path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -15,7 +15,7 @@ group: "{{ matrix_user_groupname }}" with_items: - {path: "{{ matrix_coturn_docker_src_files_path }}", when: "{{ matrix_coturn_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Coturn image is pulled docker_image: @@ -23,7 +23,7 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_coturn_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_coturn_docker_image_force_pull }}" - when: "not matrix_coturn_container_image_self_build|bool" + when: "not matrix_coturn_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" @@ -31,7 +31,7 @@ - block: - name: Ensure Coturn repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_coturn_container_image_self_build_repo }}" dest: "{{ matrix_coturn_docker_src_files_path }}" version: "{{ matrix_coturn_container_image_self_build_repo_version }}" @@ -50,10 +50,10 @@ dockerfile: "{{ matrix_coturn_container_image_self_build_repo_dockerfile_path }}" path: "{{ matrix_coturn_docker_src_files_path }}" pull: true - when: "matrix_coturn_container_image_self_build|bool" + when: "matrix_coturn_container_image_self_build | bool" - name: Ensure Coturn configuration path exists - file: + ansible.builtin.file: path: "{{ matrix_coturn_base_path }}" state: directory mode: 0750 @@ -61,7 +61,7 @@ group: "{{ matrix_user_groupname }}" - name: Ensure turnserver.conf installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/turnserver.conf.j2" dest: "{{ matrix_coturn_config_path }}" mode: 0644 @@ -74,7 +74,7 @@ driver: bridge - name: Ensure matrix-coturn.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-coturn.service.j2" dest: "{{ matrix_systemd_path }}/matrix-coturn.service" mode: 0644 @@ -84,28 +84,28 @@ # We optimize for the common use-case though (short-lived Let's Encrypt certificates). # Reloading doesn't hurt anyway, so there's no need to make this more flexible. - name: Ensure reloading systemd units installed, if necessary - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/{{ item }}.j2" dest: "{{ matrix_systemd_path }}/{{ item }}" mode: 0644 register: "matrix_coturn_systemd_service_change_results" - when: "matrix_coturn_tls_enabled|bool" + when: "matrix_coturn_tls_enabled | bool" with_items: - matrix-coturn-reload.service - matrix-coturn-reload.timer # A similar task exists in `setup_uninstall.yml` - name: Ensure reloading systemd units uninstalled, if unnecessary - file: + ansible.builtin.file: path: "{{ item }}" state: absent register: "matrix_coturn_systemd_service_change_results" - when: "not matrix_coturn_tls_enabled|bool" + when: "not matrix_coturn_tls_enabled | bool" with_items: - matrix-coturn-reload.service - matrix-coturn-reload.timer - name: Ensure systemd reloaded if systemd units changed - service: + ansible.builtin.service: daemon_reload: true when: "matrix_coturn_systemd_service_change_results.changed" diff --git a/roles/matrix-coturn/tasks/setup_uninstall.yml b/roles/matrix-coturn/tasks/setup_uninstall.yml index 097ba8733..5dd2788ef 100644 --- a/roles/matrix-coturn/tasks/setup_uninstall.yml +++ b/roles/matrix-coturn/tasks/setup_uninstall.yml @@ -1,30 +1,30 @@ --- - name: Check existence of matrix-coturn service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-coturn.service" register: matrix_coturn_service_stat - when: "not matrix_coturn_enabled|bool" + when: "not matrix_coturn_enabled | bool" - name: Ensure matrix-coturn is stopped - service: + ansible.builtin.service: name: matrix-coturn state: stopped enabled: false daemon_reload: true - when: "matrix_coturn_service_stat.stat.exists|bool" + when: "matrix_coturn_service_stat.stat.exists | bool" - name: Ensure matrix-coturn-reload.timer is stopped - service: + ansible.builtin.service: name: matrix-coturn state: stopped enabled: false daemon_reload: true failed_when: false - when: "matrix_coturn_service_stat.stat.exists|bool" + when: "matrix_coturn_service_stat.stat.exists | bool" - name: Ensure systemd units don't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/{{ item }}" state: absent register: matrix_coturn_systemd_unit_uninstallation_result @@ -34,12 +34,12 @@ - matrix-coturn-reload.timer - name: Ensure systemd reloaded after unit removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_coturn_systemd_unit_uninstallation_result.changed|bool" + when: "matrix_coturn_systemd_unit_uninstallation_result.changed | bool" - name: Ensure Matrix coturn paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_coturn_base_path }}" state: absent diff --git a/roles/matrix-coturn/tasks/validate_config.yml b/roles/matrix-coturn/tasks/validate_config.yml index 637f720db..90e842e13 100644 --- a/roles/matrix-coturn/tasks/validate_config.yml +++ b/roles/matrix-coturn/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required Coturn settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) for using Coturn. when: "vars[item] == ''" diff --git a/roles/matrix-dendrite/defaults/main.yml b/roles/matrix-dendrite/defaults/main.yml index 450ae6324..dd6d351ed 100644 --- a/roles/matrix-dendrite/defaults/main.yml +++ b/roles/matrix-dendrite/defaults/main.yml @@ -27,10 +27,10 @@ matrix_dendrite_http_bind_port: 8008 matrix_dendrite_https_bind_port: ~ # This is passed as an `-http-bind-address` flag to the Dendrite server in the container -matrix_dendrite_http_bind_address: "{{ (':' + matrix_dendrite_http_bind_port|string) if matrix_dendrite_http_bind_port else '' }}" +matrix_dendrite_http_bind_address: "{{ (':' + matrix_dendrite_http_bind_port | string) if matrix_dendrite_http_bind_port else '' }}" # This is passed as an `-https-bind-address` flag to the Dendrite server in the container -matrix_dendrite_https_bind_address: "{{ (':' + matrix_dendrite_https_bind_port|string) if matrix_dendrite_https_bind_port else '' }}" +matrix_dendrite_https_bind_address: "{{ (':' + matrix_dendrite_https_bind_port | string) if matrix_dendrite_https_bind_port else '' }}" # Controls whether the matrix-dendrite container exposes the HTTP port (tcp/{{ matrix_dendrite_http_bind_port }} in the container). # @@ -167,8 +167,8 @@ matrix_dendrite_configuration_extension_yaml: | # system_mxid_avatar_url: "mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ" # room_name: "Server Notices" -matrix_dendrite_configuration_extension: "{{ matrix_dendrite_configuration_extension_yaml|from_yaml if matrix_dendrite_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_dendrite_configuration_extension: "{{ matrix_dendrite_configuration_extension_yaml | from_yaml if matrix_dendrite_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final Dendrite configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_dendrite_configuration_yaml`. -matrix_dendrite_configuration: "{{ matrix_dendrite_configuration_yaml|from_yaml|combine(matrix_dendrite_configuration_extension, recursive=True) }}" +matrix_dendrite_configuration: "{{ matrix_dendrite_configuration_yaml | from_yaml | combine(matrix_dendrite_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-dendrite/tasks/dendrite/setup.yml b/roles/matrix-dendrite/tasks/dendrite/setup.yml index f988d918f..1a8497294 100644 --- a/roles/matrix-dendrite/tasks/dendrite/setup.yml +++ b/roles/matrix-dendrite/tasks/dendrite/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/dendrite/setup_install.yml" - when: matrix_dendrite_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/dendrite/setup_install.yml" + when: matrix_dendrite_enabled | bool -- import_tasks: "{{ role_path }}/tasks/dendrite/setup_uninstall.yml" - when: "not matrix_dendrite_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/dendrite/setup_uninstall.yml" + when: "not matrix_dendrite_enabled | bool" diff --git a/roles/matrix-dendrite/tasks/dendrite/setup_install.yml b/roles/matrix-dendrite/tasks/dendrite/setup_install.yml index a18ad065e..3052e1010 100644 --- a/roles/matrix-dendrite/tasks/dendrite/setup_install.yml +++ b/roles/matrix-dendrite/tasks/dendrite/setup_install.yml @@ -1,7 +1,7 @@ --- # This will throw a Permission Denied error if already mounted using fuse - name: Check Dendrite media store path - stat: + ansible.builtin.stat: path: "{{ matrix_dendrite_media_store_path }}" register: local_path_media_store_stat ignore_errors: true @@ -9,7 +9,7 @@ # This is separate and conditional, to ensure we don't execute it # if the path already exists or we failed to check, because it's mounted using fuse. - name: Ensure Dendrite media store path exists - file: + ansible.builtin.file: path: "{{ matrix_dendrite_media_store_path }}" state: directory mode: 0750 @@ -29,7 +29,7 @@ until: result is not failed - name: Check if a Dendrite signing key exists - stat: + ansible.builtin.stat: path: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem" register: matrix_dendrite_signing_key_stat @@ -37,7 +37,7 @@ # We don't use the `docker_container` module, because using it with `cap_drop` requires # a very recent version, which is not available for a lot of people yet. - name: Generate Dendrite signing key - command: | + ansible.builtin.command: | docker run --rm --name=matrix-dendrite-config @@ -48,34 +48,34 @@ when: "not matrix_dendrite_signing_key_stat.stat.exists" - name: Ensure Dendrite server key exists - file: + ansible.builtin.file: path: "{{ matrix_dendrite_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.pem" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Dendrite configuration installed - copy: - content: "{{ matrix_dendrite_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_dendrite_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_dendrite_config_dir_path }}/dendrite.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-dendrite.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/dendrite/systemd/matrix-dendrite.service.j2" dest: "{{ matrix_systemd_path }}/matrix-dendrite.service" mode: 0644 register: matrix_dendrite_systemd_service_result - name: Ensure systemd reloaded after matrix-dendrite.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_dendrite_systemd_service_result.changed|bool" + when: "matrix_dendrite_systemd_service_result.changed | bool" - name: Ensure matrix-dendrite-create-account script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/dendrite/usr-local-bin/matrix-dendrite-create-account.j2" dest: "{{ matrix_local_bin_path }}/matrix-dendrite-create-account" mode: 0750 diff --git a/roles/matrix-dendrite/tasks/dendrite/setup_uninstall.yml b/roles/matrix-dendrite/tasks/dendrite/setup_uninstall.yml index 89d5481c4..b6d8cfaca 100644 --- a/roles/matrix-dendrite/tasks/dendrite/setup_uninstall.yml +++ b/roles/matrix-dendrite/tasks/dendrite/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-dendrite service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-dendrite.service" register: matrix_dendrite_service_stat - name: Ensure matrix-dendrite is stopped - service: + ansible.builtin.service: name: matrix-dendrite state: stopped daemon_reload: true @@ -14,13 +14,13 @@ when: "matrix_dendrite_service_stat.stat.exists" - name: Ensure matrix-dendrite.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-dendrite.service" state: absent when: "matrix_dendrite_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-dendrite.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_dendrite_service_stat.stat.exists" diff --git a/roles/matrix-dendrite/tasks/init.yml b/roles/matrix-dendrite/tasks/init.yml index 524ef6eec..4ce641e9d 100644 --- a/roles/matrix-dendrite/tasks/init.yml +++ b/roles/matrix-dendrite/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-dendrite.service'] }}" - when: matrix_dendrite_enabled|bool + when: matrix_dendrite_enabled | bool diff --git a/roles/matrix-dendrite/tasks/main.yml b/roles/matrix-dendrite/tasks/main.yml index 5483adec1..d14beb154 100644 --- a/roles/matrix-dendrite/tasks/main.yml +++ b/roles/matrix-dendrite/tasks/main.yml @@ -1,42 +1,42 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool tags: - setup-all - setup-dendrite -- import_tasks: "{{ role_path }}/tasks/setup_dendrite.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_dendrite.yml" + when: run_setup | bool tags: - setup-all - setup-dendrite -- import_tasks: "{{ role_path }}/tasks/register_user.yml" - when: run_dendrite_register_user|bool and matrix_dendrite_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/register_user.yml" + when: run_dendrite_register_user | bool and matrix_dendrite_enabled | bool tags: - register-user -- import_tasks: "{{ role_path }}/tasks/self_check_client_api.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_client_api.yml" delegate_to: 127.0.0.1 become: false - when: run_self_check|bool and matrix_dendrite_enabled|bool + when: run_self_check | bool and matrix_dendrite_enabled | bool tags: - self-check -- import_tasks: "{{ role_path }}/tasks/self_check_federation_api.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_federation_api.yml" delegate_to: 127.0.0.1 become: false - when: run_self_check|bool and matrix_dendrite_enabled|bool + when: run_self_check | bool and matrix_dendrite_enabled | bool tags: - self-check - name: Mark matrix-dendrite role as executed - set_fact: + ansible.builtin.set_fact: matrix_dendrite_role_executed: true tags: - always diff --git a/roles/matrix-dendrite/tasks/register_user.yml b/roles/matrix-dendrite/tasks/register_user.yml index b8e3ae5eb..e1b974825 100644 --- a/roles/matrix-dendrite/tasks/register_user.yml +++ b/roles/matrix-dendrite/tasks/register_user.yml @@ -1,25 +1,28 @@ --- - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `username` variable needs to be provided to this playbook, via --extra-vars" when: "username is not defined or username == ''" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `password` variable needs to be provided to this playbook, via --extra-vars" when: "password is not defined or password == ''" - name: Ensure matrix-dendrite is started - service: + ansible.builtin.service: name: matrix-dendrite state: started daemon_reload: true register: start_result - name: Wait a while, so that Dendrite can manage to start - pause: + ansible.builtin.pause: seconds: 7 - when: "start_result.changed" + when: start_result.changed | bool - name: Register user - command: "{{ matrix_local_bin_path }}/matrix-dendrite-create-account {{ username|quote }} {{ password|quote }}" + ansible.builtin.command: + cmd: "{{ matrix_local_bin_path }}/matrix-dendrite-create-account {{ username | quote }} {{ password | quote }}" + register: matrix_dendrite_register_user_result + changed_when: matrix_dendrite_register_user_result.rc == 0 diff --git a/roles/matrix-dendrite/tasks/self_check_client_api.yml b/roles/matrix-dendrite/tasks/self_check_client_api.yml index 2470d8186..99b6cb40d 100644 --- a/roles/matrix-dendrite/tasks/self_check_client_api.yml +++ b/roles/matrix-dendrite/tasks/self_check_client_api.yml @@ -1,6 +1,6 @@ --- - name: Check Matrix Client API - uri: + ansible.builtin.uri: url: "{{ matrix_dendrite_client_api_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_dendrite_self_check_validate_certificates }}" @@ -9,10 +9,10 @@ check_mode: false - name: Fail if Matrix Client API not working - fail: + ansible.builtin.fail: msg: "Failed checking Matrix Client API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_dendrite_client_api_url_endpoint_public }}`). Is Dendrite running? Is port 443 open in your firewall? Full error: {{ result_matrix_dendrite_client_api }}" when: "(result_matrix_dendrite_client_api.failed or 'json' not in result_matrix_dendrite_client_api)" - name: Report working Matrix Client API - debug: + ansible.builtin.debug: msg: "The Matrix Client API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_dendrite_client_api_url_endpoint_public }}`) is working" diff --git a/roles/matrix-dendrite/tasks/self_check_federation_api.yml b/roles/matrix-dendrite/tasks/self_check_federation_api.yml index 0afca2cb9..25b2871ce 100644 --- a/roles/matrix-dendrite/tasks/self_check_federation_api.yml +++ b/roles/matrix-dendrite/tasks/self_check_federation_api.yml @@ -1,6 +1,6 @@ --- - name: Check Matrix Federation API - uri: + ansible.builtin.uri: url: "{{ matrix_dendrite_federation_api_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_dendrite_self_check_validate_certificates }}" @@ -9,16 +9,16 @@ check_mode: false - name: Fail if Matrix Federation API not working - fail: + ansible.builtin.fail: msg: "Failed checking Matrix Federation API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_dendrite_federation_api_url_endpoint_public }}`). Is Dendrite running? Is port {{ matrix_federation_public_port }} open in your firewall? Full error: {{ result_matrix_dendrite_federation_api }}" - when: "matrix_dendrite_federation_enabled|bool and (result_matrix_dendrite_federation_api.failed or 'json' not in result_matrix_dendrite_federation_api)" + when: "matrix_dendrite_federation_enabled | bool and (result_matrix_dendrite_federation_api.failed or 'json' not in result_matrix_dendrite_federation_api)" - name: Fail if Matrix Federation API unexpectedly enabled - fail: + ansible.builtin.fail: msg: "Matrix Federation API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_dendrite_federation_api_url_endpoint_public }}`) despite being disabled." - when: "not matrix_dendrite_federation_enabled|bool and not result_matrix_dendrite_federation_api.failed" + when: "not matrix_dendrite_federation_enabled | bool and not result_matrix_dendrite_federation_api.failed" - name: Report working Matrix Federation API - debug: + ansible.builtin.debug: msg: "The Matrix Federation API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_dendrite_federation_api_url_endpoint_public }}`) is working" - when: "matrix_dendrite_federation_enabled|bool" + when: "matrix_dendrite_federation_enabled | bool" diff --git a/roles/matrix-dendrite/tasks/setup_dendrite.yml b/roles/matrix-dendrite/tasks/setup_dendrite.yml index fc306759d..f74f08c2d 100644 --- a/roles/matrix-dendrite/tasks/setup_dendrite.yml +++ b/roles/matrix-dendrite/tasks/setup_dendrite.yml @@ -1,6 +1,6 @@ --- - name: Ensure Dendrite paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -10,6 +10,6 @@ - {path: "{{ matrix_dendrite_config_dir_path }}", when: true} - {path: "{{ matrix_dendrite_ext_path }}", when: true} - {path: "{{ matrix_dendrite_nats_storage_path }}", when: true} - when: "matrix_dendrite_enabled|bool and item.when" + when: "matrix_dendrite_enabled | bool and item.when" -- import_tasks: "{{ role_path }}/tasks/dendrite/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/dendrite/setup.yml" diff --git a/roles/matrix-dendrite/tasks/validate_config.yml b/roles/matrix-dendrite/tasks/validate_config.yml index 2d2cf4c5b..390da9380 100644 --- a/roles/matrix-dendrite/tasks/validate_config.yml +++ b/roles/matrix-dendrite/tasks/validate_config.yml @@ -1,6 +1,6 @@ --- - name: Fail if required Dendrite settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) for using Dendrite. when: "vars[item] == ''" @@ -8,7 +8,7 @@ - "matrix_dendrite_registration_shared_secret" - name: (Deprecation) Catch and report renamed settings - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-dendrite/templates/dendrite/dendrite.yaml.j2 b/roles/matrix-dendrite/templates/dendrite/dendrite.yaml.j2 index fcede4055..29f5c55f0 100644 --- a/roles/matrix-dendrite/templates/dendrite/dendrite.yaml.j2 +++ b/roles/matrix-dendrite/templates/dendrite/dendrite.yaml.j2 @@ -165,7 +165,7 @@ client_api: # If set, allows registration by anyone who knows the shared secret, regardless of # whether registration is otherwise disabled. - registration_shared_secret: {{ matrix_dendrite_registration_shared_secret|string|to_json }} + registration_shared_secret: {{ matrix_dendrite_registration_shared_secret | string|to_json }} # Whether to require reCAPTCHA for registration. enable_registration_captcha: {{ matrix_dendrite_enable_registration_captcha|to_json }} diff --git a/roles/matrix-dendrite/vars/main.yml b/roles/matrix-dendrite/vars/main.yml index 60d5f4eb5..fcf020c2c 100644 --- a/roles/matrix-dendrite/vars/main.yml +++ b/roles/matrix-dendrite/vars/main.yml @@ -5,7 +5,7 @@ matrix_dendrite_federation_api_url_endpoint_public: "https://{{ matrix_server_fq # Tells whether this role had executed or not. Toggled to `true` during runtime. matrix_dendrite_role_executed: false -matrix_dendrite_media_store_parent_path: "{{ matrix_dendrite_media_store_path|dirname }}" -matrix_dendrite_media_store_directory_name: "{{ matrix_dendrite_media_store_path|basename }}" +matrix_dendrite_media_store_parent_path: "{{ matrix_dendrite_media_store_path | dirname }}" +matrix_dendrite_media_store_directory_name: "{{ matrix_dendrite_media_store_path | basename }}" -matrix_dendrite_signing_key_file_name: "{{ matrix_dendrite_signing_key|basename }}" +matrix_dendrite_signing_key_file_name: "{{ matrix_dendrite_signing_key | basename }}" diff --git a/roles/matrix-dimension/defaults/main.yml b/roles/matrix-dimension/defaults/main.yml index 68bd79089..ea1dde108 100644 --- a/roles/matrix-dimension/defaults/main.yml +++ b/roles/matrix-dimension/defaults/main.yml @@ -48,7 +48,7 @@ matrix_dimension_integrations_rest_url: "https://{{ matrix_server_fqn_dimension matrix_dimension_integrations_widgets_urls: ["https://{{ matrix_server_fqn_dimension }}/widgets"] matrix_dimension_integrations_jitsi_widget_url: "https://{{ matrix_server_fqn_dimension }}/widgets/jitsi" -matrix_dimension_homeserver_federationUrl: "" +matrix_dimension_homeserver_federationUrl: "" # noqa var-naming # Database-related configuration fields. @@ -93,8 +93,8 @@ matrix_dimension_configuration_extension_yaml: | # botToken: "YourTokenHere" # -matrix_dimension_configuration_extension: "{{ matrix_dimension_configuration_extension_yaml|from_yaml if matrix_dimension_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_dimension_configuration_extension: "{{ matrix_dimension_configuration_extension_yaml | from_yaml if matrix_dimension_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final Dimension configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_dimension_configuration_yaml`. -matrix_dimension_configuration: "{{ matrix_dimension_configuration_yaml|from_yaml|combine(matrix_dimension_configuration_extension, recursive=True) }}" +matrix_dimension_configuration: "{{ matrix_dimension_configuration_yaml | from_yaml | combine(matrix_dimension_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-dimension/tasks/init.yml b/roles/matrix-dimension/tasks/init.yml index 6336cb4d3..c60a2fe2e 100644 --- a/roles/matrix-dimension/tasks/init.yml +++ b/roles/matrix-dimension/tasks/init.yml @@ -1,4 +1,4 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-dimension.service'] }}" - when: matrix_dimension_enabled|bool + when: matrix_dimension_enabled | bool diff --git a/roles/matrix-dimension/tasks/main.yml b/roles/matrix-dimension/tasks/main.yml index c2f013993..6eef50d65 100644 --- a/roles/matrix-dimension/tasks/main.yml +++ b/roles/matrix-dimension/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool tags: - setup-all - setup-dimension -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: run_setup|bool and matrix_dimension_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: run_setup | bool and matrix_dimension_enabled | bool tags: - setup-all - setup-dimension -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: run_setup|bool and not matrix_dimension_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: run_setup | bool and not matrix_dimension_enabled | bool tags: - setup-all - setup-dimension diff --git a/roles/matrix-dimension/tasks/setup_install.yml b/roles/matrix-dimension/tasks/setup_install.yml index b999383e1..7060285a6 100644 --- a/roles/matrix-dimension/tasks/setup_install.yml +++ b/roles/matrix-dimension/tasks/setup_install.yml @@ -1,21 +1,21 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_dimension_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_dimension_sqlite_database_path_local }}" register: matrix_dimension_sqlite_database_path_local_stat_result - block: # pgloader makes a few columns `smallint`, instead of `boolean`. # We need to fix them up. - - set_fact: + - ansible.builtin.set_fact: matrix_dimension_pgloader_additional_psql_statements_list: [] - - set_fact: + - ansible.builtin.set_fact: matrix_dimension_pgloader_additional_psql_statements_list: | {{ matrix_dimension_pgloader_additional_psql_statements_list @@ -49,11 +49,11 @@ - {'table': 'dimension_bridges', 'column': 'isEnabled', 'default': ''} - {'table': 'dimension_bridges', 'column': 'isPublic', 'default': ''} - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_dimension_sqlite_database_path_local }}" dst: "{{ matrix_dimension_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_dimension_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-dimension.service'] @@ -61,15 +61,17 @@ additional_psql_statements_list: "{{ matrix_dimension_pgloader_additional_psql_statements_list }}" additional_psql_statements_db_name: "{{ matrix_dimension_database_name }}" - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_dimension_requires_restart: true - when: "matrix_dimension_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_dimension_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_dimension_database_engine == 'postgres'" - name: Ensure Dimension base path exists - file: + ansible.builtin.file: path: "{{ matrix_dimension_base_path }}" state: directory mode: 0770 @@ -77,8 +79,8 @@ group: "{{ matrix_dimension_user_gid }}" - name: Ensure Dimension config installed - copy: - content: "{{ matrix_dimension_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_dimension_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_dimension_base_path }}/config.yaml" mode: 0640 owner: "{{ matrix_user_username }}" @@ -90,21 +92,21 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_dimension_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_dimension_docker_image_force_pull }}" - when: "not matrix_dimension_container_image_self_build|bool" + when: "not matrix_dimension_container_image_self_build | bool" register: matrix_dimension_pull_results retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: matrix_dimension_pull_results is not failed - name: Ensure dimension repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_dimension_container_image_self_build_repo }}" dest: "{{ matrix_dimension_docker_src_files_path }}" version: "{{ matrix_dimension_container_image_self_build_branch }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" - when: "matrix_dimension_container_image_self_build|bool" + when: "matrix_dimension_container_image_self_build | bool" register: matrix_dimension_git_pull_results - name: Ensure Dimension Docker image is built @@ -117,22 +119,22 @@ dockerfile: Dockerfile path: "{{ matrix_dimension_docker_src_files_path }}" pull: true - when: "matrix_dimension_container_image_self_build|bool" + when: "matrix_dimension_container_image_self_build | bool" - name: Ensure matrix-dimension.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-dimension.service.j2" dest: "{{ matrix_systemd_path }}/matrix-dimension.service" mode: 0644 register: matrix_dimension_systemd_service_result - name: Ensure systemd reloaded after matrix-dimension.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_dimension_systemd_service_result.changed|bool" + when: "matrix_dimension_systemd_service_result.changed | bool" - name: Ensure matrix-dimension.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-dimension.service" state: restarted - when: "matrix_dimension_requires_restart|bool" + when: "matrix_dimension_requires_restart | bool" diff --git a/roles/matrix-dimension/tasks/setup_uninstall.yml b/roles/matrix-dimension/tasks/setup_uninstall.yml index cdfbe07af..3e2026a11 100644 --- a/roles/matrix-dimension/tasks/setup_uninstall.yml +++ b/roles/matrix-dimension/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-dimension service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-dimension.service" register: matrix_dimension_service_stat - name: Ensure matrix-dimension is stopped - service: + ansible.builtin.service: name: matrix-dimension state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_dimension_service_stat.stat.exists|bool" + when: "matrix_dimension_service_stat.stat.exists | bool" - name: Ensure matrix-dimension.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-dimension.service" state: absent - when: "matrix_dimension_service_stat.stat.exists|bool" + when: "matrix_dimension_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-dimension.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_dimension_service_stat.stat.exists|bool" + when: "matrix_dimension_service_stat.stat.exists | bool" - name: Ensure Dimension base directory doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_dimension_base_path }}" state: absent diff --git a/roles/matrix-dimension/tasks/validate_config.yml b/roles/matrix-dimension/tasks/validate_config.yml index 8413c42f5..5af0ba6d6 100644 --- a/roles/matrix-dimension/tasks/validate_config.yml +++ b/roles/matrix-dimension/tasks/validate_config.yml @@ -1,6 +1,6 @@ --- - name: Fail if required Dimension settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) for using Dimension. with_items: @@ -8,7 +8,7 @@ when: "matrix_dimension_enabled and vars[item] == ''" - name: (Deprecation) Catch and report renamed Dimension variables - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-dimension/vars/main.yml b/roles/matrix-dimension/vars/main.yml index 131024cc2..0415989fa 100644 --- a/roles/matrix-dimension/vars/main.yml +++ b/roles/matrix-dimension/vars/main.yml @@ -2,4 +2,4 @@ # Doing `|from_yaml` when the extension contains nothing yields an empty string (""). # We need to ensure it's a dictionary or `|combine` (when building `matrix_dimension_configuration`) will fail later. -matrix_dimension_configuration_extension: "{{ matrix_dimension_configuration_extension_yaml|from_yaml if matrix_dimension_configuration_extension_yaml|from_yaml else {} }}" +matrix_dimension_configuration_extension: "{{ matrix_dimension_configuration_extension_yaml | from_yaml if matrix_dimension_configuration_extension_yaml | from_yaml else {} }}" diff --git a/roles/matrix-dynamic-dns/defaults/main.yml b/roles/matrix-dynamic-dns/defaults/main.yml index 1da87f38d..bdeea0f10 100644 --- a/roles/matrix-dynamic-dns/defaults/main.yml +++ b/roles/matrix-dynamic-dns/defaults/main.yml @@ -29,6 +29,7 @@ matrix_dynamic_dns_systemd_required_services_list: ['docker.service'] # Build the container from source when running in mode matrix_dynamic_dns_container_image_self_build: false matrix_dynamic_dns_container_image_self_build_repo: "https://github.com/linuxserver/docker-ddclient.git" +matrix_dynamic_dns_container_image_self_build_repo_branch: "{{ matrix_dynamic_dns_version }}" # Config paths matrix_dynamic_dns_base_path: "{{ matrix_base_data_path }}/dynamic-dns" diff --git a/roles/matrix-dynamic-dns/tasks/init.yml b/roles/matrix-dynamic-dns/tasks/init.yml index 6ea6a60bb..1cd6170e3 100644 --- a/roles/matrix-dynamic-dns/tasks/init.yml +++ b/roles/matrix-dynamic-dns/tasks/init.yml @@ -2,10 +2,10 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_dynamic_dns_container_image_self_build and matrix_dynamic_dns_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-dynamic-dns.service'] }}" - when: "matrix_dynamic_dns_enabled|bool" + when: "matrix_dynamic_dns_enabled | bool" diff --git a/roles/matrix-dynamic-dns/tasks/install.yml b/roles/matrix-dynamic-dns/tasks/install.yml index 60f079374..e83637bfc 100644 --- a/roles/matrix-dynamic-dns/tasks/install.yml +++ b/roles/matrix-dynamic-dns/tasks/install.yml @@ -6,14 +6,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_dynamic_dns_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_dynamic_dns_docker_image_force_pull }}" - when: matrix_dynamic_dns_enabled|bool and not matrix_dynamic_dns_container_image_self_build + when: matrix_dynamic_dns_enabled | bool and not matrix_dynamic_dns_container_image_self_build register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Dynamic DNS paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0751 @@ -23,17 +23,18 @@ - {path: "{{ matrix_dynamic_dns_base_path }}", when: true} - {path: "{{ matrix_dynamic_dns_config_path }}", when: true} - {path: "{{ matrix_dynamic_dns_docker_src_files_path }}", when: "{{ matrix_dynamic_dns_container_image_self_build }}"} - when: matrix_dynamic_dns_enabled|bool and item.when|bool + when: matrix_dynamic_dns_enabled | bool and item.when | bool - name: Ensure Dynamic DNS repository is present on self build - git: + ansible.builtin.git: repo: "{{ matrix_dynamic_dns_container_image_self_build_repo }}" + version: "{{ matrix_dynamic_dns_container_image_self_build_repo_branch }}" dest: "{{ matrix_dynamic_dns_docker_src_files_path }}" force: "yes" become: true become_user: "{{ matrix_user_username }}" register: matrix_dynamic_dns_git_pull_results - when: "matrix_dynamic_dns_enabled|bool and matrix_dynamic_dns_container_image_self_build|bool" + when: "matrix_dynamic_dns_enabled | bool and matrix_dynamic_dns_container_image_self_build | bool" - name: Ensure Dynamic DNS Docker image is built docker_image: @@ -45,10 +46,10 @@ dockerfile: Dockerfile path: "{{ matrix_dynamic_dns_docker_src_files_path }}" pull: true - when: "matrix_dynamic_dns_enabled|bool and matrix_dynamic_dns_container_image_self_build|bool" + when: "matrix_dynamic_dns_enabled | bool and matrix_dynamic_dns_container_image_self_build | bool" - name: Ensure Dynamic DNS ddclient.conf installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/ddclient.conf.j2" dest: "{{ matrix_dynamic_dns_config_path }}/ddclient.conf" mode: 0644 @@ -56,13 +57,13 @@ group: "{{ matrix_user_groupname }}" - name: Ensure matrix-dynamic-dns.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-dynamic-dns.service.j2" dest: "/etc/systemd/system/matrix-dynamic-dns.service" mode: 0644 register: matrix_dynamic_dns_systemd_service_result - name: Ensure systemd reloaded after matrix-dynamic-dns.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_dynamic_dns_systemd_service_result.changed" diff --git a/roles/matrix-dynamic-dns/tasks/main.yml b/roles/matrix-dynamic-dns/tasks/main.yml index 8b8b306c3..2f33af86e 100644 --- a/roles/matrix-dynamic-dns/tasks/main.yml +++ b/roles/matrix-dynamic-dns/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_dynamic_dns_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_dynamic_dns_enabled | bool" tags: - setup-all - setup-dynamic-dns -- import_tasks: "{{ role_path }}/tasks/install.yml" - when: "run_setup|bool and matrix_dynamic_dns_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/install.yml" + when: "run_setup | bool and matrix_dynamic_dns_enabled | bool" tags: - setup-all - setup-dynamic-dns -- import_tasks: "{{ role_path }}/tasks/uninstall.yml" - when: "run_setup|bool and not matrix_dynamic_dns_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/uninstall.yml" + when: "run_setup | bool and not matrix_dynamic_dns_enabled | bool" tags: - setup-all - setup-dynamic-dns diff --git a/roles/matrix-dynamic-dns/tasks/uninstall.yml b/roles/matrix-dynamic-dns/tasks/uninstall.yml index 80842c9c4..5e6b429cf 100644 --- a/roles/matrix-dynamic-dns/tasks/uninstall.yml +++ b/roles/matrix-dynamic-dns/tasks/uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-dynamic-dns service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-dynamic-dns.service" register: matrix_dynamic_dns_service_stat - name: Ensure matrix-dynamic-dns is stopped - service: + ansible.builtin.service: name: matrix-dynamic-dns state: stopped enabled: false @@ -14,13 +14,13 @@ when: "matrix_dynamic_dns_service_stat.stat.exists" - name: Ensure matrix-dynamic-dns.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-dynamic-dns.service" state: absent when: "matrix_dynamic_dns_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-dynamic-dns.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_dynamic_dns_service_stat.stat.exists" diff --git a/roles/matrix-dynamic-dns/tasks/validate_config.yml b/roles/matrix-dynamic-dns/tasks/validate_config.yml index 8f0001eaa..610dc2f8c 100644 --- a/roles/matrix-dynamic-dns/tasks/validate_config.yml +++ b/roles/matrix-dynamic-dns/tasks/validate_config.yml @@ -1,13 +1,13 @@ --- - name: Fail if no configurations specified - fail: + ansible.builtin.fail: msg: >- You need to define at least one configuration in `matrix_dynamic_dns_domain_configurations` for using matrix-dynamic-dns. when: "matrix_dynamic_dns_domain_configurations|length == 0" - name: Fail if required settings not defined in configuration blocks - fail: + ansible.builtin.fail: msg: >- One of the configurations in matrix_dynamic_dns_domain_configurations is missing a required key (domain, provider, protocol). when: "'domain' not in configuration or 'provider' not in configuration or 'protocol' not in configuration" diff --git a/roles/matrix-email2matrix/tasks/init.yml b/roles/matrix-email2matrix/tasks/init.yml index 5f582212a..02dbc9ee3 100644 --- a/roles/matrix-email2matrix/tasks/init.yml +++ b/roles/matrix-email2matrix/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-email2matrix.service'] }}" - when: matrix_email2matrix_enabled|bool + when: matrix_email2matrix_enabled | bool diff --git a/roles/matrix-email2matrix/tasks/main.yml b/roles/matrix-email2matrix/tasks/main.yml index 35bda4fa8..3adbc6466 100644 --- a/roles/matrix-email2matrix/tasks/main.yml +++ b/roles/matrix-email2matrix/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_email2matrix_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_email2matrix_enabled | bool" tags: - setup-all - setup-email2matrix -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_email2matrix_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_email2matrix_enabled | bool" tags: - setup-all - setup-email2matrix -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_email2matrix_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_email2matrix_enabled | bool" tags: - setup-all - setup-email2matrix diff --git a/roles/matrix-email2matrix/tasks/setup_install.yml b/roles/matrix-email2matrix/tasks/setup_install.yml index a2470728e..2a782a1a8 100644 --- a/roles/matrix-email2matrix/tasks/setup_install.yml +++ b/roles/matrix-email2matrix/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure Email2Matrix paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -11,10 +11,10 @@ - {path: "{{ matrix_email2matrix_base_path }}", when: true} - {path: "{{ matrix_email2matrix_config_dir_path }}", when: true} - {path: "{{ matrix_email2matrix_docker_src_files_path }}", when: "{{ matrix_email2matrix_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure Email2Matrix configuration file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/config.json.j2" dest: "{{ matrix_email2matrix_config_dir_path }}/config.json" owner: "{{ matrix_user_username }}" @@ -27,14 +27,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_email2matrix_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_email2matrix_docker_image_force_pull }}" - when: "not matrix_email2matrix_container_image_self_build|bool" + when: "not matrix_email2matrix_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Email2Matrix repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_email2matrix_container_image_self_build_repo }}" dest: "{{ matrix_email2matrix_docker_src_files_path }}" version: "{{ matrix_email2matrix_container_image_self_build_branch }}" @@ -42,7 +42,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_email2matrix_git_pull_results - when: "matrix_email2matrix_container_image_self_build|bool" + when: "matrix_email2matrix_container_image_self_build | bool" - name: Ensure Email2Matrix Docker image is built docker_image: @@ -54,16 +54,16 @@ dockerfile: etc/docker/Dockerfile path: "{{ matrix_email2matrix_docker_src_files_path }}" pull: true - when: "matrix_email2matrix_container_image_self_build|bool" + when: "matrix_email2matrix_container_image_self_build | bool" - name: Ensure matrix-email2matrix.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-email2matrix.service.j2" dest: "{{ matrix_systemd_path }}/matrix-email2matrix.service" mode: 0644 register: matrix_email2matrix_systemd_service_result - name: Ensure systemd reloaded after matrix-email2matrix.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_email2matrix_systemd_service_result.changed|bool" + when: "matrix_email2matrix_systemd_service_result.changed | bool" diff --git a/roles/matrix-email2matrix/tasks/setup_uninstall.yml b/roles/matrix-email2matrix/tasks/setup_uninstall.yml index 27d35f2d6..a713a65ad 100644 --- a/roles/matrix-email2matrix/tasks/setup_uninstall.yml +++ b/roles/matrix-email2matrix/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-email2matrix service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-email2matrix.service" register: matrix_email2matrix_service_stat - name: Ensure matrix-email2matrix is stopped - service: + ansible.builtin.service: name: matrix-email2matrix state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_email2matrix_service_stat.stat.exists|bool" + when: "matrix_email2matrix_service_stat.stat.exists | bool" - name: Ensure matrix-email2matrix.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-email2matrix.service" state: absent - when: "matrix_email2matrix_service_stat.stat.exists|bool" + when: "matrix_email2matrix_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-email2matrix.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_email2matrix_service_stat.stat.exists|bool" + when: "matrix_email2matrix_service_stat.stat.exists | bool" - name: Ensure Email2Matrix data path doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_email2matrix_base_path }}" state: absent diff --git a/roles/matrix-email2matrix/tasks/validate_config.yml b/roles/matrix-email2matrix/tasks/validate_config.yml index d8beecf4a..59a3581e4 100644 --- a/roles/matrix-email2matrix/tasks/validate_config.yml +++ b/roles/matrix-email2matrix/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if no mappings - fail: + ansible.builtin.fail: msg: > You need to define at least one mapping in `matrix_email2matrix_matrix_mappings` for enabling Email2Matrix. when: "matrix_email2matrix_matrix_mappings|length == 0" diff --git a/roles/matrix-email2matrix/templates/config.json.j2 b/roles/matrix-email2matrix/templates/config.json.j2 index c1be97fdb..a7ca7bc47 100644 --- a/roles/matrix-email2matrix/templates/config.json.j2 +++ b/roles/matrix-email2matrix/templates/config.json.j2 @@ -6,7 +6,7 @@ "Workers": 10 }, "Matrix": { - "Mappings": {{ matrix_email2matrix_matrix_mappings|to_nice_json }} + "Mappings": {{ matrix_email2matrix_matrix_mappings | to_nice_json }} }, "Misc": { "Debug": {{ matrix_email2matrix_misc_debug|to_json }} diff --git a/roles/matrix-etherpad/defaults/main.yml b/roles/matrix-etherpad/defaults/main.yml index 656e43f9d..8281f27ff 100644 --- a/roles/matrix-etherpad/defaults/main.yml +++ b/roles/matrix-etherpad/defaults/main.yml @@ -88,8 +88,8 @@ matrix_etherpad_configuration_default: "{{ lookup('template', 'templates/setting # matrix_etherpad_configuration_extension_json: '{}' -matrix_etherpad_configuration_extension: "{{ matrix_etherpad_configuration_extension_json|from_json if matrix_etherpad_configuration_extension_json|from_json is mapping else {} }}" +matrix_etherpad_configuration_extension: "{{ matrix_etherpad_configuration_extension_json | from_json if matrix_etherpad_configuration_extension_json | from_json is mapping else {} }}" # Holds the final Etherpad configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_etherpad_configuration_json`. -matrix_etherpad_configuration: "{{ matrix_etherpad_configuration_default|combine(matrix_etherpad_configuration_extension, recursive=True) }}" +matrix_etherpad_configuration: "{{ matrix_etherpad_configuration_default | combine(matrix_etherpad_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-etherpad/tasks/init.yml b/roles/matrix-etherpad/tasks/init.yml index 392addd04..e16b78dd6 100644 --- a/roles/matrix-etherpad/tasks/init.yml +++ b/roles/matrix-etherpad/tasks/init.yml @@ -1,26 +1,26 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-etherpad.service'] }}" - when: matrix_etherpad_enabled|bool + when: matrix_etherpad_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Etherpad'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-etherpad role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Etherpad proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_etherpad_matrix_nginx_proxy_configuration: | rewrite ^{{ matrix_etherpad_public_endpoint }}$ {{ matrix_nginx_proxy_x_forwarded_proto_value }}://$server_name{{ matrix_etherpad_public_endpoint }}/ permanent; location {{ matrix_etherpad_public_endpoint }}/ { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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; proxy_pass http://matrix-etherpad:9001/; @@ -42,23 +42,23 @@ } - name: Register Etherpad proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_dimension_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_dimension_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_dimension_additional_server_configuration_blocks | default([]) + [matrix_etherpad_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_etherpad_enabled|bool + when: matrix_etherpad_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Etherpad tool but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_etherpad_public_endpoint }}` URL endpoint to the matrix-etherpad container. You can expose the container's port using the `matrix_etherpad_container_http_host_bind_port` variable. - when: "matrix_etherpad_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_etherpad_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-etherpad/tasks/main.yml b/roles/matrix-etherpad/tasks/main.yml index bf59d838c..b1c8ab557 100644 --- a/roles/matrix-etherpad/tasks/main.yml +++ b/roles/matrix-etherpad/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: run_setup|bool and matrix_etherpad_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: run_setup | bool and matrix_etherpad_enabled | bool tags: - setup-all - setup-etherpad -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: run_setup|bool and not matrix_etherpad_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: run_setup | bool and not matrix_etherpad_enabled | bool tags: - setup-all - setup-etherpad -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool and matrix_etherpad_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool and matrix_etherpad_enabled | bool tags: - setup-all - setup-etherpad diff --git a/roles/matrix-etherpad/tasks/setup_install.yml b/roles/matrix-etherpad/tasks/setup_install.yml index 6f276e05c..0243e9d7e 100644 --- a/roles/matrix-etherpad/tasks/setup_install.yml +++ b/roles/matrix-etherpad/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure Etherpad base path exists - file: + ansible.builtin.file: path: "{{ matrix_etherpad_base_path }}" state: directory mode: 0770 @@ -9,8 +9,8 @@ group: "{{ matrix_etherpad_user_gid }}" - name: Ensure Etherpad config installed - copy: - content: "{{ matrix_etherpad_configuration|to_nice_json }}" + ansible.builtin.copy: + content: "{{ matrix_etherpad_configuration | to_nice_json }}" dest: "{{ matrix_etherpad_base_path }}/settings.json" mode: 0640 owner: "{{ matrix_etherpad_user_uid }}" @@ -28,13 +28,13 @@ until: result is not failed - name: Ensure matrix-etherpad.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-etherpad.service.j2" dest: "{{ matrix_systemd_path }}/matrix-etherpad.service" mode: 0644 register: matrix_etherpad_systemd_service_result - name: Ensure systemd reloaded after matrix-etherpad.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_etherpad_systemd_service_result.changed|bool" + when: "matrix_etherpad_systemd_service_result.changed | bool" diff --git a/roles/matrix-etherpad/tasks/setup_uninstall.yml b/roles/matrix-etherpad/tasks/setup_uninstall.yml index ae1f2604e..38697366c 100644 --- a/roles/matrix-etherpad/tasks/setup_uninstall.yml +++ b/roles/matrix-etherpad/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-etherpad service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-etherpad.service" register: matrix_etherpad_service_stat - name: Ensure matrix-etherpad is stopped - service: + ansible.builtin.service: name: matrix-etherpad state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_etherpad_service_stat.stat.exists|bool" + when: "matrix_etherpad_service_stat.stat.exists | bool" - name: Ensure matrix-etherpad.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-etherpad.service" state: absent - when: "matrix_etherpad_service_stat.stat.exists|bool" + when: "matrix_etherpad_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-etherpad.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_etherpad_service_stat.stat.exists|bool" + when: "matrix_etherpad_service_stat.stat.exists | bool" - name: Ensure Etherpad base directory doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_etherpad_base_path }}" state: absent diff --git a/roles/matrix-etherpad/tasks/validate_config.yml b/roles/matrix-etherpad/tasks/validate_config.yml index f9438e7bf..bf78c36fc 100644 --- a/roles/matrix-etherpad/tasks/validate_config.yml +++ b/roles/matrix-etherpad/tasks/validate_config.yml @@ -1,13 +1,13 @@ --- - name: Fail if Etherpad is enabled without the Dimension integrations manager - fail: + ansible.builtin.fail: msg: >- To integrate Etherpad notes with Matrix rooms you need to set "matrix_dimension_enabled" to true - when: "not matrix_dimension_enabled|bool" + when: "not matrix_dimension_enabled | bool" - name: Fail if no database is configured for Etherpad - fail: + ansible.builtin.fail: msg: >- Etherpad requires a dedicated Postgres database. Please enable the built in one, or configure an external DB by redefining "matrix_etherpad_database_hostname" when: matrix_etherpad_database_hostname == "matrix-postgres" and not matrix_postgres_enabled diff --git a/roles/matrix-grafana/tasks/init.yml b/roles/matrix-grafana/tasks/init.yml index 4c2cbf068..7b363ee77 100644 --- a/roles/matrix-grafana/tasks/init.yml +++ b/roles/matrix-grafana/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-grafana.service'] }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool diff --git a/roles/matrix-grafana/tasks/main.yml b/roles/matrix-grafana/tasks/main.yml index c93fd5002..34a3f415b 100644 --- a/roles/matrix-grafana/tasks/main.yml +++ b/roles/matrix-grafana/tasks/main.yml @@ -1,16 +1,16 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_grafana_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_grafana_enabled | bool" tags: - setup-all - setup-grafana -- import_tasks: "{{ role_path }}/tasks/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup.yml" tags: - setup-all - setup-grafana diff --git a/roles/matrix-grafana/tasks/setup.yml b/roles/matrix-grafana/tasks/setup.yml index 16b9fa659..591c02224 100644 --- a/roles/matrix-grafana/tasks/setup.yml +++ b/roles/matrix-grafana/tasks/setup.yml @@ -10,14 +10,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_grafana_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_grafana_docker_image_force_pull }}" - when: "matrix_grafana_enabled|bool" + when: "matrix_grafana_enabled | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure grafana paths exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -31,37 +31,37 @@ - "{{ matrix_grafana_config_path }}/provisioning/dashboards" - "{{ matrix_grafana_config_path }}/dashboards" - "{{ matrix_grafana_data_path }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool - name: Ensure grafana.ini present - template: + ansible.builtin.template: src: "{{ role_path }}/templates/grafana.ini.j2" dest: "{{ matrix_grafana_config_path }}/grafana.ini" mode: 0440 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool - name: Ensure provisioning/datasources/default.yaml present - template: + ansible.builtin.template: src: "{{ role_path }}/templates/datasources.yaml.j2" dest: "{{ matrix_grafana_config_path }}/provisioning/datasources/default.yaml" mode: 0440 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool - name: Ensure provisioning/dashboards/default.yaml present - template: + ansible.builtin.template: src: "{{ role_path }}/templates/dashboards.yaml.j2" dest: "{{ matrix_grafana_config_path }}/provisioning/dashboards/default.yaml" mode: 0440 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool - name: Ensure dashboard(s) downloaded - get_url: + ansible.builtin.get_url: url: "{{ item }}" dest: "{{ matrix_grafana_config_path }}/dashboards/" force: true @@ -69,50 +69,50 @@ owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" with_items: "{{ matrix_grafana_dashboard_download_urls_all }}" - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool register: result retries: "{{ matrix_geturl_retries_count }}" delay: "{{ matrix_geturl_retries_delay }}" until: result is not failed - name: Ensure matrix-grafana.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-grafana.service.j2" dest: "{{ matrix_systemd_path }}/matrix-grafana.service" mode: 0644 register: matrix_grafana_systemd_service_result - when: matrix_grafana_enabled|bool + when: matrix_grafana_enabled | bool - name: Ensure systemd reloaded after matrix-grafana.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_grafana_enabled|bool and matrix_grafana_systemd_service_result.changed" + when: "matrix_grafana_enabled | bool and matrix_grafana_systemd_service_result.changed" # # Tasks related to getting rid of matrix-grafana (if it was previously enabled) # - name: Check existence of matrix-grafana service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-grafana.service" register: matrix_grafana_service_stat - name: Ensure matrix-grafana is stopped - service: + ansible.builtin.service: name: matrix-grafana state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_grafana_enabled|bool and matrix_grafana_service_stat.stat.exists" + when: "not matrix_grafana_enabled | bool and matrix_grafana_service_stat.stat.exists" - name: Ensure matrix-grafana.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-grafana.service" state: absent - when: "not matrix_grafana_enabled|bool and matrix_grafana_service_stat.stat.exists" + when: "not matrix_grafana_enabled | bool and matrix_grafana_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-grafana.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_grafana_enabled|bool and matrix_grafana_service_stat.stat.exists" + when: "not matrix_grafana_enabled | bool and matrix_grafana_service_stat.stat.exists" diff --git a/roles/matrix-grafana/tasks/validate_config.yml b/roles/matrix-grafana/tasks/validate_config.yml index 63d4919a3..cc48c5596 100644 --- a/roles/matrix-grafana/tasks/validate_config.yml +++ b/roles/matrix-grafana/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if Prometheus not enabled - fail: + ansible.builtin.fail: msg: > You need to enable `matrix_prometheus_enabled` to use Prometheus as data source for Grafana. when: "not matrix_prometheus_enabled" diff --git a/roles/matrix-jitsi/defaults/main.yml b/roles/matrix-jitsi/defaults/main.yml index ef6a5735e..5546d19c7 100644 --- a/roles/matrix-jitsi/defaults/main.yml +++ b/roles/matrix-jitsi/defaults/main.yml @@ -132,7 +132,7 @@ matrix_jitsi_web_config_start_audio_muted_after_nth_participant: ~ # Controls after which participant video will be muted. If not specified, defaults to Jitsi's default value (likely 10) matrix_jitsi_web_config_start_video_muted_after_nth_participant: ~ -matrix_jitsi_web_config_defaultLanguage: 'en' +matrix_jitsi_web_config_defaultLanguage: 'en' # noqa var-naming # Ideal and also maximum resolution width. If not specified, defaults to Jitsi's default value (likely 1280) matrix_jitsi_web_config_resolution_width_ideal_and_max: ~ diff --git a/roles/matrix-jitsi/tasks/init.yml b/roles/matrix-jitsi/tasks/init.yml index 58567d925..8606c4b3e 100644 --- a/roles/matrix-jitsi/tasks/init.yml +++ b/roles/matrix-jitsi/tasks/init.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-jitsi-web.service', 'matrix-jitsi-prosody.service', 'matrix-jitsi-jicofo.service', 'matrix-jitsi-jvb.service'] }}" - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Fail if on an unsupported architecture - fail: + ansible.builtin.fail: msg: "Jitsi only supports the amd64 architecture right now. See https://github.com/jitsi/docker-jitsi-meet/issues/1069 and https://github.com/jitsi/docker-jitsi-meet/issues/1214" - when: matrix_jitsi_enabled|bool and matrix_architecture not in ['amd64', 'arm64'] + when: matrix_jitsi_enabled | bool and matrix_architecture not in ['amd64', 'arm64'] diff --git a/roles/matrix-jitsi/tasks/main.yml b/roles/matrix-jitsi/tasks/main.yml index fe9da205b..7da6ebf95 100644 --- a/roles/matrix-jitsi/tasks/main.yml +++ b/roles/matrix-jitsi/tasks/main.yml @@ -1,41 +1,41 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_jitsi_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_jitsi_enabled | bool" tags: - setup-all - setup-jitsi -- import_tasks: "{{ role_path }}/tasks/setup_jitsi_base.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_jitsi_base.yml" + when: run_setup | bool tags: - setup-all - setup-jitsi -- import_tasks: "{{ role_path }}/tasks/setup_jitsi_web.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_jitsi_web.yml" + when: run_setup | bool tags: - setup-all - setup-jitsi -- import_tasks: "{{ role_path }}/tasks/setup_jitsi_prosody.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_jitsi_prosody.yml" + when: run_setup | bool tags: - setup-all - setup-jitsi -- import_tasks: "{{ role_path }}/tasks/setup_jitsi_jicofo.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_jitsi_jicofo.yml" + when: run_setup | bool tags: - setup-all - setup-jitsi -- import_tasks: "{{ role_path }}/tasks/setup_jitsi_jvb.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_jitsi_jvb.yml" + when: run_setup | bool tags: - setup-all - setup-jitsi diff --git a/roles/matrix-jitsi/tasks/setup_jitsi_base.yml b/roles/matrix-jitsi/tasks/setup_jitsi_base.yml index 4b390c18c..a91949e11 100644 --- a/roles/matrix-jitsi/tasks/setup_jitsi_base.yml +++ b/roles/matrix-jitsi/tasks/setup_jitsi_base.yml @@ -1,13 +1,13 @@ --- -- import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" # # Tasks related to setting up jitsi # - name: Ensure Matrix jitsi base path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -15,7 +15,7 @@ group: "{{ matrix_user_groupname }}" with_items: - {path: "{{ matrix_jitsi_base_path }}", when: true} - when: matrix_jitsi_enabled|bool and item.when + when: matrix_jitsi_enabled | bool and item.when # # Tasks related to getting rid of jitsi (if it was previously enabled) diff --git a/roles/matrix-jitsi/tasks/setup_jitsi_jicofo.yml b/roles/matrix-jitsi/tasks/setup_jitsi_jicofo.yml index 0cb7043fa..8b2ec6a7a 100644 --- a/roles/matrix-jitsi/tasks/setup_jitsi_jicofo.yml +++ b/roles/matrix-jitsi/tasks/setup_jitsi_jicofo.yml @@ -5,7 +5,7 @@ # - name: Ensure Matrix jitsi-jicofo path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0777 @@ -14,7 +14,7 @@ with_items: - {path: "{{ matrix_jitsi_jicofo_base_path }}", when: true} - {path: "{{ matrix_jitsi_jicofo_config_path }}", when: true} - when: matrix_jitsi_enabled|bool and item.when + when: matrix_jitsi_enabled | bool and item.when - name: Ensure jitsi-jicofo Docker image is pulled docker_image: @@ -22,23 +22,23 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_jitsi_jicofo_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_jitsi_jicofo_docker_image_force_pull }}" - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure jitsi-jicofo environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jicofo/env.j2" dest: "{{ matrix_jitsi_jicofo_base_path }}/env" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: 0640 - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure jitsi-jicofo configuration files created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jicofo/{{ item }}.j2" dest: "{{ matrix_jitsi_jicofo_config_path }}/{{ item }}" owner: "{{ matrix_user_username }}" @@ -47,18 +47,18 @@ with_items: - sip-communicator.properties - logging.properties - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure matrix-jitsi-jicofo.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jicofo/matrix-jitsi-jicofo.service.j2" dest: "{{ matrix_systemd_path }}/matrix-jitsi-jicofo.service" mode: 0644 register: matrix_jitsi_jicofo_systemd_service_result - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure systemd reloaded after matrix-jitsi-jicofo.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_jitsi_enabled and matrix_jitsi_jicofo_systemd_service_result.changed" @@ -67,36 +67,36 @@ # - name: Check existence of matrix-jitsi-jicofo service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-jitsi-jicofo.service" register: matrix_jitsi_jicofo_service_stat - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" - name: Ensure matrix-jitsi-jicofo is stopped - service: + ansible.builtin.service: name: matrix-jitsi-jicofo state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jicofo_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jicofo_service_stat.stat.exists" - name: Ensure matrix-jitsi-jicofo.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-jitsi-jicofo.service" state: absent - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jicofo_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jicofo_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-jitsi-jicofo.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jicofo_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jicofo_service_stat.stat.exists" - name: Ensure Matrix jitsi-jicofo paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_jitsi_jicofo_base_path }}" state: absent - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" # Intentionally not removing the Docker image when uninstalling. # We can't be sure it had been pulled by us in the first place. diff --git a/roles/matrix-jitsi/tasks/setup_jitsi_jvb.yml b/roles/matrix-jitsi/tasks/setup_jitsi_jvb.yml index 90bf4a69f..cdb94ebdd 100644 --- a/roles/matrix-jitsi/tasks/setup_jitsi_jvb.yml +++ b/roles/matrix-jitsi/tasks/setup_jitsi_jvb.yml @@ -5,7 +5,7 @@ # - name: Ensure Matrix jitsi-jvb path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0777 @@ -14,7 +14,7 @@ with_items: - {path: "{{ matrix_jitsi_jvb_base_path }}", when: true} - {path: "{{ matrix_jitsi_jvb_config_path }}", when: true} - when: matrix_jitsi_enabled|bool and item.when + when: matrix_jitsi_enabled | bool and item.when - name: Ensure jitsi-jvb Docker image is pulled docker_image: @@ -22,14 +22,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_jitsi_jvb_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_jitsi_jvb_docker_image_force_pull }}" - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure jitsi-jvb configuration files created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jvb/{{ item }}.j2" dest: "{{ matrix_jitsi_jvb_config_path }}/{{ item }}" owner: "{{ matrix_user_username }}" @@ -38,27 +38,27 @@ with_items: - custom-sip-communicator.properties - logging.properties - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure jitsi-jvb environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jvb/env.j2" dest: "{{ matrix_jitsi_jvb_base_path }}/env" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: 0640 - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure matrix-jitsi-jvb.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/jvb/matrix-jitsi-jvb.service.j2" dest: "{{ matrix_systemd_path }}/matrix-jitsi-jvb.service" mode: 0644 register: matrix_jitsi_jvb_systemd_service_result - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure systemd reloaded after matrix-jitsi-jvb.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_jitsi_enabled and matrix_jitsi_jvb_systemd_service_result.changed" @@ -67,36 +67,36 @@ # - name: Check existence of matrix-jitsi-jvb service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-jitsi-jvb.service" register: matrix_jitsi_jvb_service_stat - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" - name: Ensure matrix-jitsi-jvb is stopped - service: + ansible.builtin.service: name: matrix-jitsi-jvb state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jvb_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jvb_service_stat.stat.exists" - name: Ensure matrix-jitsi-jvb.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-jitsi-jvb.service" state: absent - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jvb_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jvb_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-jitsi-jvb.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_jvb_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_jvb_service_stat.stat.exists" - name: Ensure Matrix jitsi-jvb paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_jitsi_jvb_base_path }}" state: absent - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" # Intentionally not removing the Docker image when uninstalling. # We can't be sure it had been pulled by us in the first place. diff --git a/roles/matrix-jitsi/tasks/setup_jitsi_prosody.yml b/roles/matrix-jitsi/tasks/setup_jitsi_prosody.yml index 6db954b8b..9383b48b6 100644 --- a/roles/matrix-jitsi/tasks/setup_jitsi_prosody.yml +++ b/roles/matrix-jitsi/tasks/setup_jitsi_prosody.yml @@ -5,7 +5,7 @@ # - name: Ensure Matrix jitsi-prosody environment exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0777 @@ -15,7 +15,7 @@ - {path: "{{ matrix_jitsi_prosody_base_path }}", when: true} - {path: "{{ matrix_jitsi_prosody_config_path }}", when: true} - {path: "{{ matrix_jitsi_prosody_plugins_path }}", when: true} - when: matrix_jitsi_enabled|bool and item.when + when: matrix_jitsi_enabled | bool and item.when - name: Ensure jitsi-prosody Docker image is pulled docker_image: @@ -23,40 +23,40 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_jitsi_prosody_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_jitsi_prosody_docker_image_force_pull }}" - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure jitsi-prosody environment variables file is created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/prosody/env.j2" dest: "{{ matrix_jitsi_prosody_base_path }}/env" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: 0640 - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure matrix-jitsi-prosody.service file is installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/prosody/matrix-jitsi-prosody.service.j2" dest: "{{ matrix_systemd_path }}/matrix-jitsi-prosody.service" mode: 0644 register: matrix_jitsi_prosody_systemd_service_result - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure systemd service is reloaded after matrix-jitsi-prosody.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_jitsi_enabled and matrix_jitsi_prosody_systemd_service_result.changed" - name: Ensure authentication is properly configured - include_tasks: + ansible.builtin.include_tasks: file: "{{ role_path }}/tasks/util/setup_jitsi_auth.yml" when: - - matrix_jitsi_enabled|bool - - matrix_jitsi_enable_auth|bool + - matrix_jitsi_enabled | bool + - matrix_jitsi_enable_auth | bool # @@ -64,36 +64,36 @@ # - name: Ensure matrix-jitsi-prosody.service file exists - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-jitsi-prosody.service" register: matrix_jitsi_prosody_service_stat - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" - name: Ensure matrix-jitsi-prosody is stopped - service: + ansible.builtin.service: name: matrix-jitsi-prosody state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_prosody_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_prosody_service_stat.stat.exists" - name: Ensure matrix-jitsi-prosody.service file doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-jitsi-prosody.service" state: absent - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_prosody_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_prosody_service_stat.stat.exists" - name: Ensure systemd is reloaded after matrix-jitsi-prosody.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_prosody_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_prosody_service_stat.stat.exists" - name: Ensure Matrix jitsi-prosody paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_jitsi_prosody_base_path }}" state: absent - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" # Intentionally not removing the Docker image when uninstalling. # We can't be sure it had been pulled by us in the first place. diff --git a/roles/matrix-jitsi/tasks/setup_jitsi_web.yml b/roles/matrix-jitsi/tasks/setup_jitsi_web.yml index feda4ace4..1c7daa4b9 100644 --- a/roles/matrix-jitsi/tasks/setup_jitsi_web.yml +++ b/roles/matrix-jitsi/tasks/setup_jitsi_web.yml @@ -5,7 +5,7 @@ # - name: Ensure Matrix jitsi-web path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0777 @@ -16,7 +16,7 @@ - {path: "{{ matrix_jitsi_web_config_path }}", when: true} - {path: "{{ matrix_jitsi_web_transcripts_path }}", when: true} - {path: "{{ matrix_jitsi_web_crontabs_path }}", when: true} - when: matrix_jitsi_enabled|bool and item.when + when: matrix_jitsi_enabled | bool and item.when - name: Ensure jitsi-web Docker image is pulled docker_image: @@ -24,23 +24,23 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_jitsi_web_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_jitsi_web_docker_image_force_pull }}" - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure jitsi-web environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/web/env.j2" dest: "{{ matrix_jitsi_web_base_path }}/env" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: 0640 - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure jitsi-web configuration files created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/web/{{ item }}.j2" dest: "{{ matrix_jitsi_web_config_path }}/{{ item }}" owner: "{{ matrix_user_username }}" @@ -49,18 +49,18 @@ with_items: - custom-config.js - custom-interface_config.js - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure matrix-jitsi-web.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/web/matrix-jitsi-web.service.j2" dest: "{{ matrix_systemd_path }}/matrix-jitsi-web.service" mode: 0644 register: matrix_jitsi_web_systemd_service_result - when: matrix_jitsi_enabled|bool + when: matrix_jitsi_enabled | bool - name: Ensure systemd reloaded after matrix-jitsi-web.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_jitsi_enabled and matrix_jitsi_web_systemd_service_result.changed" @@ -69,36 +69,36 @@ # - name: Check existence of matrix-jitsi-web service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-jitsi-web.service" register: matrix_jitsi_web_service_stat - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" - name: Ensure matrix-jitsi-web is stopped - service: + ansible.builtin.service: name: matrix-jitsi-web state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_web_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_web_service_stat.stat.exists" - name: Ensure matrix-jitsi-web.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-jitsi-web.service" state: absent - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_web_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_web_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-jitsi-web.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_jitsi_enabled|bool and matrix_jitsi_web_service_stat.stat.exists" + when: "not matrix_jitsi_enabled | bool and matrix_jitsi_web_service_stat.stat.exists" - name: Ensure Matrix jitsi-web paths doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_jitsi_web_base_path }}" state: absent - when: "not matrix_jitsi_enabled|bool" + when: "not matrix_jitsi_enabled | bool" # Intentionally not removing the Docker image when uninstalling. # We can't be sure it had been pulled by us in the first place. diff --git a/roles/matrix-jitsi/tasks/util/setup_jitsi_auth.yml b/roles/matrix-jitsi/tasks/util/setup_jitsi_auth.yml index 50973acb5..d9da9ebe1 100644 --- a/roles/matrix-jitsi/tasks/util/setup_jitsi_auth.yml +++ b/roles/matrix-jitsi/tasks/util/setup_jitsi_auth.yml @@ -4,7 +4,7 @@ # - name: Ensure matrix-jitsi-prosody container is running - systemd: + ansible.builtin.systemd: state: started name: matrix-jitsi-prosody register: matrix_jitsi_prosody_start_result @@ -15,11 +15,13 @@ # - name: Ensure Jitsi internal authentication users are configured - shell: "docker exec matrix-jitsi-prosody prosodyctl --config /config/prosody.cfg.lua register {{ item.username | quote }} meet.jitsi {{ item.password | quote }}" + ansible.builtin.shell: "{{ matrix_host_command_docker }} exec matrix-jitsi-prosody prosodyctl --config /config/prosody.cfg.lua register {{ item.username | quote }} meet.jitsi {{ item.password | quote }}" with_items: "{{ matrix_jitsi_prosody_auth_internal_accounts }}" when: - matrix_jitsi_auth_type == "internal" - matrix_jitsi_prosody_auth_internal_accounts|length > 0 + register: matrix_jitsi_user_configuration_result + changed_when: matrix_jitsi_user_configuration_result.rc == 0 # # Tasks related to configuring other Jitsi authentication mechanisms @@ -33,7 +35,7 @@ # Stop Necessary Services # - name: Ensure matrix-jitsi-prosody container is stopped if necessary - systemd: + ansible.builtin.systemd: state: stopped name: matrix-jitsi-prosody - when: matrix_jitsi_prosody_start_result.changed|bool + when: matrix_jitsi_prosody_start_result.changed | bool diff --git a/roles/matrix-jitsi/tasks/validate_config.yml b/roles/matrix-jitsi/tasks/validate_config.yml index 5131396de..df87b7589 100644 --- a/roles/matrix-jitsi/tasks/validate_config.yml +++ b/roles/matrix-jitsi/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required Jitsi settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) to properly configure Jitsi. @@ -21,19 +21,19 @@ - name: Fail if a Jitsi internal authentication account is not defined - fail: + ansible.builtin.fail: msg: >- At least one Jitsi user needs to be defined in `matrix_jitsi_prosody_auth_internal_accounts` when using internal authentication. If you're setting up Jitsi for the first time, you may have missed a step. Refer to our setup instructions (docs/configuring-playbook-jitsi.md). when: - - matrix_jitsi_enable_auth|bool + - matrix_jitsi_enable_auth | bool - matrix_jitsi_auth_type == 'internal' - matrix_jitsi_prosody_auth_internal_accounts|length == 0 - name: (Deprecation) Catch and report renamed settings - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-ma1sd/defaults/main.yml b/roles/matrix-ma1sd/defaults/main.yml index 19aaf189a..3755a46ab 100644 --- a/roles/matrix-ma1sd/defaults/main.yml +++ b/roles/matrix-ma1sd/defaults/main.yml @@ -93,9 +93,9 @@ matrix_ma1sd_dns_overwrite_homeserver_client_value: "" # https://github.com/ma1uta/ma1sd/blob/master/docs/threepids/session/session-views.md matrix_ma1sd_view_session_custom_templates_enabled: false # Defaults to: https://github.com/ma1uta/ma1sd/blob/master/src/main/resources/templates/session/tokenSubmitSuccess.html -matrix_ma1sd_view_session_custom_onTokenSubmit_success_template: "" +matrix_ma1sd_view_session_custom_onTokenSubmit_success_template: "" # noqa var-naming # Defaults to: https://github.com/ma1uta/ma1sd/blob/master/src/main/resources/templates/session/tokenSubmitFailure.html -matrix_ma1sd_view_session_custom_onTokenSubmit_failure_template: "" +matrix_ma1sd_view_session_custom_onTokenSubmit_failure_template: "" # noqa var-naming # Override the default email templates # To use this, fill in the template variables with the full desired template as a multi-line YAML variable @@ -156,8 +156,8 @@ matrix_ma1sd_configuration_extension_yaml: | # bindDn: CN=My Ma1sd User,OU=Users,DC=example,DC=org # bindPassword: TheUserPassword -matrix_ma1sd_configuration_extension: "{{ matrix_ma1sd_configuration_extension_yaml|from_yaml if matrix_ma1sd_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_ma1sd_configuration_extension: "{{ matrix_ma1sd_configuration_extension_yaml | from_yaml if matrix_ma1sd_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final ma1sd configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_ma1sd_configuration_yaml`. -matrix_ma1sd_configuration: "{{ matrix_ma1sd_configuration_yaml|from_yaml|combine(matrix_ma1sd_configuration_extension, recursive=True) }}" +matrix_ma1sd_configuration: "{{ matrix_ma1sd_configuration_yaml | from_yaml | combine(matrix_ma1sd_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-ma1sd/tasks/init.yml b/roles/matrix-ma1sd/tasks/init.yml index a7c914dbb..1d425006f 100644 --- a/roles/matrix-ma1sd/tasks/init.yml +++ b/roles/matrix-ma1sd/tasks/init.yml @@ -2,10 +2,10 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_ma1sd_container_image_self_build and matrix_ma1sd_enabled|bool" + when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_ma1sd_container_image_self_build and matrix_ma1sd_enabled | bool" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-ma1sd.service'] }}" - when: matrix_ma1sd_enabled|bool + when: matrix_ma1sd_enabled | bool diff --git a/roles/matrix-ma1sd/tasks/main.yml b/roles/matrix-ma1sd/tasks/main.yml index 2902c05d9..f55e7891c 100644 --- a/roles/matrix-ma1sd/tasks/main.yml +++ b/roles/matrix-ma1sd/tasks/main.yml @@ -1,30 +1,30 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.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" +- ansible.builtin.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_install.yml" - when: "run_setup|bool and matrix_ma1sd_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_ma1sd_enabled | bool" tags: - setup-all - setup-ma1sd -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_ma1sd_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_ma1sd_enabled | bool" tags: - setup-all - setup-ma1sd -- import_tasks: "{{ role_path }}/tasks/self_check_ma1sd.yml" +- ansible.builtin.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" + when: "run_self_check | bool and matrix_ma1sd_enabled | bool" tags: - self-check diff --git a/roles/matrix-ma1sd/tasks/migrate_mxisd.yml b/roles/matrix-ma1sd/tasks/migrate_mxisd.yml index 720afa768..7457001c8 100644 --- a/roles/matrix-ma1sd/tasks/migrate_mxisd.yml +++ b/roles/matrix-ma1sd/tasks/migrate_mxisd.yml @@ -3,24 +3,24 @@ # This task is for migrating existing mxisd data when transitioning to the ma1sd fork. - name: Check for existent mxisd data - stat: + ansible.builtin.stat: path: "{{ matrix_base_data_path }}/mxisd/data" register: ma1sd_migrate_mxisd_data_dir_stat - name: Warn if mxisd data detected - debug: + ansible.builtin.debug: msg: > You seem to have an existing mxisd folder in `{{ matrix_base_data_path }}/mxisd`. We are going to migrate it to ma1sd and rename the folder to mxisd.migrated. when: "ma1sd_migrate_mxisd_data_dir_stat.stat.exists" - name: Check existence of old matrix-mxisd service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mxisd.service" register: matrix_mxisd_service_stat - name: Ensure matrix-mxisd is stopped - service: + ansible.builtin.service: name: matrix-mxisd state: stopped enabled: false @@ -28,13 +28,13 @@ when: "matrix_mxisd_service_stat.stat.exists" - name: Check existence of matrix-ma1sd service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-ma1sd.service" register: matrix_ma1sd_service_stat when: "ma1sd_migrate_mxisd_data_dir_stat.stat.exists" - name: Ensure matrix-ma1sd is stopped - service: + ansible.builtin.service: name: matrix-ma1sd state: stopped daemon_reload: true @@ -44,28 +44,37 @@ # recursively copy remote directories (like `/matrix/mxisd/data/sign.key`) in older versions of Ansible. - block: - name: Copy mxisd data files to ma1sd folder - command: "cp -ar {{ matrix_base_data_path }}/mxisd/data {{ matrix_ma1sd_base_path }}" + ansible.builtin.command: + cmd: "cp -ar {{ matrix_base_data_path }}/mxisd/data {{ matrix_ma1sd_base_path }}" + register: matrix_ma1sd_migrate_mxisd_data_files_copying_result + changed_when: matrix_ma1sd_migrate_mxisd_data_files_copying_result.rc == 0 - name: Check existence of mxisd.db file - stat: + ansible.builtin.stat: path: "{{ matrix_ma1sd_data_path }}/mxisd.db" register: matrix_ma1sd_mxisd_db_stat - name: Rename database (mxisd.db -> ma1sd.db) - command: "mv {{ matrix_ma1sd_data_path }}/mxisd.db {{ matrix_ma1sd_data_path }}/ma1sd.db" + ansible.builtin.command: + cmd: "mv {{ matrix_ma1sd_data_path }}/mxisd.db {{ matrix_ma1sd_data_path }}/ma1sd.db" + register: matrix_ma1sd_migrate_mxisd_move_db_result + changed_when: matrix_ma1sd_migrate_mxisd_move_db_result.rc == 0 when: "matrix_ma1sd_mxisd_db_stat.stat.exists" - name: Rename mxisd folder - command: "mv {{ matrix_base_data_path }}/mxisd {{ matrix_base_data_path }}/mxisd.migrated" + ansible.builtin.command: + cmd: "mv {{ matrix_base_data_path }}/mxisd {{ matrix_base_data_path }}/mxisd.migrated" + register: matrix_ma1sd_migrate_mxisd_move_directory_result + changed_when: matrix_ma1sd_migrate_mxisd_move_directory_result.rc == 0 when: "ma1sd_migrate_mxisd_data_dir_stat.stat.exists" - name: Ensure outdated matrix-mxisd.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mxisd.service" state: absent when: "matrix_mxisd_service_stat.stat.exists" - name: Ensure systemd reloaded after removing outdated matrix-mxisd.service - service: + ansible.builtin.service: daemon_reload: true when: "matrix_mxisd_service_stat.stat.exists" diff --git a/roles/matrix-ma1sd/tasks/self_check_ma1sd.yml b/roles/matrix-ma1sd/tasks/self_check_ma1sd.yml index 4a4c71367..6fde9dd2f 100644 --- a/roles/matrix-ma1sd/tasks/self_check_ma1sd.yml +++ b/roles/matrix-ma1sd/tasks/self_check_ma1sd.yml @@ -1,10 +1,10 @@ --- -- set_fact: +- ansible.builtin.set_fact: ma1sd_url_endpoint_public: "https://{{ matrix_server_fqn_matrix }}/_matrix/identity/api/v1" - name: Check ma1sd Identity Service - uri: + ansible.builtin.uri: url: "{{ ma1sd_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_ma1sd_self_check_validate_certificates }}" @@ -13,10 +13,10 @@ ignore_errors: true - name: Fail if ma1sd Identity Service not working - fail: + ansible.builtin.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: + ansible.builtin.debug: msg: "ma1sd at `{{ matrix_server_fqn_matrix }}` is working (checked endpoint: `{{ ma1sd_url_endpoint_public }}`)" diff --git a/roles/matrix-ma1sd/tasks/setup_install.yml b/roles/matrix-ma1sd/tasks/setup_install.yml index e3347a4db..ef32288fa 100644 --- a/roles/matrix-ma1sd/tasks/setup_install.yml +++ b/roles/matrix-ma1sd/tasks/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure ma1sd paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -11,38 +11,40 @@ - {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: "item.when|bool" + when: "item.when | bool" -- import_tasks: "{{ role_path }}/tasks/migrate_mxisd.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_mxisd.yml" # These (SQLite -> Postgres) migration tasks are usually at the top, # but we'd like to run them after `migrate_mxisd.yml`, which requires the ma1sd paths to exist. -- set_fact: +- ansible.builtin.set_fact: matrix_ma1sd_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_ma1sd_sqlite_database_path_local }}" register: matrix_ma1sd_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_ma1sd_sqlite_database_path_local }}" dst: "{{ matrix_ma1sd_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_ma1sd_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-ma1sd.service'] pgloader_options: ['--with "quote identifiers"'] - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_ma1sd_requires_restart: true - when: "matrix_ma1sd_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_ma1sd_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_ma1sd_database_engine == 'postgres'" - name: Ensure ma1sd image is pulled @@ -51,7 +53,7 @@ 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: "not matrix_ma1sd_container_image_self_build|bool" + when: "not matrix_ma1sd_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" @@ -59,7 +61,7 @@ - block: - name: Ensure gradle is installed for self-building (Debian) - apt: + ansible.builtin.apt: name: - gradle state: present @@ -67,7 +69,7 @@ when: (ansible_os_family == 'Debian') - name: Ensure gradle is installed for self-building (RedHat) - fail: + ansible.builtin.fail: msg: "Installing gradle on RedHat ({{ ansible_distribution }}) is currently not supported, so self-building ma1sd cannot happen at this time" when: ansible_os_family == 'RedHat' @@ -75,12 +77,12 @@ pacman: name: - gradle - state: latest + state: present update_cache: true when: ansible_distribution == 'Archlinux' - name: Ensure ma1sd repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_ma1sd_container_image_self_build_repo }}" dest: "{{ matrix_ma1sd_docker_src_files_path }}" version: "{{ matrix_ma1sd_container_image_self_build_branch }}" @@ -90,9 +92,11 @@ register: matrix_ma1sd_git_pull_results - name: Ensure ma1sd Docker image is built - shell: "DOCKER_BUILDKIT=1 ./gradlew dockerBuild" - args: + ansible.builtin.command: + cmd: ./gradlew dockerBuild chdir: "{{ matrix_ma1sd_docker_src_files_path }}" + environment: + DOCKER_BUILDKIT: 1 when: matrix_ma1sd_git_pull_results.changed - name: Ensure ma1sd Docker image is tagged correctly @@ -107,18 +111,18 @@ repository: "{{ matrix_ma1sd_docker_image }}" force_tag: true source: local - when: "matrix_ma1sd_container_image_self_build|bool" + when: "matrix_ma1sd_container_image_self_build | bool" - name: Ensure ma1sd config installed - copy: - content: "{{ matrix_ma1sd_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_ma1sd_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_ma1sd_config_path }}/ma1sd.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure custom view templates are installed, if any - copy: + ansible.builtin.copy: content: "{{ item.value }}" dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}" mode: 0644 @@ -127,10 +131,10 @@ with_items: - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_success_template }}", location: 'tokenSubmitSuccess.html'} - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_failure_template }}", location: 'tokenSubmitFailure.html'} - when: "matrix_ma1sd_view_session_custom_templates_enabled|bool and item.value" + when: "matrix_ma1sd_view_session_custom_templates_enabled | bool and item.value" - name: Ensure custom email templates are installed, if any - copy: + ansible.builtin.copy: content: "{{ item.value }}" dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}" mode: 0644 @@ -141,11 +145,11 @@ - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'} - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'} - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'} - when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled|bool and item.value" + when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled | bool and item.value" # Only cleaning up for people who define the respective templates - name: (Cleanup) Ensure custom email templates are not in data/ anymore (we've put them in config/) - file: + ansible.builtin.file: path: "{{ matrix_ma1sd_data_path }}/{{ item.location }}" state: absent with_items: @@ -153,22 +157,22 @@ - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'} - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'} - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'} - when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled|bool and item.value" + when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled | bool and item.value" - name: Ensure matrix-ma1sd.service installed - template: + ansible.builtin.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 - name: Ensure systemd reloaded after matrix-ma1sd.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_ma1sd_systemd_service_result.changed|bool" + when: "matrix_ma1sd_systemd_service_result.changed | bool" - name: Ensure matrix-ma1sd.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-ma1sd.service" state: restarted - when: "matrix_ma1sd_requires_restart|bool" + when: "matrix_ma1sd_requires_restart | bool" diff --git a/roles/matrix-ma1sd/tasks/setup_uninstall.yml b/roles/matrix-ma1sd/tasks/setup_uninstall.yml index 30a1bfda6..2bc505b0f 100644 --- a/roles/matrix-ma1sd/tasks/setup_uninstall.yml +++ b/roles/matrix-ma1sd/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-ma1sd service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-ma1sd.service" register: matrix_ma1sd_service_stat - name: Ensure matrix-ma1sd is stopped - service: + ansible.builtin.service: name: matrix-ma1sd state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_ma1sd_service_stat.stat.exists|bool" + when: "matrix_ma1sd_service_stat.stat.exists | bool" - name: Ensure matrix-ma1sd.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-ma1sd.service" state: absent - when: "matrix_ma1sd_service_stat.stat.exists|bool" + when: "matrix_ma1sd_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-ma1sd.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_ma1sd_service_stat.stat.exists|bool" + when: "matrix_ma1sd_service_stat.stat.exists | bool" - name: Ensure Matrix ma1sd paths don't exist - file: + ansible.builtin.file: path: "{{ matrix_ma1sd_base_path }}" state: absent diff --git a/roles/matrix-ma1sd/tasks/validate_config.yml b/roles/matrix-ma1sd/tasks/validate_config.yml index 5f621fcac..af12dd3f1 100644 --- a/roles/matrix-ma1sd/tasks/validate_config.yml +++ b/roles/matrix-ma1sd/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: (Deprecation) Warn about ma1sd variables that are not used anymore - fail: + ansible.builtin.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. @@ -31,7 +31,7 @@ - 'matrix_ma1sd_architecture' - name: Ensure ma1sd configuration does not contain any dot-notation keys - fail: + ansible.builtin.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. @@ -40,7 +40,7 @@ with_dict: "{{ matrix_ma1sd_configuration }}" - name: Fail if required ma1sd settings not defined - fail: + ansible.builtin.fail: msg: > You need to define a required configuration setting (`{{ item }}`) for using ma1sd. when: "vars[item] == ''" @@ -49,7 +49,7 @@ - "matrix_ma1sd_dns_overwrite_homeserver_client_value" - name: (Deprecation) Catch and report renamed ma1sd variables - fail: + ansible.builtin.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 }}`). @@ -60,7 +60,7 @@ - {'old': 'matrix_ma1sd_default_port', 'new': 'matrix_ma1sd_container_port'} - name: (Deprecation) Catch and report mxisd variables - fail: + ansible.builtin.fail: msg: >- mxisd is deprecated and has been replaced with ma1sd (https://github.com/ma1uta/ma1sd), a compatible fork. The playbook will migrate your existing mxisd configuration and data automatically, but you need to adjust variable names. diff --git a/roles/matrix-ma1sd/vars/main.yml b/roles/matrix-ma1sd/vars/main.yml index b6c97a593..3adc735e9 100644 --- a/roles/matrix-ma1sd/vars/main.yml +++ b/roles/matrix-ma1sd/vars/main.yml @@ -2,4 +2,4 @@ # Doing `|from_yaml` when the extension contains nothing yields an empty string (""). # We need to ensure it's a dictionary or `|combine` (when building `matrix_ma1sd_configuration`) will fail later. -matrix_ma1sd_configuration_extension: "{{ matrix_ma1sd_configuration_extension_yaml|from_yaml if matrix_ma1sd_configuration_extension_yaml|from_yaml else {} }}" +matrix_ma1sd_configuration_extension: "{{ matrix_ma1sd_configuration_extension_yaml | from_yaml if matrix_ma1sd_configuration_extension_yaml | from_yaml else {} }}" diff --git a/roles/matrix-mailer/tasks/init.yml b/roles/matrix-mailer/tasks/init.yml index c928d5574..e83902d7a 100644 --- a/roles/matrix-mailer/tasks/init.yml +++ b/roles/matrix-mailer/tasks/init.yml @@ -2,10 +2,10 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_mailer_container_image_self_build and matrix_mailer_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mailer.service'] }}" - when: matrix_mailer_enabled|bool + when: matrix_mailer_enabled | bool diff --git a/roles/matrix-mailer/tasks/main.yml b/roles/matrix-mailer/tasks/main.yml index c69dad201..e49ff26d6 100644 --- a/roles/matrix-mailer/tasks/main.yml +++ b/roles/matrix-mailer/tasks/main.yml @@ -1,11 +1,11 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup_mailer.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_mailer.yml" + when: run_setup | bool tags: - setup-all - setup-mailer diff --git a/roles/matrix-mailer/tasks/setup_mailer.yml b/roles/matrix-mailer/tasks/setup_mailer.yml index d2f8f9171..2ab39df5d 100644 --- a/roles/matrix-mailer/tasks/setup_mailer.yml +++ b/roles/matrix-mailer/tasks/setup_mailer.yml @@ -5,7 +5,7 @@ # - name: Ensure mailer base path exists - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -14,17 +14,17 @@ with_items: - {path: "{{ matrix_mailer_base_path }}", when: true} - {path: "{{ matrix_mailer_container_image_self_build_src_files_path }}", when: "{{ matrix_mailer_container_image_self_build }}"} - when: "matrix_mailer_enabled|bool and item.when" + when: "matrix_mailer_enabled | bool and item.when" - name: Ensure mailer environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/env-mailer.j2" dest: "{{ matrix_mailer_base_path }}/env-mailer" mode: 0640 - when: matrix_mailer_enabled|bool + when: matrix_mailer_enabled | bool - name: Ensure exim-relay repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_mailer_container_image_self_build_repository_url }}" dest: "{{ matrix_mailer_container_image_self_build_src_files_path }}" version: "{{ matrix_mailer_container_image_self_build_version }}" @@ -32,7 +32,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_mailer_git_pull_results - when: "matrix_mailer_enabled|bool and matrix_mailer_container_image_self_build|bool" + when: "matrix_mailer_enabled | bool and matrix_mailer_container_image_self_build | bool" - name: Ensure exim-relay Docker image is built docker_image: @@ -44,7 +44,7 @@ dockerfile: Dockerfile path: "{{ matrix_mailer_container_image_self_build_src_files_path }}" pull: true - when: "matrix_mailer_enabled|bool and matrix_mailer_container_image_self_build|bool" + when: "matrix_mailer_enabled | bool and matrix_mailer_container_image_self_build | bool" - name: Ensure exim-relay image is pulled docker_image: @@ -52,63 +52,63 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mailer_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_mailer_docker_image_force_pull }}" - when: "matrix_mailer_enabled|bool and not matrix_mailer_container_image_self_build|bool" + when: "matrix_mailer_enabled | bool and not matrix_mailer_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-mailer.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mailer.service.j2" dest: "{{ matrix_systemd_path }}/matrix-mailer.service" mode: 0644 register: matrix_mailer_systemd_service_result - when: matrix_mailer_enabled|bool + when: matrix_mailer_enabled | bool - name: Ensure systemd reloaded after matrix-mailer.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_mailer_enabled|bool and matrix_mailer_systemd_service_result.changed" + when: "matrix_mailer_enabled | bool and matrix_mailer_systemd_service_result.changed" # # Tasks related to getting rid of the mailer (if it was previously enabled) # - name: Check existence of matrix-mailer service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-mailer.service" register: matrix_mailer_service_stat - when: "not matrix_mailer_enabled|bool" + when: "not matrix_mailer_enabled | bool" - name: Ensure matrix-mailer is stopped - service: + ansible.builtin.service: name: matrix-mailer state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_mailer_enabled|bool and matrix_mailer_service_stat.stat.exists" + when: "not matrix_mailer_enabled | bool and matrix_mailer_service_stat.stat.exists" - name: Ensure matrix-mailer.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-mailer.service" state: absent - when: "not matrix_mailer_enabled|bool and matrix_mailer_service_stat.stat.exists" + when: "not matrix_mailer_enabled | bool and matrix_mailer_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-mailer.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_mailer_enabled|bool and matrix_mailer_service_stat.stat.exists" + when: "not matrix_mailer_enabled | bool and matrix_mailer_service_stat.stat.exists" - name: Ensure Matrix mailer environment variables path doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_mailer_base_path }}" state: absent - when: "not matrix_mailer_enabled|bool" + when: "not matrix_mailer_enabled | bool" - name: Ensure mailer Docker image doesn't exist docker_image: name: "{{ matrix_mailer_docker_image }}" state: absent - when: "not matrix_mailer_enabled|bool" + when: "not matrix_mailer_enabled | bool" diff --git a/roles/matrix-nginx-proxy/tasks/init.yml b/roles/matrix-nginx-proxy/tasks/init.yml index ddc8cb47b..eb4249cb8 100644 --- a/roles/matrix-nginx-proxy/tasks/init.yml +++ b/roles/matrix-nginx-proxy/tasks/init.yml @@ -1,9 +1,9 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-nginx-proxy.service'] }}" - when: matrix_nginx_proxy_enabled|bool + when: matrix_nginx_proxy_enabled | bool -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + [item.name] }}" - when: "item.applicable|bool and item.enableable|bool" + when: "item.applicable | bool and item.enableable | bool" with_items: "{{ matrix_ssl_renewal_systemd_units_list }}" diff --git a/roles/matrix-nginx-proxy/tasks/main.yml b/roles/matrix-nginx-proxy/tasks/main.yml index 74f8e8d1d..9c34d1f56 100644 --- a/roles/matrix-nginx-proxy/tasks/main.yml +++ b/roles/matrix-nginx-proxy/tasks/main.yml @@ -1,39 +1,39 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always # Always validating the configuration, even if `matrix_nginx_proxy: false`. # This role performs actions even if the role is disabled, so we need # to ensure there's a valid configuration in any case. -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool tags: - setup-all - setup-nginx-proxy -- import_tasks: "{{ role_path }}/tasks/ssl/main.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ssl/main.yml" + when: run_setup | bool tags: - setup-all - setup-nginx-proxy - setup-ssl -- import_tasks: "{{ role_path }}/tasks/setup_nginx_proxy.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_nginx_proxy.yml" + when: run_setup | bool tags: - setup-all - setup-nginx-proxy -- import_tasks: "{{ role_path }}/tasks/self_check_well_known.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_well_known.yml" delegate_to: 127.0.0.1 become: false - when: run_self_check|bool + when: run_self_check | bool tags: - self-check - name: Mark matrix-nginx-proxy role as executed - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_role_executed: true tags: - always diff --git a/roles/matrix-nginx-proxy/tasks/nginx-proxy/setup_metrics_auth.yml b/roles/matrix-nginx-proxy/tasks/nginx-proxy/setup_metrics_auth.yml index 046746df2..c511e402c 100644 --- a/roles/matrix-nginx-proxy/tasks/nginx-proxy/setup_metrics_auth.yml +++ b/roles/matrix-nginx-proxy/tasks/nginx-proxy/setup_metrics_auth.yml @@ -2,7 +2,7 @@ # When we're dealing with raw htpasswd content, we just store it in the file directly. - name: Ensure matrix-metrics-htpasswd is present when generated from raw content (protecting /metrics/* URIs) - copy: + ansible.builtin.copy: content: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content }}" dest: "{{ matrix_nginx_proxy_data_path }}/matrix-metrics-htpasswd" owner: "{{ matrix_user_username }}" @@ -30,7 +30,7 @@ # We store the password in a file and make the `htpasswd` tool read it from there, # as opposed to passing it directly on stdin (which will expose it to other processes on the server). - name: Store metrics password in a temporary file - copy: + ansible.builtin.copy: content: "{{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password }}" dest: "/tmp/matrix-nginx-proxy-metrics-password" mode: 0400 @@ -38,7 +38,7 @@ group: "{{ matrix_user_gid }}" - name: Generate matrix-metrics-htpasswd from username/password (protecting /metrics/* URIs) - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -51,9 +51,10 @@ {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_apache_container_image }} -c 'cat /password | htpasswd -i -c /data/matrix-metrics-htpasswd {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username }} && chmod 600 /data/matrix-metrics-htpasswd' + changed_when: true - name: Delete temporary metrics password file - file: + ansible.builtin.file: path: /tmp/matrix-nginx-proxy-metrics-password state: absent when: matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username != '' diff --git a/roles/matrix-nginx-proxy/tasks/self_check_well_known.yml b/roles/matrix-nginx-proxy/tasks/self_check_well_known.yml index be1b65553..2a5042d5a 100644 --- a/roles/matrix-nginx-proxy/tasks/self_check_well_known.yml +++ b/roles/matrix-nginx-proxy/tasks/self_check_well_known.yml @@ -1,7 +1,7 @@ --- - name: Determine well-known files to check (Matrix) - set_fact: + ansible.builtin.set_fact: well_known_file_checks: - path: /.well-known/matrix/client purpose: Client Discovery @@ -10,7 +10,7 @@ validate_certs: "{{ matrix_nginx_proxy_self_check_validate_certificates }}" - block: - - set_fact: + - ansible.builtin.set_fact: well_known_file_check_matrix_server: path: /.well-known/matrix/server purpose: Server Discovery @@ -19,12 +19,12 @@ validate_certs: "{{ matrix_nginx_proxy_self_check_validate_certificates }}" - name: Determine domains that we require certificates for (ma1sd) - set_fact: + ansible.builtin.set_fact: well_known_file_checks: "{{ well_known_file_checks + [well_known_file_check_matrix_server] }}" - when: matrix_well_known_matrix_server_enabled|bool + when: matrix_well_known_matrix_server_enabled | bool - name: Perform well-known checks - include_tasks: "{{ role_path }}/tasks/self_check_well_known_file.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/self_check_well_known_file.yml" with_items: "{{ well_known_file_checks }}" loop_control: loop_var: well_known_file_check diff --git a/roles/matrix-nginx-proxy/tasks/self_check_well_known_file.yml b/roles/matrix-nginx-proxy/tasks/self_check_well_known_file.yml index 588cd1e78..95a43dead 100644 --- a/roles/matrix-nginx-proxy/tasks/self_check_well_known_file.yml +++ b/roles/matrix-nginx-proxy/tasks/self_check_well_known_file.yml @@ -1,13 +1,13 @@ --- -- set_fact: +- ansible.builtin.set_fact: 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 }}" # 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 - uri: + ansible.builtin.uri: url: "{{ well_known_url_matrix }}" follow_redirects: none return_content: true @@ -19,25 +19,25 @@ ignore_errors: true - name: Fail if .well-known not working on the matrix hostname - fail: + ansible.builtin.fail: 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 }}" when: "result_well_known_matrix.failed" - name: Parse JSON for well-known payload at the matrix hostname - set_fact: - well_known_matrix_payload: "{{ result_well_known_matrix.content|from_json }}" + ansible.builtin.set_fact: + well_known_matrix_payload: "{{ result_well_known_matrix.content | from_json }}" - name: Fail if .well-known not CORS-aware on the matrix hostname - fail: + ansible.builtin.fail: 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." 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 - debug: + ansible.builtin.debug: msg: "well-known for {{ well_known_file_check.purpose }} is configured correctly for `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ well_known_url_matrix }}`)" - name: Check .well-known on the identity hostname - uri: + ansible.builtin.uri: url: "{{ well_known_url_identity }}" follow_redirects: "{{ well_known_file_check.follow_redirects }}" return_content: true @@ -49,25 +49,25 @@ ignore_errors: true - name: Fail if .well-known not working on the identity hostname - fail: + ansible.builtin.fail: 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 }}" when: "result_well_known_identity.failed" - name: Parse JSON for well-known payload at the identity hostname - set_fact: - well_known_identity_payload: "{{ result_well_known_identity.content|from_json }}" + ansible.builtin.set_fact: + well_known_identity_payload: "{{ result_well_known_identity.content | from_json }}" - name: Fail if .well-known not CORS-aware on the identity hostname - fail: + ansible.builtin.fail: 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" 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 - fail: + ansible.builtin.fail: 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?" when: "well_known_matrix_payload != well_known_identity_payload" - name: Report working .well-known on the identity hostname - debug: + ansible.builtin.debug: 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 }}`)" diff --git a/roles/matrix-nginx-proxy/tasks/setup_nginx_proxy.yml b/roles/matrix-nginx-proxy/tasks/setup_nginx_proxy.yml index 70541fdc1..e2d3c36e8 100644 --- a/roles/matrix-nginx-proxy/tasks/setup_nginx_proxy.yml +++ b/roles/matrix-nginx-proxy/tasks/setup_nginx_proxy.yml @@ -11,7 +11,7 @@ # to be unnecessary. # - name: Ensure Matrix nginx-proxy paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -22,159 +22,159 @@ - {path: "{{ matrix_nginx_proxy_data_path }}", when: true} - {path: "{{ matrix_nginx_proxy_confd_path }}", when: true} - {path: "{{ matrix_nginx_proxy_synapse_cache_path }}", when: "{{ matrix_nginx_proxy_synapse_cache_enabled and not matrix_nginx_proxy_enabled }}"} - when: item.when|bool + when: item.when | bool - name: Ensure Matrix nginx-proxy configured (main config override) - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/nginx.conf.j2" dest: "{{ matrix_nginx_proxy_base_path }}/nginx.conf" mode: 0644 - when: matrix_nginx_proxy_enabled|bool + when: matrix_nginx_proxy_enabled | bool - name: Setup metrics - include_tasks: "{{ role_path }}/tasks/nginx-proxy/setup_metrics_auth.yml" - when: matrix_nginx_proxy_proxy_matrix_metrics_enabled|bool and matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled|bool + ansible.builtin.include_tasks: "{{ role_path }}/tasks/nginx-proxy/setup_metrics_auth.yml" + when: matrix_nginx_proxy_proxy_matrix_metrics_enabled | bool and matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled | bool - name: Ensure Matrix nginx-proxy configured (generic) - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/nginx-http.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/nginx-http.conf" mode: 0644 - when: matrix_nginx_proxy_enabled|bool + when: matrix_nginx_proxy_enabled | bool - name: Ensure Matrix nginx-proxy configuration for matrix-synapse exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-synapse.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-synapse.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_synapse_enabled|bool + when: matrix_nginx_proxy_proxy_synapse_enabled | bool - name: Ensure Matrix nginx-proxy configuration for matrix-synapse deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-synapse.conf" state: absent - when: "not matrix_nginx_proxy_proxy_synapse_enabled|bool" + when: "not matrix_nginx_proxy_proxy_synapse_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for matrix-dendrite exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-dendrite.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-dendrite.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_dendrite_enabled|bool + when: matrix_nginx_proxy_proxy_dendrite_enabled | bool - name: Ensure Matrix nginx-proxy configuration for matrix-dendrite deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-dendrite.conf" state: absent - when: "not matrix_nginx_proxy_proxy_dendrite_enabled|bool" + when: "not matrix_nginx_proxy_proxy_dendrite_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for Element domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-client-element.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-client-element.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_element_enabled|bool + when: matrix_nginx_proxy_proxy_element_enabled | bool - name: Ensure Matrix nginx-proxy configuration for riot domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-riot-web.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-riot-web.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_riot_compat_redirect_enabled|bool + when: matrix_nginx_proxy_proxy_riot_compat_redirect_enabled | bool - name: Ensure Matrix nginx-proxy configuration for Hydrogen domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-client-hydrogen.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-client-hydrogen.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_hydrogen_enabled|bool + when: matrix_nginx_proxy_proxy_hydrogen_enabled | bool - name: Ensure Matrix nginx-proxy configuration for Cinny domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-client-cinny.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-client-cinny.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_cinny_enabled|bool + when: matrix_nginx_proxy_proxy_cinny_enabled | bool - name: Ensure Matrix nginx-proxy configuration for buscarron domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-bot-buscarron.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-bot-buscarron.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_buscarron_enabled|bool + when: matrix_nginx_proxy_proxy_buscarron_enabled | bool - name: Ensure Matrix nginx-proxy configuration for dimension domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-dimension.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-dimension.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_dimension_enabled|bool + when: matrix_nginx_proxy_proxy_dimension_enabled | bool - name: Ensure Matrix nginx-proxy configuration for goneb domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-bot-go-neb.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-bot-go-neb.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_bot_go_neb_enabled|bool + when: matrix_nginx_proxy_proxy_bot_go_neb_enabled | bool - name: Ensure Matrix nginx-proxy configuration for jitsi domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-jitsi.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-jitsi.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_jitsi_enabled|bool + when: matrix_nginx_proxy_proxy_jitsi_enabled | bool - name: Ensure Matrix nginx-proxy configuration for grafana domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-grafana.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-grafana.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_grafana_enabled|bool + when: matrix_nginx_proxy_proxy_grafana_enabled | bool - name: Ensure Matrix nginx-proxy configuration for sygnal domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-sygnal.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-sygnal.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_sygnal_enabled|bool + when: matrix_nginx_proxy_proxy_sygnal_enabled | bool - name: Ensure Matrix nginx-proxy configuration for ntfy domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-ntfy.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-ntfy.conf" mode: 0644 - when: matrix_nginx_proxy_proxy_ntfy_enabled|bool + when: matrix_nginx_proxy_proxy_ntfy_enabled | bool - name: Ensure Matrix nginx-proxy configuration for Matrix domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-domain.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-domain.conf" mode: 0644 - name: Ensure Matrix nginx-proxy data directory for base domain exists - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_data_path }}/matrix-domain" state: directory mode: 0750 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_nginx_proxy_base_domain_serving_enabled|bool and matrix_nginx_proxy_base_domain_create_directory|bool + when: matrix_nginx_proxy_base_domain_serving_enabled | bool and matrix_nginx_proxy_base_domain_create_directory | bool - name: Ensure Matrix nginx-proxy homepage for base domain exists - copy: + ansible.builtin.copy: content: "{{ matrix_nginx_proxy_base_domain_homepage_template }}" dest: "{{ matrix_nginx_proxy_data_path }}/matrix-domain/index.html" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_nginx_proxy_base_domain_serving_enabled|bool and matrix_nginx_proxy_base_domain_homepage_enabled|bool and matrix_nginx_proxy_base_domain_create_directory|bool + when: matrix_nginx_proxy_base_domain_serving_enabled | bool and matrix_nginx_proxy_base_domain_homepage_enabled | bool and matrix_nginx_proxy_base_domain_create_directory | bool - name: Ensure Matrix nginx-proxy configuration for base domain exists - template: + ansible.builtin.template: src: "{{ role_path }}/templates/nginx/conf.d/matrix-base-domain.conf.j2" dest: "{{ matrix_nginx_proxy_confd_path }}/matrix-base-domain.conf" mode: 0644 - when: matrix_nginx_proxy_base_domain_serving_enabled|bool + when: matrix_nginx_proxy_base_domain_serving_enabled | bool # # Tasks related to setting up matrix-nginx-proxy @@ -185,22 +185,22 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_nginx_proxy_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_nginx_proxy_docker_image_force_pull }}" - when: matrix_nginx_proxy_enabled|bool + when: matrix_nginx_proxy_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-nginx-proxy.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-nginx-proxy.service.j2" dest: "{{ matrix_systemd_path }}/matrix-nginx-proxy.service" mode: 0644 register: matrix_nginx_proxy_systemd_service_result - when: matrix_nginx_proxy_enabled|bool + when: matrix_nginx_proxy_enabled | bool - name: Ensure systemd reloaded after matrix-nginx-proxy.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_nginx_proxy_enabled and matrix_nginx_proxy_systemd_service_result.changed" @@ -210,128 +210,128 @@ # - name: Check existence of matrix-nginx-proxy service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-nginx-proxy.service" register: matrix_nginx_proxy_service_stat - when: "not matrix_nginx_proxy_enabled|bool" + when: "not matrix_nginx_proxy_enabled | bool" - name: Ensure matrix-nginx-proxy is stopped - service: + ansible.builtin.service: name: matrix-nginx-proxy state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_nginx_proxy_enabled|bool and matrix_nginx_proxy_service_stat.stat.exists" + when: "not matrix_nginx_proxy_enabled | bool and matrix_nginx_proxy_service_stat.stat.exists" - name: Ensure matrix-nginx-proxy.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-nginx-proxy.service" state: absent - when: "not matrix_nginx_proxy_enabled|bool and matrix_nginx_proxy_service_stat.stat.exists" + when: "not matrix_nginx_proxy_enabled | bool and matrix_nginx_proxy_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-nginx-proxy.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_nginx_proxy_enabled|bool and matrix_nginx_proxy_service_stat.stat.exists" + when: "not matrix_nginx_proxy_enabled | bool and matrix_nginx_proxy_service_stat.stat.exists" - name: Ensure Matrix nginx-proxy configuration for matrix domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-domain.conf" state: absent - when: "not matrix_nginx_proxy_proxy_matrix_enabled|bool" + when: "not matrix_nginx_proxy_proxy_matrix_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for riot domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-riot-web.conf" state: absent - when: "not matrix_nginx_proxy_proxy_riot_compat_redirect_enabled|bool" + when: "not matrix_nginx_proxy_proxy_riot_compat_redirect_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for Hydrogen domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-client-hydrogen.conf" state: absent - when: "not matrix_nginx_proxy_proxy_hydrogen_enabled|bool" + when: "not matrix_nginx_proxy_proxy_hydrogen_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for Cinny domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-client-cinny.conf" state: absent - when: "not matrix_nginx_proxy_proxy_cinny_enabled|bool" + when: "not matrix_nginx_proxy_proxy_cinny_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for buscarron domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-bot-buscarron.conf" state: absent - when: "not matrix_nginx_proxy_proxy_buscarron_enabled|bool" + when: "not matrix_nginx_proxy_proxy_buscarron_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for dimension domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-dimension.conf" state: absent - when: "not matrix_nginx_proxy_proxy_dimension_enabled|bool" + when: "not matrix_nginx_proxy_proxy_dimension_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for goneb domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-bot-go-neb.conf" state: absent - when: "not matrix_nginx_proxy_proxy_bot_go_neb_enabled|bool" + when: "not matrix_nginx_proxy_proxy_bot_go_neb_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for jitsi domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-jitsi.conf" state: absent - when: "not matrix_nginx_proxy_proxy_jitsi_enabled|bool" + when: "not matrix_nginx_proxy_proxy_jitsi_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for grafana domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-grafana.conf" state: absent - when: "not matrix_nginx_proxy_proxy_grafana_enabled|bool" + when: "not matrix_nginx_proxy_proxy_grafana_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for sygnal domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-sygnal.conf" state: absent - when: "not matrix_nginx_proxy_proxy_sygnal_enabled|bool" + when: "not matrix_nginx_proxy_proxy_sygnal_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for ntfy domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-ntfy.conf" state: absent - when: "not matrix_nginx_proxy_proxy_ntfy_enabled|bool" + when: "not matrix_nginx_proxy_proxy_ntfy_enabled | bool" - name: Ensure Matrix nginx-proxy homepage for base domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_data_path }}/matrix-domain/index.html" state: absent - when: "not matrix_nginx_proxy_base_domain_serving_enabled|bool" + when: "not matrix_nginx_proxy_base_domain_serving_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for base domain deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_confd_path }}/matrix-base-domain.conf" state: absent - when: "not matrix_nginx_proxy_base_domain_serving_enabled|bool" + when: "not matrix_nginx_proxy_base_domain_serving_enabled | bool" - name: Ensure Matrix nginx-proxy configuration for main config override deleted - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_base_path }}/nginx.conf" state: absent - when: "not matrix_nginx_proxy_enabled|bool" + when: "not matrix_nginx_proxy_enabled | bool" - name: Ensure Matrix nginx-proxy htpasswd is deleted (protecting /_synapse/metrics URI) - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_data_path }}/matrix-synapse-metrics-htpasswd" state: absent # This file is now generated by the matrix-synapse role and saved in the Synapse directory - name: (Cleanup) Ensure old sample prometheus.yml for external scraping is deleted - file: + ansible.builtin.file: path: "{{ matrix_base_data_path }}/external_prometheus.yml.example" state: absent - name: Ensure Matrix nginx-proxy htpasswd is deleted (protecting /metrics/* URIs) - file: + ansible.builtin.file: path: "{{ matrix_nginx_proxy_data_path }}/matrix-metrics-htpasswd" state: absent - when: "not matrix_nginx_proxy_proxy_matrix_metrics_enabled|bool or not matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled|bool" + when: "not matrix_nginx_proxy_proxy_matrix_metrics_enabled | bool or not matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled | bool" diff --git a/roles/matrix-nginx-proxy/tasks/setup_well_known.yml b/roles/matrix-nginx-proxy/tasks/setup_well_known.yml index 1c85552c3..11e941bd4 100644 --- a/roles/matrix-nginx-proxy/tasks/setup_well_known.yml +++ b/roles/matrix-nginx-proxy/tasks/setup_well_known.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_well_known_file_path: "{{ matrix_static_files_base_path }}/.well-known/matrix/client" # We need others to be able to read these directories too, @@ -7,7 +7,7 @@ # # For running with another webserver, we recommend being part of the `matrix` group. - name: Ensure Matrix static-files path exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0755 @@ -17,7 +17,7 @@ - "{{ matrix_static_files_base_path }}/.well-known/matrix" - name: Ensure Matrix /.well-known/matrix/client configured - template: + ansible.builtin.template: src: "{{ role_path }}/templates/well-known/matrix-client.j2" dest: "{{ matrix_static_files_base_path }}/.well-known/matrix" mode: 0644 diff --git a/roles/matrix-nginx-proxy/tasks/ssl/main.yml b/roles/matrix-nginx-proxy/tasks/ssl/main.yml index 6b843c7b6..e9d270cfe 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/main.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/main.yml @@ -1,12 +1,12 @@ --- - name: Fail if using unsupported SSL certificate retrieval method - fail: + ansible.builtin.fail: msg: "The `matrix_ssl_retrieval_method` variable contains an unsupported value" when: "matrix_ssl_retrieval_method not in ['lets-encrypt', 'self-signed', 'manually-managed', 'none']" - name: Fail if using unsupported private key type - fail: + ansible.builtin.fail: msg: "The `matrix_ssl_lets_encrypt_key_type` variable contains an unsupported value" when: "matrix_ssl_lets_encrypt_key_type not in ['rsa', 'ecdsa']" @@ -14,7 +14,7 @@ # Common tasks, required by almost any method below. - name: Ensure SSL certificate paths exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0770 @@ -29,8 +29,8 @@ # Method specific tasks follow -- import_tasks: tasks/ssl/setup_ssl_lets_encrypt.yml +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_lets_encrypt.yml" -- import_tasks: tasks/ssl/setup_ssl_self_signed.yml +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_self_signed.yml" -- import_tasks: tasks/ssl/setup_ssl_manually_managed.yml +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_manually_managed.yml" diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt.yml index bfd25894a..0e5339a9a 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt.yml @@ -3,7 +3,7 @@ # This is a cleanup/migration task, because of to the new way we manage cronjobs (`cron` module) and the new script name. # This migration task can be removed some time in the future. - name: (Migration) Remove deprecated Let's Encrypt SSL certificate management files - file: + ansible.builtin.file: path: "{{ item }}" state: absent with_items: @@ -25,23 +25,23 @@ force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_ssl_lets_encrypt_certbot_docker_image_force_pull }}" - name: Obtain Let's Encrypt certificates - include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml" with_items: "{{ matrix_ssl_domains_to_obtain_certificates_for }}" loop_control: loop_var: domain_name - name: Ensure Let's Encrypt SSL renewal script installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-ssl-lets-encrypt-certificates-renew.j2" dest: "{{ matrix_local_bin_path }}/matrix-ssl-lets-encrypt-certificates-renew" mode: 0755 - name: Ensure SSL renewal systemd units installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/{{ item.name }}.j2" dest: "{{ matrix_systemd_path }}/{{ item.name }}" mode: 0644 - when: "item.applicable|bool" + when: "item.applicable | bool" with_items: "{{ matrix_ssl_renewal_systemd_units_list }}" when: "matrix_ssl_retrieval_method == 'lets-encrypt'" @@ -51,14 +51,14 @@ - block: - name: Ensure matrix-ssl-lets-encrypt-renew cronjob removed - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/{{ item.name }}" state: absent - when: "not item.applicable|bool" + when: "not item.applicable | bool" with_items: "{{ matrix_ssl_renewal_systemd_units_list }}" - name: Ensure Let's Encrypt SSL renewal script removed - file: + ansible.builtin.file: path: "{{ matrix_local_bin_path }}/matrix-ssl-lets-encrypt-certificates-renew" state: absent when: "matrix_ssl_retrieval_method != 'lets-encrypt'" diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml index 12a212579..18cae090e 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_lets_encrypt_obtain_for_domain.yml @@ -1,35 +1,35 @@ --- -- debug: +- ansible.builtin.debug: msg: "Dealing with SSL certificate retrieval for domain: {{ domain_name }}" -- set_fact: +- ansible.builtin.set_fact: domain_name_certificate_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/fullchain.pem" - name: Check if a certificate for the domain already exists - stat: + ansible.builtin.stat: path: "{{ domain_name_certificate_path }}" register: domain_name_certificate_path_stat -- set_fact: +- ansible.builtin.set_fact: domain_name_needs_cert: "{{ not domain_name_certificate_path_stat.stat.exists }}" - block: - name: Ensure required service for obtaining is started - service: + ansible.builtin.service: name: "{{ matrix_ssl_pre_obtaining_required_service_name }}" state: started register: matrix_ssl_pre_obtaining_required_service_start_result - name: Wait some time, so that the required service for obtaining can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ matrix_ssl_pre_obtaining_required_service_start_wait_time_seconds }}" - when: "matrix_ssl_pre_obtaining_required_service_start_result.changed|bool" - when: "domain_name_needs_cert|bool and matrix_ssl_pre_obtaining_required_service_name != ''" + when: "matrix_ssl_pre_obtaining_required_service_start_result.changed | bool" + when: "domain_name_needs_cert | bool and matrix_ssl_pre_obtaining_required_service_name != ''" # This will fail if there is something running on port 80 (like matrix-nginx-proxy). # We suppress the error, as we'll try another method below. - name: Attempt initial SSL certificate retrieval with standalone authenticator (directly) - shell: >- + ansible.builtin.shell: >- {{ matrix_host_command_docker }} run --rm --name=matrix-certbot @@ -51,14 +51,14 @@ --agree-tos --email={{ matrix_ssl_lets_encrypt_support_email }} -d {{ domain_name }} - when: domain_name_needs_cert|bool + when: domain_name_needs_cert | bool register: result_certbot_direct ignore_errors: true # If matrix-nginx-proxy is configured from a previous run of this playbook, # and it's running now, it may be able to proxy requests to `matrix_ssl_lets_encrypt_certbot_standalone_http_port`. - name: Attempt initial SSL certificate retrieval with standalone authenticator (via proxy) - shell: >- + ansible.builtin.shell: >- {{ matrix_host_command_docker }} run --rm --name=matrix-certbot @@ -86,7 +86,7 @@ ignore_errors: true - name: Fail if all SSL certificate retrieval attempts failed - fail: + ansible.builtin.fail: msg: | Failed to obtain a certificate directly (by listening on port 80) and also failed to obtain by relying on the server at port 80 to proxy the request. diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed.yml index 7bcd3d748..f6fc5a817 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed.yml @@ -1,7 +1,7 @@ --- - name: Verify certificates - include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml" with_items: "{{ matrix_ssl_domains_to_obtain_certificates_for }}" loop_control: loop_var: domain_name diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml index 2b5bb1f31..ab0ffa2fe 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_manually_managed_verify_for_domain.yml @@ -1,23 +1,23 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_ssl_certificate_verification_cert_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/fullchain.pem" matrix_ssl_certificate_verification_cert_key_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/privkey.pem" - name: Check if SSL certificate file exists - stat: + ansible.builtin.stat: path: "{{ matrix_ssl_certificate_verification_cert_path }}" register: matrix_ssl_certificate_verification_cert_path_stat_result -- fail: +- ansible.builtin.fail: msg: "Failed finding a certificate file (for domain `{{ domain_name }}`) at `{{ matrix_ssl_certificate_verification_cert_path }}`" when: "not matrix_ssl_certificate_verification_cert_path_stat_result.stat.exists" - name: Check if SSL certificate key file exists - stat: + ansible.builtin.stat: path: "{{ matrix_ssl_certificate_verification_cert_key_path }}" register: matrix_ssl_certificate_verification_cert_key_path_stat_result -- fail: +- ansible.builtin.fail: msg: "Failed finding a certificate key file (for domain `{{ domain_name }}`) at `{{ matrix_ssl_certificate_verification_cert_key_path }}`" when: "not matrix_ssl_certificate_verification_cert_key_path_stat_result.stat.exists" diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed.yml index 47ec40aaf..3a7f19587 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed.yml @@ -1,10 +1,10 @@ --- -- import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml" when: "matrix_ssl_retrieval_method == 'self-signed'" - name: Generate self-signed certificates - include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml" with_items: "{{ matrix_ssl_domains_to_obtain_certificates_for }}" loop_control: loop_var: domain_name diff --git a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml index ff7fa2d8b..d0b254a26 100644 --- a/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml +++ b/roles/matrix-nginx-proxy/tasks/ssl/setup_ssl_self_signed_obtain_for_domain.yml @@ -1,19 +1,19 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_ssl_certificate_csr_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/csr.csr" matrix_ssl_certificate_cert_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/fullchain.pem" matrix_ssl_certificate_cert_key_path: "{{ matrix_ssl_config_dir_path }}/live/{{ domain_name }}/privkey.pem" - name: Check if SSL certificate file exists - stat: + ansible.builtin.stat: path: "{{ matrix_ssl_certificate_cert_path }}" register: matrix_ssl_certificate_cert_path_stat_result # In order to do any sort of generation (below), we need to ensure the directory exists first - name: Ensure SSL certificate directory exists - file: - path: "{{ matrix_ssl_certificate_csr_path|dirname }}" + ansible.builtin.file: + path: "{{ matrix_ssl_certificate_csr_path | dirname }}" state: directory mode: 0750 owner: "{{ matrix_user_username }}" @@ -28,7 +28,7 @@ # # We'll do it in a more manual way. - name: Generate SSL certificate - command: | + ansible.builtin.command: | openssl req -x509 \ -sha256 \ -newkey rsa:4096 \ @@ -40,7 +40,7 @@ when: "not matrix_ssl_certificate_cert_path_stat_result.stat.exists" - name: Adjust SSL certificate file ownership - file: + ansible.builtin.file: path: "{{ item }}" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" diff --git a/roles/matrix-nginx-proxy/tasks/validate_config.yml b/roles/matrix-nginx-proxy/tasks/validate_config.yml index c6697e935..6c87a4bb2 100644 --- a/roles/matrix-nginx-proxy/tasks/validate_config.yml +++ b/roles/matrix-nginx-proxy/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: (Deprecation) Catch and report renamed settings - fail: + ansible.builtin.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 }}`). @@ -16,28 +16,28 @@ - {'old': 'matrix_nginx_proxy_reload_cron_time_definition', 'new': ''} - name: Fail on unknown matrix_ssl_retrieval_method - fail: + ansible.builtin.fail: msg: >- `matrix_ssl_retrieval_method` needs to be set to a known value. when: "matrix_ssl_retrieval_method not in ['lets-encrypt', 'self-signed', 'manually-managed', 'none']" - name: Fail on unknown matrix_nginx_proxy_ssl_config - fail: + ansible.builtin.fail: msg: >- `matrix_nginx_proxy_ssl_preset` needs to be set to a known value. when: "matrix_nginx_proxy_ssl_preset not in ['modern', 'intermediate', 'old']" - name: Fail if Basic Auth enabled for metrics, but no credentials supplied - fail: + ansible.builtin.fail: msg: | Enabling Basic Auth for metrics (`matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled`) requires: - either a username/password (provided in `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username` and `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password`) - or raw htpasswd content (provided in `matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content`) - when: "matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled|bool and (matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content == '' and (matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username == '' or matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password == ''))" + when: "matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled | bool and (matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_raw_content == '' and (matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_username == '' or matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_password == ''))" - block: - name: (Deprecation) Catch and report renamed settings - fail: + ansible.builtin.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 }}`). @@ -48,7 +48,7 @@ when: "item.old in vars" - name: Fail if required variables are undefined - fail: + ansible.builtin.fail: msg: "The `{{ item }}` variable must be defined and have a non-null value" with_items: - "matrix_ssl_lets_encrypt_support_email" @@ -60,7 +60,7 @@ when: "matrix_ssl_retrieval_method == 'lets-encrypt'" - name: (Deprecation) Catch and report old metrics usage - fail: + ansible.builtin.fail: msg: >- Your configuration contains a variable (`{{ item }}`), which refers to the old metrics collection system for Synapse, which exposed metrics on `https://matrix.DOMAIN/_synapse/metrics` and `https://matrix.DOMAIN/_synapse-worker-TYPE-ID/metrics`. diff --git a/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-synapse.conf.j2 b/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-synapse.conf.j2 index 69f13a1aa..735f45383 100644 --- a/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-synapse.conf.j2 +++ b/roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-synapse.conf.j2 @@ -1,9 +1,9 @@ #jinja2: lstrip_blocks: "True" -{% set generic_workers = matrix_nginx_proxy_synapse_workers_list|selectattr('type', 'equalto', 'generic_worker')|list %} -{% set media_repository_workers = matrix_nginx_proxy_synapse_workers_list|selectattr('type', 'equalto', 'media_repository')|list %} -{% set user_dir_workers = matrix_nginx_proxy_synapse_workers_list|selectattr('type', 'equalto', 'user_dir')|list %} -{% set frontend_proxy_workers = matrix_nginx_proxy_synapse_workers_list|selectattr('type', 'equalto', 'frontend_proxy')|list %} +{% set generic_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'generic_worker') | list %} +{% set media_repository_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'media_repository') | list %} +{% set user_dir_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'user_dir') | list %} +{% set frontend_proxy_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'frontend_proxy') | list %} {% if matrix_nginx_proxy_synapse_workers_enabled %} {% if matrix_nginx_proxy_synapse_cache_enabled %} proxy_cache_path {{ matrix_nginx_proxy_synapse_cache_path }} levels=1:2 keys_zone={{ matrix_nginx_proxy_synapse_cache_keys_zone_name }}:{{ matrix_nginx_proxy_synapse_cache_keys_zone_size }} inactive={{ matrix_nginx_proxy_synapse_cache_inactive_time }} max_size={{ matrix_nginx_proxy_synapse_cache_max_size_mb }}m; diff --git a/roles/matrix-nginx-proxy/vars/main.yml b/roles/matrix-nginx-proxy/vars/main.yml index 5c51fe5bd..1a9ed929c 100644 --- a/roles/matrix-nginx-proxy/vars/main.yml +++ b/roles/matrix-nginx-proxy/vars/main.yml @@ -11,8 +11,8 @@ matrix_ssl_renewal_systemd_units_list: applicable: "{{ matrix_ssl_retrieval_method == 'lets-encrypt' }}" enableable: true - name: matrix-ssl-nginx-proxy-reload.service - applicable: "{{ matrix_ssl_retrieval_method == 'lets-encrypt' and matrix_nginx_proxy_enabled|bool }}" + applicable: "{{ matrix_ssl_retrieval_method == 'lets-encrypt' and matrix_nginx_proxy_enabled | bool }}" enableable: false - name: matrix-ssl-nginx-proxy-reload.timer - applicable: "{{ matrix_ssl_retrieval_method == 'lets-encrypt' and matrix_nginx_proxy_enabled|bool }}" + applicable: "{{ matrix_ssl_retrieval_method == 'lets-encrypt' and matrix_nginx_proxy_enabled | bool }}" enableable: true diff --git a/roles/matrix-ntfy/defaults/main.yml b/roles/matrix-ntfy/defaults/main.yml index 96e9e69df..66bc5be45 100644 --- a/roles/matrix-ntfy/defaults/main.yml +++ b/roles/matrix-ntfy/defaults/main.yml @@ -41,8 +41,8 @@ matrix_ntfy_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_ntfy_configuration_yaml`. -matrix_ntfy_configuration_extension: "{{ matrix_ntfy_configuration_extension_yaml|from_yaml if matrix_ntfy_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_ntfy_configuration_extension: "{{ matrix_ntfy_configuration_extension_yaml | from_yaml if matrix_ntfy_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final ntfy configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_ntfy_configuration_yaml`. -matrix_ntfy_configuration: "{{ matrix_ntfy_configuration_yaml|from_yaml|combine(matrix_ntfy_configuration_extension, recursive=True) }}" +matrix_ntfy_configuration: "{{ matrix_ntfy_configuration_yaml | from_yaml | combine(matrix_ntfy_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-ntfy/tasks/init.yml b/roles/matrix-ntfy/tasks/init.yml index e2622655e..6222ada0c 100644 --- a/roles/matrix-ntfy/tasks/init.yml +++ b/roles/matrix-ntfy/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-ntfy.service'] }}" - when: matrix_ntfy_enabled|bool + when: matrix_ntfy_enabled | bool diff --git a/roles/matrix-ntfy/tasks/main.yml b/roles/matrix-ntfy/tasks/main.yml index 5dd0d172a..200d38c4a 100644 --- a/roles/matrix-ntfy/tasks/main.yml +++ b/roles/matrix-ntfy/tasks/main.yml @@ -1,24 +1,24 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_ntfy_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_ntfy_enabled | bool" tags: - setup-all - setup-ntfy -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_ntfy_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_ntfy_enabled | bool" tags: - setup-all - setup-ntfy -- import_tasks: "{{ role_path }}/tasks/self_check.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check.yml" delegate_to: 127.0.0.1 become: false - when: "run_self_check|bool and matrix_ntfy_enabled|bool" + when: "run_self_check | bool and matrix_ntfy_enabled | bool" tags: - self-check diff --git a/roles/matrix-ntfy/tasks/self_check.yml b/roles/matrix-ntfy/tasks/self_check.yml index e91047341..02529f35e 100644 --- a/roles/matrix-ntfy/tasks/self_check.yml +++ b/roles/matrix-ntfy/tasks/self_check.yml @@ -3,11 +3,11 @@ # Query an arbitrary ntfy topic using ntfy's UnifiedPush topic name syntax. # Expect an empty response (because we query 'since=1s'). -- set_fact: +- ansible.builtin.set_fact: matrix_ntfy_url_endpoint_public: "{{ matrix_ntfy_base_url }}/upSELFCHECK123/json?poll=1&since=1s" - name: Check ntfy - uri: + ansible.builtin.uri: url: "{{ matrix_ntfy_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_ntfy_self_check_validate_certificates }}" @@ -16,10 +16,10 @@ ignore_errors: true - name: Fail if ntfy not working - fail: + ansible.builtin.fail: msg: "Failed checking ntfy is up at `{{ matrix_server_fqn_ntfy }}` (checked endpoint: `{{ matrix_ntfy_url_endpoint_public }}`). Is ntfy running? Is port 443 open in your firewall? Full error: {{ matrix_ntfy_self_check_result }}" when: "matrix_ntfy_self_check_result.failed" - name: Report working ntfy - debug: + ansible.builtin.debug: msg: "ntfy at `{{ matrix_server_fqn_ntfy }}` is working (checked endpoint: `{{ matrix_ntfy_url_endpoint_public }}`)" diff --git a/roles/matrix-ntfy/tasks/setup_install.yml b/roles/matrix-ntfy/tasks/setup_install.yml index 461d31763..9afabc4cd 100644 --- a/roles/matrix-ntfy/tasks/setup_install.yml +++ b/roles/matrix-ntfy/tasks/setup_install.yml @@ -12,7 +12,7 @@ until: result is not failed - name: Ensure matrix-ntfy paths exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -24,21 +24,21 @@ - "{{ matrix_ntfy_data_path }}" - name: Ensure matrix-ntfy config installed - copy: - content: "{{ matrix_ntfy_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_ntfy_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_ntfy_config_dir_path }}/server.yml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-ntfy.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-ntfy.service.j2" dest: "{{ matrix_systemd_path }}/matrix-ntfy.service" mode: 0644 register: matrix_ntfy_systemd_service_result - name: Ensure systemd reloaded after matrix-ntfy.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_ntfy_systemd_service_result.changed" diff --git a/roles/matrix-ntfy/tasks/setup_uninstall.yml b/roles/matrix-ntfy/tasks/setup_uninstall.yml index e63caa9a7..f6d9cc8aa 100644 --- a/roles/matrix-ntfy/tasks/setup_uninstall.yml +++ b/roles/matrix-ntfy/tasks/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-ntfy service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-ntfy.service" register: matrix_ntfy_service_stat - name: Ensure matrix-ntfy is stopped - service: + ansible.builtin.service: name: matrix-ntfy state: stopped enabled: false @@ -15,18 +15,18 @@ when: "matrix_ntfy_service_stat.stat.exists" - name: Ensure matrix-ntfy.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-ntfy.service" state: absent when: "matrix_ntfy_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-ntfy.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_ntfy_service_stat.stat.exists" - name: Ensure matrix-ntfy path doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_ntfy_base_path }}" state: absent diff --git a/roles/matrix-postgres-backup/tasks/init.yml b/roles/matrix-postgres-backup/tasks/init.yml index f74cea06e..5ece870a4 100644 --- a/roles/matrix-postgres-backup/tasks/init.yml +++ b/roles/matrix-postgres-backup/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-postgres-backup.service'] }}" - when: matrix_postgres_backup_enabled|bool + when: matrix_postgres_backup_enabled | bool diff --git a/roles/matrix-postgres-backup/tasks/main.yml b/roles/matrix-postgres-backup/tasks/main.yml index 19e3db5b8..1403fa5b2 100644 --- a/roles/matrix-postgres-backup/tasks/main.yml +++ b/roles/matrix-postgres-backup/tasks/main.yml @@ -1,17 +1,17 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_postgres_backup_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_postgres_backup_enabled | bool" tags: - setup-all - setup-postgres-backup -- import_tasks: "{{ role_path }}/tasks/setup_postgres_backup.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_postgres_backup.yml" + when: run_setup | bool tags: - setup-all - setup-postgres-backup diff --git a/roles/matrix-postgres-backup/tasks/setup_postgres_backup.yml b/roles/matrix-postgres-backup/tasks/setup_postgres_backup.yml index 733410335..a62467572 100644 --- a/roles/matrix-postgres-backup/tasks/setup_postgres_backup.yml +++ b/roles/matrix-postgres-backup/tasks/setup_postgres_backup.yml @@ -1,18 +1,20 @@ --- # -# Tasks related to setting up an internal postgres server +# Tasks related to setting up postgres backup # -- import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml" - when: 'matrix_postgres_backup_enabled|bool and matrix_postgres_backup_postgres_data_path != ""' +- ansible.builtin.import_role: + name: matrix-postgres + tasks_from: detect_existing_postgres_version + when: 'matrix_postgres_backup_enabled | bool and matrix_postgres_backup_postgres_data_path != ""' # If we have found an existing version (installed from before), we use its corresponding Docker image. # If not, we install using the latest Postgres. # # Upgrading is supposed to be performed separately and explicitly (see `upgrade_postgres.yml`). -- set_fact: - matrix_postgres_backup_docker_image_to_use: "{{ matrix_postgres_backup_docker_image_latest if matrix_postgres_backup_detected_version_corresponding_docker_image|default('') == '' else matrix_postgres_backup_detected_version_corresponding_docker_image }}" - when: matrix_postgres_backup_enabled|bool +- ansible.builtin.set_fact: + matrix_postgres_backup_docker_image_to_use: "{{ matrix_postgres_backup_docker_image_latest if matrix_postgres_backup_detected_version_corresponding_docker_image | default('') == '' else matrix_postgres_backup_detected_version_corresponding_docker_image }}" + when: matrix_postgres_backup_enabled | bool - name: Ensure postgres backup Docker image is pulled docker_image: @@ -20,14 +22,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_postgres_backup_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_postgres_backup_docker_image_force_pull }}" - when: matrix_postgres_backup_enabled|bool + when: matrix_postgres_backup_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Postgres backup paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0700 @@ -35,10 +37,10 @@ group: "{{ matrix_user_groupname }}" with_items: - "{{ matrix_postgres_backup_path }}" - when: matrix_postgres_backup_enabled|bool + when: matrix_postgres_backup_enabled | bool - name: Ensure Postgres environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/{{ item }}.j2" dest: "{{ matrix_postgres_backup_path }}/{{ item }}" owner: "{{ matrix_user_username }}" @@ -46,65 +48,65 @@ mode: 0640 with_items: - "env-postgres-backup" - when: matrix_postgres_backup_enabled|bool + when: matrix_postgres_backup_enabled | bool - name: Ensure matrix-postgres-backup.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-postgres-backup.service.j2" dest: "{{ matrix_systemd_path }}/matrix-postgres-backup.service" mode: 0644 register: matrix_postgres_backup_systemd_service_result - when: matrix_postgres_backup_enabled|bool + when: matrix_postgres_backup_enabled | bool - name: Ensure systemd reloaded after matrix-postgres-backup.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_postgres_backup_enabled|bool and matrix_postgres_backup_systemd_service_result.changed" + when: "matrix_postgres_backup_enabled | bool and matrix_postgres_backup_systemd_service_result.changed" # -# Tasks related to getting rid of the internal postgres backup server (if it was previously enabled) +# Tasks related to getting rid of postgres backup (if it was previously enabled) # - name: Check existence of matrix-postgres-backup service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-postgres-backup.service" register: matrix_postgres_backup_service_stat - when: "not matrix_postgres_backup_enabled|bool" + when: "not matrix_postgres_backup_enabled | bool" - name: Ensure matrix-postgres-backup is stopped - service: + ansible.builtin.service: name: matrix-postgres-backup state: stopped enabled: false daemon_reload: true - when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists" + when: "not matrix_postgres_backup_enabled | bool and matrix_postgres_backup_service_stat.stat.exists" - name: Ensure matrix-postgres-backup.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-postgres-backup.service" state: absent - when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists" + when: "not matrix_postgres_backup_enabled | bool and matrix_postgres_backup_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-postgres-backup.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_service_stat.stat.exists" + when: "not matrix_postgres_backup_enabled | bool and matrix_postgres_backup_service_stat.stat.exists" - name: Check existence of matrix-postgres-backup backup path - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_backup_path }}" register: matrix_postgres_backup_path_stat - when: "not matrix_postgres_backup_enabled|bool" + when: "not matrix_postgres_backup_enabled | bool" # We just want to notify the user. Deleting data is too destructive. - name: Inject warning if matrix-postgres backup data remains - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: You are not using the local backup service to backup the PostgreSQL database, but some old data remains from before in `{{ matrix_postgres_backup_path }}`. Feel free to delete it." ] }} - when: "not matrix_postgres_backup_enabled|bool and matrix_postgres_backup_path_stat.stat.exists" + when: "not matrix_postgres_backup_enabled | bool and matrix_postgres_backup_path_stat.stat.exists" diff --git a/roles/matrix-postgres-backup/tasks/util/detect_existing_postgres_version.yml b/roles/matrix-postgres-backup/tasks/util/detect_existing_postgres_version.yml index 10828cc7a..877e5934d 100644 --- a/roles/matrix-postgres-backup/tasks/util/detect_existing_postgres_version.yml +++ b/roles/matrix-postgres-backup/tasks/util/detect_existing_postgres_version.yml @@ -4,58 +4,58 @@ # If there is, it also tries to detect the Docker image that corresponds to that version. - name: Initialize Postgres version determination variables (default to empty) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detection_pg_version_path: "{{ matrix_postgres_data_path }}/PG_VERSION" matrix_postgres_backup_detected_existing: false matrix_postgres_backup_detected_version: "" matrix_postgres_backup_detected_version_corresponding_docker_image: "" - name: Determine existing Postgres version (check PG_VERSION file) - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_backup_detection_pg_version_path }}" register: result_pg_version_stat -- set_fact: +- ansible.builtin.set_fact: matrix_postgres_backup_detected_existing: true when: "result_pg_version_stat.stat.exists" - name: Determine existing Postgres version (read PG_VERSION file) - slurp: + ansible.builtin.slurp: src: "{{ matrix_postgres_backup_detection_pg_version_path }}" register: result_pg_version - when: matrix_postgres_backup_detected_existing|bool + when: matrix_postgres_backup_detected_existing | bool - name: Determine existing Postgres version (make sense of PG_VERSION file) - set_fact: - matrix_postgres_backup_detected_version: "{{ result_pg_version['content']|b64decode|replace('\n', '') }}" - when: matrix_postgres_backup_detected_existing|bool + ansible.builtin.set_fact: + matrix_postgres_backup_detected_version: "{{ result_pg_version['content'] | b64decode | replace('\n', '') }}" + when: matrix_postgres_backup_detected_existing | bool - name: Determine corresponding Docker image to detected version (assume default of latest) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_latest }}" when: "matrix_postgres_backup_detected_version != ''" - name: Determine corresponding Docker image to detected version (use 9.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_v9 }}" when: "matrix_postgres_backup_detected_version.startswith('9.')" - name: Determine corresponding Docker image to detected version (use 10.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_v10 }}" when: "matrix_postgres_backup_detected_version == '10' or matrix_postgres_backup_detected_version.startswith('10.')" - name: Determine corresponding Docker image to detected version (use 11.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_v11 }}" when: "matrix_postgres_backup_detected_version == '11' or matrix_postgres_backup_detected_version.startswith('11.')" - name: Determine corresponding Docker image to detected version (use 12.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_v12 }}" when: "matrix_postgres_backup_detected_version == '12' or matrix_postgres_backup_detected_version.startswith('12.')" - name: Determine corresponding Docker image to detected version (use 13.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_backup_detected_version_corresponding_docker_image: "{{ matrix_postgres_backup_docker_image_v13 }}" when: "matrix_postgres_backup_detected_version == '13' or matrix_postgres_backup_detected_version.startswith('13.')" diff --git a/roles/matrix-postgres-backup/tasks/validate_config.yml b/roles/matrix-postgres-backup/tasks/validate_config.yml index fda9b9193..8a2ddb5ad 100644 --- a/roles/matrix-postgres-backup/tasks/validate_config.yml +++ b/roles/matrix-postgres-backup/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required Postgres settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" diff --git a/roles/matrix-postgres/defaults/main.yml b/roles/matrix-postgres/defaults/main.yml index 3a4d73be1..39481f2e7 100644 --- a/roles/matrix-postgres/defaults/main.yml +++ b/roles/matrix-postgres/defaults/main.yml @@ -78,7 +78,7 @@ matrix_postgres_import_roles_to_ignore: [matrix_postgres_connection_username] # which is unsupported by default by newer Postgres versions (v14+). # When users are created and passwords are set by the playbook, they end up hashed as `scram-sha-256` on Postgres v14+. # If an md5-hashed password is restored on top, Postgres v14+ will refuse to authenticate users with it by default. -matrix_postgres_import_roles_ignore_regex: "^(CREATE|ALTER) ROLE ({{ matrix_postgres_import_roles_to_ignore|join('|') }})(;| WITH)" +matrix_postgres_import_roles_ignore_regex: "^(CREATE|ALTER) ROLE ({{ matrix_postgres_import_roles_to_ignore | join('|') }})(;| WITH)" # noqa var-spacing # A list of databases to avoid creating when importing (or upgrading) the database. # If a dump file contains the databases and they've also been created beforehand (see `matrix_postgres_additional_databases`), @@ -86,7 +86,7 @@ matrix_postgres_import_roles_ignore_regex: "^(CREATE|ALTER) ROLE ({{ matrix_post # We either need to not create them or to ignore the `CREATE DATABASE` statements in the dump. matrix_postgres_import_databases_to_ignore: [matrix_postgres_db_name] -matrix_postgres_import_databases_ignore_regex: "^CREATE DATABASE ({{ matrix_postgres_import_databases_to_ignore|join('|') }})\\s" +matrix_postgres_import_databases_ignore_regex: "^CREATE DATABASE ({{ matrix_postgres_import_databases_to_ignore | join('|') }})\\s" # noqa var-spacing # The number of seconds to wait after starting `matrix-postgres.service` # and before trying to run queries for creating additional databases/users against it. diff --git a/roles/matrix-postgres/tasks/util/detect_existing_postgres_version.yml b/roles/matrix-postgres/tasks/detect_existing_postgres_version.yml similarity index 80% rename from roles/matrix-postgres/tasks/util/detect_existing_postgres_version.yml rename to roles/matrix-postgres/tasks/detect_existing_postgres_version.yml index a7e94a0c3..4f4e5e9a7 100644 --- a/roles/matrix-postgres/tasks/util/detect_existing_postgres_version.yml +++ b/roles/matrix-postgres/tasks/detect_existing_postgres_version.yml @@ -2,60 +2,63 @@ # This utility aims to determine if there is some existing Postgres version in use or not. # If there is, it also tries to detect the Docker image that corresponds to that version. +# +# This utility is intentionally not in `tasks/util`, because if it were, it wouldn't be possible +# to include it in other roles via the import_role module: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_role_module.html - name: Initialize Postgres version determination variables (default to empty) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detection_pg_version_path: "{{ matrix_postgres_data_path }}/PG_VERSION" matrix_postgres_detected_existing: false matrix_postgres_detected_version: "" matrix_postgres_detected_version_corresponding_docker_image: "" - name: Determine existing Postgres version (check PG_VERSION file) - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_detection_pg_version_path }}" register: result_pg_version_stat -- set_fact: +- ansible.builtin.set_fact: matrix_postgres_detected_existing: true when: "result_pg_version_stat.stat.exists" - name: Determine existing Postgres version (read PG_VERSION file) - slurp: + ansible.builtin.slurp: src: "{{ matrix_postgres_detection_pg_version_path }}" register: result_pg_version - when: matrix_postgres_detected_existing|bool + when: matrix_postgres_detected_existing | bool - name: Determine existing Postgres version (make sense of PG_VERSION file) - set_fact: - matrix_postgres_detected_version: "{{ result_pg_version['content']|b64decode|replace('\n', '') }}" - when: matrix_postgres_detected_existing|bool + ansible.builtin.set_fact: + matrix_postgres_detected_version: "{{ result_pg_version['content'] | b64decode | replace('\n', '') }}" + when: matrix_postgres_detected_existing | bool - name: Determine corresponding Docker image to detected version (assume default of latest) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_latest }}" when: "matrix_postgres_detected_version != ''" - name: Determine corresponding Docker image to detected version (use 9.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v9 }}" when: "matrix_postgres_detected_version.startswith('9.')" - name: Determine corresponding Docker image to detected version (use 10.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v10 }}" when: "matrix_postgres_detected_version == '10' or matrix_postgres_detected_version.startswith('10.')" - name: Determine corresponding Docker image to detected version (use 11.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v11 }}" when: "matrix_postgres_detected_version == '11' or matrix_postgres_detected_version.startswith('11.')" - name: Determine corresponding Docker image to detected version (use 12.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v12 }}" when: "matrix_postgres_detected_version == '12' or matrix_postgres_detected_version.startswith('12.')" - name: Determine corresponding Docker image to detected version (use 13.x, if detected) - set_fact: + ansible.builtin.set_fact: matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v13 }}" when: "matrix_postgres_detected_version == '13' or matrix_postgres_detected_version.startswith('13.')" diff --git a/roles/matrix-postgres/tasks/import_generic_sqlite_db.yml b/roles/matrix-postgres/tasks/import_generic_sqlite_db.yml index 2a673ee3f..671cb33f5 100644 --- a/roles/matrix-postgres/tasks/import_generic_sqlite_db.yml +++ b/roles/matrix-postgres/tasks/import_generic_sqlite_db.yml @@ -3,22 +3,22 @@ # Pre-checks - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `sqlite_database_path` variable needs to be provided to this playbook, via --extra-vars" when: "sqlite_database_path is not defined or sqlite_database_path.startswith('<')" - name: Check if the provided SQLite database file exists - stat: + ansible.builtin.stat: path: "{{ sqlite_database_path }}" register: sqlite_database_path_stat_result - name: Fail if provided SQLite database file doesn't exist - fail: + ansible.builtin.fail: msg: "File cannot be found on the server at {{ sqlite_database_path }}" when: "not sqlite_database_path_stat_result.stat.exists" @@ -27,16 +27,16 @@ - block: - name: Fail if postgres_connection_string_variable_name points to an undefined variable - fail: msg="postgres_connection_string_variable_name is defined, but there is no variable with the name `{{ postgres_connection_string_variable_name }}`" + ansible.builtin.fail: msg="postgres_connection_string_variable_name is defined, but there is no variable with the name `{{ postgres_connection_string_variable_name }}`" when: "postgres_connection_string_variable_name not in vars" - name: Get Postgres connection string from variable - set_fact: + ansible.builtin.set_fact: postgres_db_connection_string: "{{ lookup('vars', postgres_connection_string_variable_name) }}" when: 'postgres_connection_string_variable_name is defined' - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: >- Either a `postgres_db_connection_string` variable or a `postgres_connection_string_variable_name` needs to be provided to this playbook, via `--extra-vars`. Example: `--extra-vars="postgres_db_connection_string=postgresql://username:password@localhost:/database_name"` or `--extra-vars="postgres_connection_string_variable_name=matrix_appservice_discord_database_connString"` @@ -46,29 +46,29 @@ # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" # Actual import work - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true register: matrix_postgres_service_start_result - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false - when: "matrix_postgres_service_start_result.changed|bool" + when: "matrix_postgres_service_start_result.changed | bool" - name: Import SQLite database from {{ sqlite_database_path }} into Postgres - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -80,16 +80,20 @@ {{ matrix_postgres_pgloader_docker_image }} -c 'pgloader /in.db {{ postgres_db_connection_string }}' + register: matrix_postgres_import_generic_sqlite_db_import_result + changed_when: matrix_postgres_import_generic_sqlite_db_import_result.rc == 0 - name: Archive SQLite database ({{ sqlite_database_path }} -> {{ sqlite_database_path }}.backup) - command: + ansible.builtin.command: cmd: "mv {{ sqlite_database_path }} {{ sqlite_database_path }}.backup" + register: matrix_postgres_import_generic_sqlite_db_move_result + changed_when: matrix_postgres_import_generic_sqlite_db_move_result.rc == 0 - name: Inject result - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your SQLite database file has been imported into Postgres. The original file has been moved from `{{ sqlite_database_path }}` to `{{ sqlite_database_path }}.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete this file." diff --git a/roles/matrix-postgres/tasks/import_postgres.yml b/roles/matrix-postgres/tasks/import_postgres.yml index 948c4b3aa..53d67436b 100644 --- a/roles/matrix-postgres/tasks/import_postgres.yml +++ b/roles/matrix-postgres/tasks/import_postgres.yml @@ -3,22 +3,22 @@ # Pre-checks - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `server_path_postgres_dump` variable needs to be provided to this playbook, via --extra-vars" when: "server_path_postgres_dump is not defined or server_path_postgres_dump.startswith('<')" - name: Check if the provided Postgres dump file exists - stat: + ansible.builtin.stat: path: "{{ server_path_postgres_dump }}" register: result_server_path_postgres_dump_stat - name: Fail if provided Postgres dump file doesn't exists - fail: + ansible.builtin.fail: msg: "File cannot be found on the server at {{ server_path_postgres_dump }}" when: "not result_server_path_postgres_dump_stat.stat.exists" @@ -26,49 +26,49 @@ # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" - name: Set postgres_import_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_import_wait_time: "{{ 7 * 86400 }}" - when: "postgres_import_wait_time|default('') == ''" + when: "postgres_import_wait_time | default('') == ''" # By default, we connect and import into the main (`matrix`) database. # Single-database dumps for Synapse may wish to import into `synapse` instead. - name: Set postgres_default_import_database, if not provided - set_fact: + ansible.builtin.set_fact: postgres_default_import_database: "{{ matrix_postgres_db_name }}" - when: "postgres_default_import_database|default('') == ''" + when: "postgres_default_import_database | default('') == ''" # Actual import work - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false -- import_tasks: tasks/util/detect_existing_postgres_version.yml +- ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml - name: Abort, if no existing Postgres version detected - fail: + ansible.builtin.fail: msg: "Could not find existing Postgres installation" - when: "not matrix_postgres_detected_existing|bool" + when: "not matrix_postgres_detected_existing | bool" # Starting the database container had automatically created the default # role (`matrix_postgres_connection_username`) and database (`matrix_postgres_db_name`). # The dump most likely contains those same entries and would try to re-create them, leading to errors. # We need to skip over those lines. - name: Generate Postgres database import command - set_fact: + ansible.builtin.set_fact: matrix_postgres_import_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-postgres-import --log-driver=none @@ -76,14 +76,16 @@ --cap-drop=ALL --network={{ matrix_docker_network }} --env-file={{ matrix_postgres_base_path }}/env-postgres-psql - --mount type=bind,src={{ server_path_postgres_dump }},dst=/{{ server_path_postgres_dump|basename }},ro + --mount type=bind,src={{ server_path_postgres_dump }},dst=/{{ server_path_postgres_dump | basename }},ro --entrypoint=/bin/sh {{ matrix_postgres_docker_image_latest }} - -c "cat /{{ server_path_postgres_dump|basename }} | + -c "cat /{{ server_path_postgres_dump | basename }} | {{ 'gunzip |' if server_path_postgres_dump.endswith('.gz') else '' }} grep -vE '{{ matrix_postgres_import_roles_ignore_regex }}' | grep -vE '{{ matrix_postgres_import_databases_ignore_regex }}' | psql -v ON_ERROR_STOP=1 -h matrix-postgres --dbname={{ postgres_default_import_database }}" + tags: + - skip_ansible_lint # This is a hack. # See: https://ansibledaily.com/print-to-standard-output-without-escaping/ @@ -91,7 +93,7 @@ # We want to run `debug: msg=".."`, but that dumps it as JSON and escapes double quotes within it, # which ruins the command (`matrix_postgres_import_command`) - name: Note about Postgres importing alternative - set_fact: + ansible.builtin.set_fact: dummy: true with_items: - >- @@ -101,6 +103,9 @@ and manually run the above import command directly on the server. - name: Perform Postgres database import - command: "{{ matrix_postgres_import_command }}" + ansible.builtin.command: + cmd: "{{ matrix_postgres_import_command }}" async: "{{ postgres_import_wait_time }}" poll: 10 + register: matrix_postgres_import_postgres_command_result + changed_when: matrix_postgres_import_postgres_command_result.rc == 0 diff --git a/roles/matrix-postgres/tasks/import_synapse_sqlite_db.yml b/roles/matrix-postgres/tasks/import_synapse_sqlite_db.yml index 2dafba591..a459b6e1d 100644 --- a/roles/matrix-postgres/tasks/import_synapse_sqlite_db.yml +++ b/roles/matrix-postgres/tasks/import_synapse_sqlite_db.yml @@ -3,22 +3,22 @@ # Pre-checks - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `server_path_homeserver_db` variable needs to be provided to this playbook, via --extra-vars" when: "server_path_homeserver_db is not defined or server_path_homeserver_db.startswith('<')" - name: Check if the provided SQLite homeserver.db file exists - stat: + ansible.builtin.stat: path: "{{ server_path_homeserver_db }}" register: result_server_path_homeserver_db_stat - name: Fail if provided SQLite homeserver.db file doesn't exist - fail: + ansible.builtin.fail: msg: "File cannot be found on the server at {{ server_path_homeserver_db }}" when: "not result_server_path_homeserver_db_stat.stat.exists" @@ -26,26 +26,26 @@ # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" # Actual import work - name: Ensure matrix-postgres is stopped - service: + ansible.builtin.service: name: matrix-postgres state: stopped daemon_reload: true - name: Ensure postgres data is wiped out - file: + ansible.builtin.file: path: "{{ matrix_postgres_data_path }}" state: absent - name: Ensure postgres data path exists - file: + ansible.builtin.file: path: "{{ matrix_postgres_data_path }}" state: directory mode: 0700 @@ -53,13 +53,13 @@ group: "{{ matrix_user_groupname }}" - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: restarted daemon_reload: true - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false @@ -70,17 +70,20 @@ # Also, some old `docker_container` versions were buggy and would leave containers behind # on failure, which we had to work around to allow retries (by re-running the playbook). - name: Import SQLite database into Postgres - command: | - docker run - --rm - --name=matrix-synapse-migrate - --log-driver=none - --user={{ matrix_user_uid }}:{{ matrix_user_gid }} - --cap-drop=ALL - --network={{ matrix_docker_network }} - --entrypoint=python - --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data - --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/matrix-media-store-parent/media-store - --mount type=bind,src={{ server_path_homeserver_db }},dst=/{{ server_path_homeserver_db|basename }} - {{ matrix_synapse_docker_image }} - /usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db|basename }} --postgres-config /data/homeserver.yaml + ansible.builtin.command: + cmd: | + docker run + --rm + --name=matrix-synapse-migrate + --log-driver=none + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} + --cap-drop=ALL + --network={{ matrix_docker_network }} + --entrypoint=python + --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data + --mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/matrix-media-store-parent/media-store + --mount type=bind,src={{ server_path_homeserver_db }},dst=/{{ server_path_homeserver_db | basename }} + {{ matrix_synapse_docker_image }} + /usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db | basename }} --postgres-config /data/homeserver.yaml + register: matrix_postgres_import_synapse_sqlite_db_result + changed_when: matrix_postgres_import_synapse_sqlite_db_result.rc == 0 diff --git a/roles/matrix-postgres/tasks/init.yml b/roles/matrix-postgres/tasks/init.yml index e5ebd9c56..659380f10 100644 --- a/roles/matrix-postgres/tasks/init.yml +++ b/roles/matrix-postgres/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-postgres.service'] }}" - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool diff --git a/roles/matrix-postgres/tasks/main.yml b/roles/matrix-postgres/tasks/main.yml index 79890417f..8e21b3c63 100644 --- a/roles/matrix-postgres/tasks/main.yml +++ b/roles/matrix-postgres/tasks/main.yml @@ -1,45 +1,45 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_postgres_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_postgres_enabled | bool" tags: - setup-all - setup-postgres -- import_tasks: "{{ role_path }}/tasks/setup_postgres.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_postgres.yml" + when: run_setup | bool tags: - setup-all - setup-postgres -- import_tasks: "{{ role_path }}/tasks/import_postgres.yml" - when: run_postgres_import|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/import_postgres.yml" + when: run_postgres_import | bool tags: - import-postgres # The `run_postgres_import_sqlite_db` variable had better be renamed to be consistent, # but that's a breaking change which may cause trouble for people. -- import_tasks: "{{ role_path }}/tasks/import_synapse_sqlite_db.yml" - when: run_postgres_import_sqlite_db|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/import_synapse_sqlite_db.yml" + when: run_postgres_import_sqlite_db | bool tags: - import-synapse-sqlite-db # Perhaps we need a new variable here, instead of `run_postgres_import_sqlite_db`. -- import_tasks: "{{ role_path }}/tasks/import_generic_sqlite_db.yml" - when: run_postgres_import_sqlite_db|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/import_generic_sqlite_db.yml" + when: run_postgres_import_sqlite_db | bool tags: - import-generic-sqlite-db -- import_tasks: "{{ role_path }}/tasks/upgrade_postgres.yml" - when: run_postgres_upgrade|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/upgrade_postgres.yml" + when: run_postgres_upgrade | bool tags: - upgrade-postgres -- import_tasks: "{{ role_path }}/tasks/run_vacuum.yml" - when: run_postgres_vacuum|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/run_vacuum.yml" + when: run_postgres_vacuum | bool tags: - run-postgres-vacuum diff --git a/roles/matrix-postgres/tasks/util/migrate_db_to_postgres.yml b/roles/matrix-postgres/tasks/migrate_db_to_postgres.yml similarity index 83% rename from roles/matrix-postgres/tasks/util/migrate_db_to_postgres.yml rename to roles/matrix-postgres/tasks/migrate_db_to_postgres.yml index 90f73dba8..be967d684 100644 --- a/roles/matrix-postgres/tasks/util/migrate_db_to_postgres.yml +++ b/roles/matrix-postgres/tasks/migrate_db_to_postgres.yml @@ -1,17 +1,17 @@ --- - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Fail if util called incorrectly (missing matrix_postgres_db_migration_request) - fail: + ansible.builtin.fail: msg: "The `matrix_postgres_db_migration_request` variable needs to be provided to this util." when: "matrix_postgres_db_migration_request is not defined" - name: Fail if util called incorrectly (invalid matrix_postgres_db_migration_request) - fail: + ansible.builtin.fail: msg: "The `matrix_postgres_db_migration_request` variable needs to contain `{{ item }}`." with_items: - src @@ -22,18 +22,18 @@ when: "item not in matrix_postgres_db_migration_request" - name: Check if the provided source database file exists - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_db_migration_request.src }}" register: matrix_postgres_db_migration_request_src_stat_result - name: Fail if provided source database file doesn't exist - fail: + ansible.builtin.fail: msg: "File cannot be found on the server at {{ matrix_postgres_db_migration_request.src }}" when: "not matrix_postgres_db_migration_request_src_stat_result.stat.exists" - block: - name: Ensure pgloader repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_postgres_pgloader_container_image_self_build_repo }}" dest: "{{ matrix_postgres_pgloader_container_image_self_build_src_path }}" version: "{{ matrix_postgres_pgloader_container_image_self_build_repo_branch }}" @@ -49,7 +49,7 @@ # # Although we're not using the dimitri/pgloader image, the one we're using suffers from the same problem. - name: Switch pgloader base image from Debian stable (likely 10.x/Buster) to Bullseye - lineinfile: + ansible.builtin.lineinfile: path: "{{ matrix_postgres_pgloader_container_image_self_build_src_path }}/Dockerfile" regexp: "{{ item.match }}" line: "{{ item.replace }}" @@ -69,7 +69,7 @@ dockerfile: Dockerfile path: "{{ matrix_postgres_pgloader_container_image_self_build_src_path }}" pull: true - when: "matrix_postgres_pgloader_container_image_self_build|bool" + when: "matrix_postgres_pgloader_container_image_self_build | bool" - name: Ensure pgloader Docker image is pulled docker_image: @@ -82,26 +82,26 @@ # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" # Actual import work # matrix-postgres is most likely started already - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true register: matrix_postgres_service_start_result - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false - when: "matrix_postgres_service_start_result.changed|bool" + when: "matrix_postgres_service_start_result.changed | bool" # We only stop services here, leaving it to the caller to start them later. # @@ -112,14 +112,14 @@ # However, we don't do it, because it's simpler having it here, and it also gets to happen only if we'll be doing an import. # If we bailed out (somewhere above), nothing would have gotten stopped. It's nice to leave this running in such cases. - name: Ensure systemd services blocking the database import are stopped - service: + ansible.builtin.service: name: "{{ item }}" state: stopped failed_when: false with_items: "{{ matrix_postgres_db_migration_request.systemd_services_to_stop }}" - name: Import {{ matrix_postgres_db_migration_request.engine_old }} database from {{ matrix_postgres_db_migration_request.src }} into Postgres - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -130,18 +130,20 @@ --entrypoint=/bin/sh {{ matrix_postgres_pgloader_docker_image }} -c - 'pgloader {{ matrix_postgres_db_migration_request.pgloader_options|default([])|join(' ') }} /in.db {{ matrix_postgres_db_migration_request.dst }}' + 'pgloader {{ matrix_postgres_db_migration_request.pgloader_options | default([]) | join(' ') }} /in.db {{ matrix_postgres_db_migration_request.dst }}' + register: matrix_postgres_migrate_db_to_postgres_import_result + changed_when: matrix_postgres_migrate_db_to_postgres_import_result.rc == 0 - block: - # We can't use `{{ role_path }}` here, neither with `import_tasks`, nor with `include_tasks`, - # because it refers to the role that included this util, and not to the role this file belongs to. - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/detect_existing_postgres_version.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: detect_existing_postgres_version - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_docker_image_to_use: "{{ matrix_postgres_docker_image_latest if matrix_postgres_detected_version_corresponding_docker_image == '' else matrix_postgres_detected_version_corresponding_docker_image }}" - name: Execute additional Postgres SQL migration statements - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -152,18 +154,22 @@ {{ matrix_postgres_docker_image_to_use }} psql --host=matrix-postgres --dbname={{ matrix_postgres_db_migration_request.additional_psql_statements_db_name }} --command='{{ item }}' with_items: "{{ matrix_postgres_db_migration_request.additional_psql_statements_list }}" + register: matrix_postgres_migrate_db_to_postgres_additional_queries_result + changed_when: matrix_postgres_migrate_db_to_postgres_additional_queries_result.rc == 0 - when: "matrix_postgres_db_migration_request.additional_psql_statements_list|default([])|length > 0" + when: "matrix_postgres_db_migration_request.additional_psql_statements_list | default([])|length > 0" - name: Archive {{ matrix_postgres_db_migration_request.engine_old }} database ({{ matrix_postgres_db_migration_request.src }} -> {{ matrix_postgres_db_migration_request.src }}.backup) - command: + ansible.builtin.command: cmd: "mv {{ matrix_postgres_db_migration_request.src }} {{ matrix_postgres_db_migration_request.src }}.backup" + register: matrix_postgres_migrate_db_to_postgres_move_result + changed_when: matrix_postgres_migrate_db_to_postgres_move_result.rc == 0 - name: Inject result - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your {{ matrix_postgres_db_migration_request.engine_old }} database file has been imported into Postgres. The original database file has been moved from `{{ matrix_postgres_db_migration_request.src }}` to `{{ matrix_postgres_db_migration_request.src }}.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete this file." diff --git a/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml b/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml index f927783fa..fde580f55 100644 --- a/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml +++ b/roles/matrix-postgres/tasks/migrate_postgres_data_directory.yml @@ -9,14 +9,17 @@ # # For this reason, we store the Postgres data in `/matrix/postgres/data` and need to relocate any installations # which still store it in the parent directory (`/matrix/postgres`). +# +# This utility is intentionally not in `tasks/util`, because if it were, it wouldn't be possible +# to include it in other roles via the import_role module: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_role_module.html - name: Check if old Postgres data directory is used - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_base_path }}/PG_VERSION" register: result_pg_old_data_dir_stat - name: Warn if old Postgres data directory detected - debug: + ansible.builtin.debug: msg: > Found that you have Postgres data in `{{ matrix_postgres_base_path }}`. From now on, Postgres data is supposed to be stored in `{{ matrix_postgres_data_path }}` instead. @@ -26,14 +29,14 @@ # We should stop Postgres first, before building a list of files, # as to ignore any `postmaster.pid` files, etc. - name: Ensure matrix-postgres is stopped - service: + ansible.builtin.service: name: matrix-postgres state: stopped daemon_reload: true when: "result_pg_old_data_dir_stat.stat.exists" - name: Find files and directories in old Postgres data path - find: + ansible.builtin.find: paths: "{{ matrix_postgres_base_path }}" file_type: any excludes: ["data"] @@ -41,7 +44,7 @@ when: "result_pg_old_data_dir_stat.stat.exists" - name: Ensure new Postgres data path exists - file: + ansible.builtin.file: path: "{{ matrix_postgres_data_path }}" state: directory mode: 0700 @@ -51,8 +54,11 @@ - block: - name: Relocate Postgres data files from old directory to new - command: "mv {{ item.path }} {{ matrix_postgres_data_path }}/{{ item.path|basename }}" + ansible.builtin.command: + cmd: "mv {{ item.path }} {{ matrix_postgres_data_path }}/{{ item.path | basename }}" with_items: "{{ result_pg_old_data_dir_find.files }}" + register: matrix_postgres_migrate_postgres_data_directory_move_result + changed_when: matrix_postgres_migrate_postgres_data_directory_move_result.rc == 0 when: "result_pg_old_data_dir_stat.stat.exists" # Intentionally not starting matrix-postgres here. @@ -61,12 +67,12 @@ # and have it initialize a new database. - name: Ensure outdated matrix-postgres.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-postgres.service" state: absent when: "result_pg_old_data_dir_stat.stat.exists" - name: Ensure systemd reloaded after getting rid of outdated matrix-postgres.service - service: + ansible.builtin.service: daemon_reload: true when: "result_pg_old_data_dir_stat.stat.exists" diff --git a/roles/matrix-postgres/tasks/run_vacuum.yml b/roles/matrix-postgres/tasks/run_vacuum.yml index 0b7a60f81..ce2bee6b9 100644 --- a/roles/matrix-postgres/tasks/run_vacuum.yml +++ b/roles/matrix-postgres/tasks/run_vacuum.yml @@ -3,47 +3,47 @@ # Pre-checks - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot run vacuum." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" # Defaults - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" - name: Set postgres_vacuum_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_vacuum_wait_time: "{{ 7 * 86400 }}" - when: "postgres_vacuum_wait_time|default('') == ''" + when: "postgres_vacuum_wait_time | default('') == ''" # Actual vacuuming work - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false -- import_tasks: tasks/util/detect_existing_postgres_version.yml +- ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml - name: Abort, if no existing Postgres version detected - fail: + ansible.builtin.fail: msg: "Could not find existing Postgres installation" - when: "not matrix_postgres_detected_existing|bool" + when: "not matrix_postgres_detected_existing | bool" - name: Generate Postgres database vacuum command - set_fact: + ansible.builtin.set_fact: matrix_postgres_vacuum_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-postgres-synapse-vacuum --user={{ matrix_user_uid }}:{{ matrix_user_gid }} @@ -54,37 +54,38 @@ psql -v ON_ERROR_STOP=1 -h matrix-postgres {{ matrix_synapse_database_database }} -c 'VACUUM FULL VERBOSE' - name: Note about Postgres vacuum alternative - debug: + ansible.builtin.debug: msg: >- - Running vacuum with the following Postgres command: `{{ matrix_postgres_vacuum_command }}`. + Running vacuum with the following Postgres ansible.builtin.command: `{{ matrix_postgres_vacuum_command }}`. If this crashes, you can stop all processes (`systemctl stop matrix-*`), start Postgres only (`systemctl start matrix-postgres`) and manually run the above command directly on the server. - name: Populate service facts - service_facts: + ansible.builtin.service_facts: -- set_fact: - matrix_postgres_synapse_was_running: "{{ ansible_facts.services['matrix-synapse.service']|default(none) is not none and ansible_facts.services['matrix-synapse.service'].state == 'running' }}" +- ansible.builtin.set_fact: + matrix_postgres_synapse_was_running: "{{ ansible_facts.services['matrix-synapse.service'] | default(none) is not none and ansible_facts.services['matrix-synapse.service'].state == 'running' }}" - name: Ensure matrix-synapse is stopped - service: + ansible.builtin.service: name: matrix-synapse state: stopped daemon_reload: true - name: Run Postgres vacuum command - command: "{{ matrix_postgres_vacuum_command }}" + ansible.builtin.command: "{{ matrix_postgres_vacuum_command }}" async: "{{ postgres_vacuum_wait_time }}" poll: 10 register: matrix_postgres_synapse_vacuum_result + changed_when: matrix_postgres_synapse_vacuum_result.rc == 0 # Intentionally show the results -- debug: var="matrix_postgres_synapse_vacuum_result" +- ansible.builtin.debug: var="matrix_postgres_synapse_vacuum_result" - name: Ensure matrix-synapse is started, if it previously was - service: + ansible.builtin.service: name: matrix-synapse state: started daemon_reload: true - when: "matrix_postgres_synapse_was_running|bool" + when: "matrix_postgres_synapse_was_running | bool" diff --git a/roles/matrix-postgres/tasks/setup_postgres.yml b/roles/matrix-postgres/tasks/setup_postgres.yml index 04763a324..49eb3249b 100644 --- a/roles/matrix-postgres/tasks/setup_postgres.yml +++ b/roles/matrix-postgres/tasks/setup_postgres.yml @@ -4,36 +4,36 @@ # Tasks related to setting up an internal postgres server # -- import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml" - when: matrix_postgres_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml" + when: matrix_postgres_enabled | bool -- import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml" - when: matrix_postgres_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/detect_existing_postgres_version.yml" + when: matrix_postgres_enabled | bool # If we have found an existing version (installed from before), we use its corresponding Docker image. # If not, we install using the latest Postgres. # # Upgrading is supposed to be performed separately and explicitly (see `upgrade_postgres.yml`). -- set_fact: +- ansible.builtin.set_fact: matrix_postgres_docker_image_to_use: "{{ matrix_postgres_docker_image_latest if matrix_postgres_detected_version_corresponding_docker_image == '' else matrix_postgres_detected_version_corresponding_docker_image }}" - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Abort if on an unsupported Postgres version - fail: + ansible.builtin.fail: msg: "You're on Postgres {{ matrix_postgres_detected_version }}, which is no longer supported. To upgrade, see docs/maintenance-postgres.md" - when: "matrix_postgres_enabled|bool and matrix_postgres_detected_version.startswith('9.')" + when: "matrix_postgres_enabled | bool and matrix_postgres_detected_version.startswith('9.')" - name: Inject warning if on an old version of Postgres - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: Your setup is on an old Postgres version ({{ matrix_postgres_docker_image_to_use }}), while {{ matrix_postgres_docker_image_latest }} is supported. You can upgrade using --tags=upgrade-postgres" ] }} - when: "matrix_postgres_enabled|bool and matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest" + when: "matrix_postgres_enabled | bool and matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest" # Even if we don't run the internal server, we still need this for running the CLI - name: Ensure postgres Docker image is pulled @@ -42,14 +42,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_postgres_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_postgres_docker_image_force_pull }}" - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure Postgres paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0700 @@ -58,22 +58,22 @@ with_items: - "{{ matrix_postgres_base_path }}" - "{{ matrix_postgres_data_path }}" - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool # We do this as a separate task, because: # - we'd like to do it for the data path only, not for the base path (which contains root-owned environment variable files we'd like to leave as-is) # - we need to do it without `mode`, or we risk making certain `.conf` and other files's executable bit to flip to true - name: Ensure Postgres data path ownership is correct - file: + ansible.builtin.file: path: "{{ matrix_postgres_data_path }}" state: directory owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" recurse: true - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure Postgres environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/{{ item }}.j2" dest: "{{ matrix_postgres_base_path }}/{{ item }}" owner: "{{ matrix_user_username }}" @@ -82,79 +82,79 @@ with_items: - "env-postgres-psql" - "env-postgres-server" - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure matrix-postgres-cli script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli.j2" dest: "{{ matrix_local_bin_path }}/matrix-postgres-cli" mode: 0755 - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure matrix-postgres-cli-non-interactive script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli-non-interactive.j2" dest: "{{ matrix_local_bin_path }}/matrix-postgres-cli-non-interactive" mode: 0755 - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure matrix-change-user-admin-status script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-change-user-admin-status.j2" dest: "{{ matrix_local_bin_path }}/matrix-change-user-admin-status" mode: 0755 - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: (Migration) Ensure old matrix-make-user-admin script deleted - file: + ansible.builtin.file: path: "{{ matrix_local_bin_path }}/matrix-make-user-admin" state: absent - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure matrix-postgres-update-user-password-hash script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-update-user-password-hash.j2" dest: "{{ matrix_local_bin_path }}/matrix-postgres-update-user-password-hash" mode: 0755 - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure matrix-postgres.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-postgres.service.j2" dest: "{{ matrix_systemd_path }}/matrix-postgres.service" mode: 0644 register: matrix_postgres_systemd_service_result - when: matrix_postgres_enabled|bool + when: matrix_postgres_enabled | bool - name: Ensure systemd reloaded after matrix-postgres.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_postgres_enabled|bool and matrix_postgres_systemd_service_result.changed" + when: "matrix_postgres_enabled | bool and matrix_postgres_systemd_service_result.changed" -- include_tasks: +- ansible.builtin.include_tasks: file: "{{ role_path }}/tasks/util/create_additional_databases.yml" apply: tags: - always - when: "matrix_postgres_enabled|bool and matrix_postgres_additional_databases|length > 0" + when: "matrix_postgres_enabled | bool and matrix_postgres_additional_databases|length > 0" - name: Check existence of matrix-postgres backup data path - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_data_path }}-auto-upgrade-backup" register: matrix_postgres_data_backup_path_stat - when: "matrix_postgres_enabled|bool" + when: "matrix_postgres_enabled | bool" - name: Inject warning if backup data remains - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: You have some Postgres backup data in `{{ matrix_postgres_data_path }}-auto-upgrade-backup`, which was created during the last major Postgres update you ran. If your setup works well after this upgrade, feel free to delete this whole directory." ] }} - when: "matrix_postgres_enabled|bool and matrix_postgres_data_backup_path_stat.stat.exists" + when: "matrix_postgres_enabled | bool and matrix_postgres_data_backup_path_stat.stat.exists" # @@ -162,54 +162,54 @@ # - name: Check existence of matrix-postgres service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-postgres.service" register: matrix_postgres_service_stat - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Ensure matrix-postgres is stopped - service: + ansible.builtin.service: name: matrix-postgres state: stopped daemon_reload: true - when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists" + when: "not matrix_postgres_enabled | bool and matrix_postgres_service_stat.stat.exists" - name: Ensure matrix-postgres.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-postgres.service" state: absent - when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists" + when: "not matrix_postgres_enabled | bool and matrix_postgres_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-postgres.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists" + when: "not matrix_postgres_enabled | bool and matrix_postgres_service_stat.stat.exists" - name: Check existence of matrix-postgres local data path - stat: + ansible.builtin.stat: path: "{{ matrix_postgres_data_path }}" register: matrix_postgres_data_path_stat - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" # We just want to notify the user. Deleting data is too destructive. - name: Inject warning if matrix-postgres local data remains - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [ "NOTE: You are not using a local PostgreSQL database, but some old data remains from before in `{{ matrix_postgres_data_path }}`. Feel free to delete it." ] }} - when: "not matrix_postgres_enabled|bool and matrix_postgres_data_path_stat.stat.exists" + when: "not matrix_postgres_enabled | bool and matrix_postgres_data_path_stat.stat.exists" - name: Remove Postgres scripts - file: + ansible.builtin.file: path: "{{ matrix_local_bin_path }}/{{ item }}" state: absent with_items: - matrix-postgres-cli - matrix-change-user-admin-status - matrix-postgres-update-user-password-hash - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" diff --git a/roles/matrix-postgres/tasks/upgrade_postgres.yml b/roles/matrix-postgres/tasks/upgrade_postgres.yml index bf98d938a..2f228a4c2 100644 --- a/roles/matrix-postgres/tasks/upgrade_postgres.yml +++ b/roles/matrix-postgres/tasks/upgrade_postgres.yml @@ -1,73 +1,73 @@ --- - name: Set default postgres_dump_dir, if not provided - set_fact: + ansible.builtin.set_fact: postgres_dump_dir: "/tmp" - when: "postgres_dump_dir|default('') == ''" + when: "postgres_dump_dir | default('') == ''" - name: Set postgres_dump_name, if not provided - set_fact: + ansible.builtin.set_fact: postgres_dump_name: "matrix-postgres-dump.sql.gz" - when: "postgres_dump_name|default('') == ''" + when: "postgres_dump_name | default('') == ''" - name: Set postgres_auto_upgrade_backup_data_path, if not provided - set_fact: + ansible.builtin.set_fact: postgres_auto_upgrade_backup_data_path: "{{ matrix_postgres_data_path }}-auto-upgrade-backup" - when: "postgres_auto_upgrade_backup_data_path|default('') == ''" + when: "postgres_auto_upgrade_backup_data_path | default('') == ''" - name: Set postgres_start_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: postgres_start_wait_time: 15 - when: "postgres_start_wait_time|default('') == ''" + when: "postgres_start_wait_time | default('') == ''" - name: Set postgres_force_upgrade, if not provided - set_fact: + ansible.builtin.set_fact: postgres_force_upgrade: false - when: "postgres_force_upgrade|default('') == ''" + when: "postgres_force_upgrade | default('') == ''" - name: Fail, if trying to upgrade external Postgres database - fail: + ansible.builtin.fail: msg: "Your configuration indicates that you're not using Postgres from this role. There is nothing to upgrade." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Check Postgres auto-upgrade backup data directory - stat: + ansible.builtin.stat: path: "{{ postgres_auto_upgrade_backup_data_path }}" register: result_auto_upgrade_path - name: Abort, if existing Postgres auto-upgrade data path detected - fail: + ansible.builtin.fail: msg: "Detected that a left-over {{ postgres_auto_upgrade_backup_data_path }} exists. You should rename it to {{ matrix_postgres_data_path }} if the previous upgrade went wrong, or delete it if it went well." when: "result_auto_upgrade_path.stat.exists" -- import_tasks: tasks/util/detect_existing_postgres_version.yml +- ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml - name: Abort, if no existing Postgres version detected - fail: + ansible.builtin.fail: msg: "Could not find existing Postgres installation" - when: "not matrix_postgres_detected_existing|bool" + when: "not matrix_postgres_detected_existing | bool" - name: Abort, if already at latest Postgres version - fail: + ansible.builtin.fail: msg: "You are already running the latest Postgres version supported ({{ matrix_postgres_docker_image_latest }}). Nothing to do" when: "matrix_postgres_detected_version_corresponding_docker_image == matrix_postgres_docker_image_latest and not postgres_force_upgrade" -- debug: +- ansible.builtin.debug: msg: "Upgrading database from {{ matrix_postgres_detected_version_corresponding_docker_image }} to {{ matrix_postgres_docker_image_latest }}" - name: Ensure matrix-synapse is stopped - service: + ansible.builtin.service: name: matrix-synapse state: stopped - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false @@ -78,41 +78,49 @@ # role (`matrix_postgres_connection_username`) and database (`matrix_postgres_db_name`) by itself on startup, # we need to remove these from the dump, or we'll get errors saying these already exist. - name: Perform Postgres database dump - command: >- - {{ matrix_host_command_docker }} run --rm --name matrix-postgres-dump - --log-driver=none - --user={{ matrix_user_uid }}:{{ matrix_user_gid }} - --network={{ matrix_docker_network }} - --env-file={{ matrix_postgres_base_path }}/env-postgres-psql - --entrypoint=/bin/sh - --mount type=bind,src={{ postgres_dump_dir }},dst=/out - {{ matrix_postgres_detected_version_corresponding_docker_image }} - -c "pg_dumpall -h matrix-postgres - {{ '| gzip -c ' if postgres_dump_name.endswith('.gz') else '' }} - > /out/{{ postgres_dump_name }}" + ansible.builtin.command: + cmd: >- + {{ matrix_host_command_docker }} run --rm --name matrix-postgres-dump + --log-driver=none + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} + --network={{ matrix_docker_network }} + --env-file={{ matrix_postgres_base_path }}/env-postgres-psql + --entrypoint=/bin/sh + --mount type=bind,src={{ postgres_dump_dir }},dst=/out + {{ matrix_postgres_detected_version_corresponding_docker_image }} + -c "pg_dumpall -h matrix-postgres + {{ '| gzip -c ' if postgres_dump_name.endswith('.gz') else '' }} + > /out/{{ postgres_dump_name }}" + register: matrix_postgres_upgrade_postgres_dump_command_result + changed_when: matrix_postgres_upgrade_postgres_dump_command_result.rc == 0 + tags: + - skip_ansible_lint - name: Ensure matrix-postgres is stopped - service: + ansible.builtin.service: name: matrix-postgres state: stopped - name: Rename existing Postgres data directory - command: "mv {{ matrix_postgres_data_path }} {{ postgres_auto_upgrade_backup_data_path }}" + ansible.builtin.command: + cmd: "mv {{ matrix_postgres_data_path }} {{ postgres_auto_upgrade_backup_data_path }}" + register: matrix_postgres_upgrade_postgres_move_command_result + changed_when: matrix_postgres_upgrade_postgres_move_command_result.rc == 0 -- debug: +- ansible.builtin.debug: msg: "NOTE: Your Postgres data directory has been moved from `{{ matrix_postgres_data_path }}` to `{{ postgres_auto_upgrade_backup_data_path }}`. In the event of failure, you can move it back and run the playbook with --tags=setup-postgres to restore operation." -- import_tasks: tasks/setup_postgres.yml +- ansible.builtin.import_tasks: tasks/setup_postgres.yml - name: Ensure matrix-postgres autoruns and is restarted - service: + ansible.builtin.service: name: matrix-postgres enabled: true state: restarted daemon_reload: true - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ postgres_start_wait_time }}" delegate_to: 127.0.0.1 become: false @@ -122,7 +130,7 @@ # The dump most likely contains those same entries and would try to re-create them, leading to errors. # We need to skip over those lines. - name: Generate Postgres database import command - set_fact: + ansible.builtin.set_fact: matrix_postgres_import_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-postgres-import --log-driver=none @@ -138,6 +146,8 @@ grep -vE '{{ matrix_postgres_import_roles_ignore_regex }}' | grep -vE '{{ matrix_postgres_import_databases_ignore_regex }}' | psql -v ON_ERROR_STOP=1 -h matrix-postgres" + tags: + - skip_ansible_lint # This is a hack. # See: https://ansibledaily.com/print-to-standard-output-without-escaping/ @@ -145,7 +155,7 @@ # We want to run `debug: msg=".."`, but that dumps it as JSON and escapes double quotes within it, # which ruins the command (`matrix_postgres_import_command`) - name: Note about Postgres importing - set_fact: + ansible.builtin.set_fact: dummy: true with_items: - >- @@ -155,18 +165,21 @@ and restore the automatically-made backup (`mv {{ postgres_auto_upgrade_backup_data_path }} {{ matrix_postgres_data_path }}`). - name: Perform Postgres database import - command: "{{ matrix_postgres_import_command }}" + ansible.builtin.command: + cmd: "{{ matrix_postgres_import_command }}" + register: matrix_postgres_upgrade_postgres_import_command_result + changed_when: matrix_postgres_upgrade_postgres_import_command_result.rc == 0 - name: Delete Postgres database dump file - file: + ansible.builtin.file: path: "{{ postgres_dump_dir }}/{{ postgres_dump_name }}" state: absent - name: Ensure matrix-synapse is started - service: + ansible.builtin.service: name: matrix-synapse state: started daemon_reload: true -- debug: +- ansible.builtin.debug: msg: "NOTE: Your old Postgres data directory is preserved at `{{ postgres_auto_upgrade_backup_data_path }}`. You might want to get rid of it once you've confirmed that all is well." diff --git a/roles/matrix-postgres/tasks/util/create_additional_database.yml b/roles/matrix-postgres/tasks/util/create_additional_database.yml index 22b3c9a2a..da95b8704 100644 --- a/roles/matrix-postgres/tasks/util/create_additional_database.yml +++ b/roles/matrix-postgres/tasks/util/create_additional_database.yml @@ -3,7 +3,7 @@ # It'd be better if this is belonged to `validate_config.yml`, but it would have to be some loop-within-a-loop there, # and that's ugly. We also don't expect this to catch errors often. It's more of a defensive last-minute check. - name: Fail if additional database data appears invalid - fail: + ansible.builtin.fail: msg: "Additional database definition ({{ additional_db }} lacks a required key: {{ item }}" when: "item not in additional_db" with_items: "{{ ['name', 'username', 'password'] }}" @@ -12,7 +12,7 @@ # This file will be mounted into the container and fed to Postgres. # This way, we avoid passing sensitive data around in CLI commands that other users on the system can see. - name: Create additional database initialization SQL file for {{ additional_db.name }} - template: + ansible.builtin.template: src: "{{ role_path }}/templates/sql/init-additional-db-user-and-role.sql.j2" dest: "/tmp/matrix-postgres-init-additional-db-user-and-role.sql" mode: 0600 @@ -20,7 +20,7 @@ group: "{{ matrix_user_gid }}" - name: Execute Postgres additional database initialization SQL file for {{ additional_db.name }} - command: + ansible.builtin.command: cmd: >- {{ matrix_host_command_docker }} run --rm @@ -33,8 +33,9 @@ {{ matrix_postgres_docker_image_to_use }} -c 'psql -h {{ matrix_postgres_connection_hostname }} --file=/matrix-postgres-init-additional-db-user-and-role.sql' + changed_when: true - name: Delete additional database initialization SQL file for {{ additional_db.name }} - file: + ansible.builtin.file: path: /tmp/matrix-postgres-init-additional-db-user-and-role.sql state: absent diff --git a/roles/matrix-postgres/tasks/util/create_additional_databases.yml b/roles/matrix-postgres/tasks/util/create_additional_databases.yml index de87f98c4..7fe5713e1 100644 --- a/roles/matrix-postgres/tasks/util/create_additional_databases.yml +++ b/roles/matrix-postgres/tasks/util/create_additional_databases.yml @@ -1,21 +1,21 @@ --- - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true register: matrix_postgres_service_start_result - name: Wait a bit, so that Postgres can start - wait_for: + ansible.builtin.wait_for: timeout: "{{ matrix_postgres_additional_databases_postgres_start_wait_timeout_seconds }}" delegate_to: 127.0.0.1 become: false - when: "matrix_postgres_service_start_result.changed|bool" + when: "matrix_postgres_service_start_result.changed | bool" - name: Create additional Postgres user and database - include_tasks: "{{ role_path }}/tasks/util/create_additional_database.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/util/create_additional_database.yml" with_items: "{{ matrix_postgres_additional_databases }}" loop_control: loop_var: additional_db diff --git a/roles/matrix-postgres/tasks/validate_config.yml b/roles/matrix-postgres/tasks/validate_config.yml index eac4dd5b1..f239b116a 100644 --- a/roles/matrix-postgres/tasks/validate_config.yml +++ b/roles/matrix-postgres/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: (Deprecation) Warn about matrix_postgres_use_external usage - fail: + ansible.builtin.fail: msg: > The `matrix_postgres_use_external` variable defined in your configuration is not used by this playbook anymore! You'll need to adapt to the new way of using an external Postgres server. @@ -13,7 +13,7 @@ # This is separate (from the other required variables below), # because we'd like to have a friendlier message for our existing users. - name: Fail if matrix_postgres_connection_password not defined - fail: + ansible.builtin.fail: msg: >- The playbook no longer has a default Postgres password defined in the `matrix_postgres_connection_password` variable, among lots of other Postgres changes. You need to perform multiple manual steps to resolve this. @@ -22,7 +22,7 @@ when: "matrix_postgres_connection_password == ''" - name: Fail if required Postgres settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`). when: "vars[item] == ''" @@ -34,6 +34,6 @@ - "matrix_postgres_db_name" - name: Fail if Postgres password length exceeded - fail: + ansible.builtin.fail: msg: "The maximum `matrix_postgres_connection_password` length is 99 characters" when: "matrix_postgres_connection_password|length > 99" diff --git a/roles/matrix-prometheus-node-exporter/tasks/init.yml b/roles/matrix-prometheus-node-exporter/tasks/init.yml index d08340a83..51dd94f2a 100644 --- a/roles/matrix-prometheus-node-exporter/tasks/init.yml +++ b/roles/matrix-prometheus-node-exporter/tasks/init.yml @@ -1,24 +1,24 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-prometheus-node-exporter.service'] }}" - when: matrix_prometheus_node_exporter_enabled|bool + when: matrix_prometheus_node_exporter_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append node-exporter'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-prometheus-node-exporter role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate node-exporter metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/node-exporter) - set_fact: + ansible.builtin.set_fact: matrix_prometheus_node_exporter_nginx_metrics_configuration_block: | location /metrics/node-exporter { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-prometheus-node-exporter:9100"; @@ -31,11 +31,11 @@ } - name: Register node-exporter metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/node-exporter) - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + [matrix_prometheus_node_exporter_nginx_metrics_configuration_block] }} - when: matrix_prometheus_node_exporter_enabled|bool and matrix_prometheus_node_exporter_metrics_proxying_enabled|bool + when: matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_metrics_proxying_enabled | bool diff --git a/roles/matrix-prometheus-node-exporter/tasks/main.yml b/roles/matrix-prometheus-node-exporter/tasks/main.yml index 71bbb8d74..81b0c7022 100644 --- a/roles/matrix-prometheus-node-exporter/tasks/main.yml +++ b/roles/matrix-prometheus-node-exporter/tasks/main.yml @@ -1,10 +1,10 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup.yml" tags: - setup-all - setup-prometheus-node-exporter diff --git a/roles/matrix-prometheus-node-exporter/tasks/setup.yml b/roles/matrix-prometheus-node-exporter/tasks/setup.yml index 21d0b55db..0c6e77fcb 100644 --- a/roles/matrix-prometheus-node-exporter/tasks/setup.yml +++ b/roles/matrix-prometheus-node-exporter/tasks/setup.yml @@ -10,50 +10,50 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_prometheus_node_exporter_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_prometheus_node_exporter_docker_image_force_pull }}" - when: "matrix_prometheus_node_exporter_enabled|bool" + when: "matrix_prometheus_node_exporter_enabled | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-prometheus-node-exporter.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-prometheus-node-exporter.service.j2" dest: "{{ matrix_systemd_path }}/matrix-prometheus-node-exporter.service" mode: 0644 register: matrix_prometheus_node_exporter_systemd_service_result - when: matrix_prometheus_node_exporter_enabled|bool + when: matrix_prometheus_node_exporter_enabled | bool - name: Ensure systemd reloaded after matrix-prometheus.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_prometheus_node_exporter_enabled|bool and matrix_prometheus_node_exporter_systemd_service_result.changed" + when: "matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_systemd_service_result.changed" # # Tasks related to getting rid of matrix-prometheus-node-exporter (if it was previously enabled) # - name: Check existence of matrix-prometheus-node-exporter service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-prometheus-node-exporter.service" register: matrix_prometheus_node_exporter_service_stat - name: Ensure matrix-prometheus-node-exporter is stopped - service: + ansible.builtin.service: name: matrix-prometheus-node-exporter state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_prometheus_node_exporter_enabled|bool and matrix_prometheus_node_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_service_stat.stat.exists" - name: Ensure matrix-prometheus-node-exporter.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-prometheus-node-exporter.service" state: absent - when: "not matrix_prometheus_node_exporter_enabled|bool and matrix_prometheus_node_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-prometheus-node-exporter.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_prometheus_node_exporter_enabled|bool and matrix_prometheus_node_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_service_stat.stat.exists" diff --git a/roles/matrix-prometheus-postgres-exporter/defaults/main.yml b/roles/matrix-prometheus-postgres-exporter/defaults/main.yml index b7cd08b9a..82a12f42e 100644 --- a/roles/matrix-prometheus-postgres-exporter/defaults/main.yml +++ b/roles/matrix-prometheus-postgres-exporter/defaults/main.yml @@ -12,8 +12,8 @@ matrix_prometheus_postgres_exporter_docker_image_force_pull: "{{ matrix_promethe # A list of extra arguments to pass to the container matrix_prometheus_postgres_exporter_container_extra_arguments: ["-e PG_EXPORTER_AUTO_DISCOVER_DATABASES=true", - "-e PG_EXPORTER_WEB_LISTEN_ADDRESS=\":{{matrix_prometheus_postgres_exporter_port}}\"", - "-e DATA_SOURCE_NAME=\"postgresql://{{matrix_prometheus_postgres_exporter_database_username}}:{{matrix_prometheus_postgres_exporter_database_password}}@{{matrix_prometheus_postgres_exporter_database_hostname}}:5432/{{matrix_prometheus_postgres_exporter_database_name}}?sslmode=disable\""] + "-e PG_EXPORTER_WEB_LISTEN_ADDRESS=\":{{ matrix_prometheus_postgres_exporter_port }}\"", + "-e DATA_SOURCE_NAME=\"postgresql://{{ matrix_prometheus_postgres_exporter_database_username }}:{{ matrix_prometheus_postgres_exporter_database_password }}@{{ matrix_prometheus_postgres_exporter_database_hostname }}:5432/{{ matrix_prometheus_postgres_exporter_database_name }}?sslmode=disable\""] # List of systemd services that matrix-prometheus-postgres-exporter.service depends on matrix_prometheus_postgres_exporter_systemd_required_services_list: ['docker.service'] diff --git a/roles/matrix-prometheus-postgres-exporter/tasks/init.yml b/roles/matrix-prometheus-postgres-exporter/tasks/init.yml index 996cc975d..6da169370 100644 --- a/roles/matrix-prometheus-postgres-exporter/tasks/init.yml +++ b/roles/matrix-prometheus-postgres-exporter/tasks/init.yml @@ -1,24 +1,24 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-prometheus-postgres-exporter.service'] }}" - when: matrix_prometheus_postgres_exporter_enabled|bool + when: matrix_prometheus_postgres_exporter_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append postgres-exporter'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-prometheus-postgres-exporter role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate postgres-exporter metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/postgres-exporter) - set_fact: + ansible.builtin.set_fact: matrix_prometheus_postgres_exporter_nginx_metrics_configuration_block: | location /metrics/postgres-exporter { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-prometheus-postgres-exporter:9187"; @@ -31,11 +31,11 @@ } - name: Register postgres-exporter metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/postgres-exporter) - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + [matrix_prometheus_postgres_exporter_nginx_metrics_configuration_block] }} - when: matrix_prometheus_node_exporter_enabled|bool and matrix_prometheus_node_exporter_metrics_proxying_enabled|bool + when: matrix_prometheus_node_exporter_enabled | bool and matrix_prometheus_node_exporter_metrics_proxying_enabled | bool diff --git a/roles/matrix-prometheus-postgres-exporter/tasks/main.yml b/roles/matrix-prometheus-postgres-exporter/tasks/main.yml index e94970995..434735877 100644 --- a/roles/matrix-prometheus-postgres-exporter/tasks/main.yml +++ b/roles/matrix-prometheus-postgres-exporter/tasks/main.yml @@ -1,10 +1,10 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup.yml" tags: - setup-all - setup-prometheus-postgres-exporter diff --git a/roles/matrix-prometheus-postgres-exporter/tasks/setup.yml b/roles/matrix-prometheus-postgres-exporter/tasks/setup.yml index 08ffe708e..00a61df62 100644 --- a/roles/matrix-prometheus-postgres-exporter/tasks/setup.yml +++ b/roles/matrix-prometheus-postgres-exporter/tasks/setup.yml @@ -10,50 +10,50 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_prometheus_postgres_exporter_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_prometheus_postgres_exporter_docker_image_force_pull }}" - when: "matrix_prometheus_postgres_exporter_enabled|bool" + when: "matrix_prometheus_postgres_exporter_enabled | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-prometheus-postgres-exporter.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-prometheus-postgres-exporter.service.j2" dest: "{{ matrix_systemd_path }}/matrix-prometheus-postgres-exporter.service" mode: 0644 register: matrix_prometheus_postgres_exporter_systemd_service_result - when: matrix_prometheus_postgres_exporter_enabled|bool + when: matrix_prometheus_postgres_exporter_enabled | bool - name: Ensure systemd reloaded after matrix-prometheus.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_prometheus_postgres_exporter_enabled|bool and matrix_prometheus_postgres_exporter_systemd_service_result.changed" + when: "matrix_prometheus_postgres_exporter_enabled | bool and matrix_prometheus_postgres_exporter_systemd_service_result.changed" # # Tasks related to getting rid of matrix-prometheus-postgres-exporter (if it was previously enabled) # - name: Check existence of matrix-prometheus-postgres-exporter service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-prometheus-postgres-exporter.service" register: matrix_prometheus_postgres_exporter_service_stat - name: Ensure matrix-prometheus-postgres-exporter is stopped - service: + ansible.builtin.service: name: matrix-prometheus-postgres-exporter state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_prometheus_postgres_exporter_enabled|bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_postgres_exporter_enabled | bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" - name: Ensure matrix-prometheus-postgres-exporter.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-prometheus-postgres-exporter.service" state: absent - when: "not matrix_prometheus_postgres_exporter_enabled|bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_postgres_exporter_enabled | bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-prometheus-postgres-exporter.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_prometheus_postgres_exporter_enabled|bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" + when: "not matrix_prometheus_postgres_exporter_enabled | bool and matrix_prometheus_postgres_exporter_service_stat.stat.exists" diff --git a/roles/matrix-prometheus/defaults/main.yml b/roles/matrix-prometheus/defaults/main.yml index 547a868ff..8f5c21481 100644 --- a/roles/matrix-prometheus/defaults/main.yml +++ b/roles/matrix-prometheus/defaults/main.yml @@ -75,8 +75,8 @@ matrix_prometheus_configuration_extension_yaml: | # If you need something more special, you can take full control by # completely redefining `matrix_prometheus_configuration_yaml`. -matrix_prometheus_configuration_extension: "{{ matrix_prometheus_configuration_extension_yaml|from_yaml if matrix_prometheus_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_prometheus_configuration_extension: "{{ matrix_prometheus_configuration_extension_yaml | from_yaml if matrix_prometheus_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_prometheus_configuration_yaml`. -matrix_prometheus_configuration: "{{ matrix_prometheus_configuration_yaml|from_yaml|combine(matrix_prometheus_configuration_extension, recursive=True) }}" +matrix_prometheus_configuration: "{{ matrix_prometheus_configuration_yaml | from_yaml | combine(matrix_prometheus_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-prometheus/tasks/init.yml b/roles/matrix-prometheus/tasks/init.yml index 6587ddd91..298536730 100644 --- a/roles/matrix-prometheus/tasks/init.yml +++ b/roles/matrix-prometheus/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-prometheus.service'] }}" - when: matrix_prometheus_enabled|bool + when: matrix_prometheus_enabled | bool diff --git a/roles/matrix-prometheus/tasks/main.yml b/roles/matrix-prometheus/tasks/main.yml index c74918fa8..1a5a37089 100644 --- a/roles/matrix-prometheus/tasks/main.yml +++ b/roles/matrix-prometheus/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_prometheus_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_prometheus_enabled | bool" tags: - setup-all - setup-prometheus -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_prometheus_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_prometheus_enabled | bool" tags: - setup-all - setup-prometheus -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_prometheus_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_prometheus_enabled | bool" tags: - setup-all - setup-prometheus diff --git a/roles/matrix-prometheus/tasks/setup_install.yml b/roles/matrix-prometheus/tasks/setup_install.yml index 06989e7ef..c3aeaa7a6 100644 --- a/roles/matrix-prometheus/tasks/setup_install.yml +++ b/roles/matrix-prometheus/tasks/setup_install.yml @@ -12,7 +12,7 @@ until: result is not failed - name: Ensure Prometheus paths exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -24,35 +24,35 @@ - "{{ matrix_prometheus_data_path }}" - name: Download synapse-v2.rules - get_url: + ansible.builtin.get_url: url: "{{ matrix_prometheus_scraper_synapse_rules_download_url }}" dest: "{{ matrix_prometheus_config_path }}/synapse-v2.rules" force: true mode: 0440 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: "matrix_prometheus_scraper_synapse_rules_enabled|bool" + when: "matrix_prometheus_scraper_synapse_rules_enabled | bool" register: result retries: "{{ matrix_geturl_retries_count }}" delay: "{{ matrix_geturl_retries_delay }}" until: result is not failed - name: Ensure prometheus.yml installed - copy: - content: "{{ matrix_prometheus_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_prometheus_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_prometheus_config_path }}/prometheus.yml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-prometheus.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-prometheus.service.j2" dest: "{{ matrix_systemd_path }}/matrix-prometheus.service" mode: 0644 register: matrix_prometheus_systemd_service_result - name: Ensure systemd reloaded after matrix-prometheus.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_prometheus_systemd_service_result.changed|bool" + when: "matrix_prometheus_systemd_service_result.changed | bool" diff --git a/roles/matrix-prometheus/tasks/setup_uninstall.yml b/roles/matrix-prometheus/tasks/setup_uninstall.yml index c9f07f52e..7dd944591 100644 --- a/roles/matrix-prometheus/tasks/setup_uninstall.yml +++ b/roles/matrix-prometheus/tasks/setup_uninstall.yml @@ -1,26 +1,26 @@ --- - name: Check existence of matrix-prometheus service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-prometheus.service" register: matrix_prometheus_service_stat - name: Ensure matrix-prometheus is stopped - service: + ansible.builtin.service: name: matrix-prometheus state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_prometheus_service_stat.stat.exists|bool" + when: "matrix_prometheus_service_stat.stat.exists | bool" - name: Ensure matrix-prometheus.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-prometheus.service" state: absent - when: "matrix_prometheus_service_stat.stat.exists|bool" + when: "matrix_prometheus_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-prometheus.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_prometheus_service_stat.stat.exists|bool" + when: "matrix_prometheus_service_stat.stat.exists | bool" diff --git a/roles/matrix-prometheus/tasks/validate_config.yml b/roles/matrix-prometheus/tasks/validate_config.yml index 9fcfe12b2..3e3863042 100644 --- a/roles/matrix-prometheus/tasks/validate_config.yml +++ b/roles/matrix-prometheus/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if Synapse metrics or Prometheus Node Exporter not enabled - fail: + ansible.builtin.fail: msg: > You need to enable `matrix_prometheus_scraper_synapse_enabled` and/or `matrix_prometheus_scraper_node_enabled` for Prometheus grab metrics. when: "not matrix_prometheus_scraper_synapse_enabled and not matrix_prometheus_scraper_node_enabled" diff --git a/roles/matrix-redis/tasks/init.yml b/roles/matrix-redis/tasks/init.yml index 99c52026d..00154b336 100644 --- a/roles/matrix-redis/tasks/init.yml +++ b/roles/matrix-redis/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-redis'] }}" - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool diff --git a/roles/matrix-redis/tasks/main.yml b/roles/matrix-redis/tasks/main.yml index 430b6a646..1bcac7d6a 100644 --- a/roles/matrix-redis/tasks/main.yml +++ b/roles/matrix-redis/tasks/main.yml @@ -1,11 +1,11 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/setup_redis.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_redis.yml" + when: run_setup | bool tags: - setup-all - setup-redis diff --git a/roles/matrix-redis/tasks/setup_redis.yml b/roles/matrix-redis/tasks/setup_redis.yml index df1d17367..7dd7ea9f2 100644 --- a/roles/matrix-redis/tasks/setup_redis.yml +++ b/roles/matrix-redis/tasks/setup_redis.yml @@ -10,14 +10,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_redis_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_redis_docker_image_force_pull }}" - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure redis paths exist - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0700 @@ -26,79 +26,79 @@ with_items: - "{{ matrix_redis_base_path }}" - "{{ matrix_redis_data_path }}" - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool # We do this as a separate task, because: # - we'd like to do it for the data path only, not for the base path (which contains root-owned environment variable files we'd like to leave as-is) # - we need to do it without `mode`, or we risk making certain `.conf` and other files's executable bit to flip to true - name: Ensure redis data path ownership is correct - file: + ansible.builtin.file: path: "{{ matrix_redis_data_path }}" state: directory owner: "{{ matrix_user_username }}" group: "{{ matrix_user_username }}" recurse: true - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool - name: Ensure redis environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/{{ item }}.j2" dest: "{{ matrix_redis_base_path }}/{{ item }}" mode: 0644 with_items: - "redis.conf" - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool - name: Ensure matrix-redis.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-redis.service.j2" dest: "{{ matrix_systemd_path }}/matrix-redis.service" mode: 0644 register: matrix_redis_systemd_service_result - when: matrix_redis_enabled|bool + when: matrix_redis_enabled | bool - name: Ensure systemd reloaded after matrix-redis.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_redis_enabled|bool and matrix_redis_systemd_service_result.changed" + when: "matrix_redis_enabled | bool and matrix_redis_systemd_service_result.changed" # # Tasks related to getting rid of the internal redis server (if it was previously enabled) # - name: Check existence of matrix-redis service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-redis.service" register: matrix_redis_service_stat - when: "not matrix_redis_enabled|bool" + when: "not matrix_redis_enabled | bool" - name: Ensure matrix-redis is stopped - service: + ansible.builtin.service: name: matrix-redis state: stopped enabled: false daemon_reload: true - when: "not matrix_redis_enabled|bool and matrix_redis_service_stat.stat.exists" + when: "not matrix_redis_enabled | bool and matrix_redis_service_stat.stat.exists" - name: Ensure matrix-redis.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-redis.service" state: absent - when: "not matrix_redis_enabled|bool and matrix_redis_service_stat.stat.exists" + when: "not matrix_redis_enabled | bool and matrix_redis_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-redis.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_redis_enabled|bool and matrix_redis_service_stat.stat.exists" + when: "not matrix_redis_enabled | bool and matrix_redis_service_stat.stat.exists" - name: Check existence of matrix-redis local data path - stat: + ansible.builtin.stat: path: "{{ matrix_redis_data_path }}" register: matrix_redis_data_path_stat - when: "not matrix_redis_enabled|bool" + when: "not matrix_redis_enabled | bool" # We just want to notify the user. Deleting data is too destructive. - name: Notify if matrix-redis local data remains - debug: + ansible.builtin.debug: msg: "Note: You are not using a local redis instance, but some old data remains from before in `{{ matrix_redis_data_path }}`. Feel free to delete it." - when: "not matrix_redis_enabled|bool and matrix_redis_data_path_stat.stat.exists" + when: "not matrix_redis_enabled | bool and matrix_redis_data_path_stat.stat.exists" diff --git a/roles/matrix-registration/defaults/main.yml b/roles/matrix-registration/defaults/main.yml index 9f4c673cd..1e53ae982 100644 --- a/roles/matrix-registration/defaults/main.yml +++ b/roles/matrix-registration/defaults/main.yml @@ -115,8 +115,8 @@ matrix_registration_configuration_extension_yaml: | # password: # min_length: 12 -matrix_registration_configuration_extension: "{{ matrix_registration_configuration_extension_yaml|from_yaml if matrix_registration_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_registration_configuration_extension: "{{ matrix_registration_configuration_extension_yaml | from_yaml if matrix_registration_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final matrix-registration configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_registration_configuration_yaml`. -matrix_registration_configuration: "{{ matrix_registration_configuration_yaml|from_yaml|combine(matrix_registration_configuration_extension, recursive=True) }}" +matrix_registration_configuration: "{{ matrix_registration_configuration_yaml | from_yaml | combine(matrix_registration_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-registration/tasks/generate_token.yml b/roles/matrix-registration/tasks/generate_token.yml index 4e337b016..c910bf63b 100644 --- a/roles/matrix-registration/tasks/generate_token.yml +++ b/roles/matrix-registration/tasks/generate_token.yml @@ -1,17 +1,17 @@ --- - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `one_time` variable needs to be provided to this playbook, via --extra-vars" when: "one_time is not defined or one_time not in ['yes', 'no']" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `ex_date` variable (expiration date) needs to be provided to this playbook, via --extra-vars" when: "ex_date is not defined or ex_date == ''" - name: Call matrix-registration token creation API - uri: + ansible.builtin.uri: url: "{{ matrix_registration_api_token_endpoint }}" follow_redirects: none validate_certs: "{{ matrix_registration_api_validate_certs }}" @@ -23,12 +23,12 @@ body: | { "one_time": {{ 'true' if one_time == 'yes' else 'false' }}, - "ex_date": {{ ex_date|to_json }} + "ex_date": {{ ex_date | to_json }} } check_mode: false register: matrix_registration_api_result -- set_fact: +- ansible.builtin.set_fact: matrix_registration_api_result_message: >- matrix-registration result: @@ -42,10 +42,10 @@ check_mode: false - name: Inject result message into matrix_playbook_runtime_results - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [matrix_registration_api_result_message] }} diff --git a/roles/matrix-registration/tasks/init.yml b/roles/matrix-registration/tasks/init.yml index 44a887d18..064f895c1 100644 --- a/roles/matrix-registration/tasks/init.yml +++ b/roles/matrix-registration/tasks/init.yml @@ -2,32 +2,32 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_registration_container_image_self_build and matrix_registration_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-registration.service'] }}" - when: matrix_registration_enabled|bool + when: matrix_registration_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append matrix-registration'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-registration role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate matrix-registration proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_registration_matrix_nginx_proxy_configuration: | rewrite ^{{ matrix_registration_public_endpoint }}$ {{ matrix_nginx_proxy_x_forwarded_proto_value }}://$server_name{{ matrix_registration_public_endpoint }}/ permanent; rewrite ^{{ matrix_registration_public_endpoint }}/$ {{ matrix_nginx_proxy_x_forwarded_proto_value }}://$server_name{{ matrix_registration_public_endpoint }}/register redirect; location ~ ^{{ matrix_registration_public_endpoint }}/(.*) { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-registration:5000"; @@ -47,23 +47,23 @@ } - name: Register matrix-registration proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_registration_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_registration_enabled|bool + when: matrix_registration_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the matrix-registration tool but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_registration_public_endpoint }}` URL endpoint to the matrix-registration container. You can expose the container's port using the `matrix_registration_container_http_host_bind_port` variable. - when: "matrix_registration_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_registration_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-registration/tasks/list_tokens.yml b/roles/matrix-registration/tasks/list_tokens.yml index 9ef40d274..4bcd14605 100644 --- a/roles/matrix-registration/tasks/list_tokens.yml +++ b/roles/matrix-registration/tasks/list_tokens.yml @@ -1,7 +1,7 @@ --- - name: Call matrix-registration list all tokens API - uri: + ansible.builtin.uri: url: "{{ matrix_registration_api_token_endpoint }}" follow_redirects: none validate_certs: "{{ matrix_registration_api_validate_certs }}" @@ -13,7 +13,7 @@ check_mode: false register: matrix_registration_api_result -- set_fact: +- ansible.builtin.set_fact: matrix_registration_api_result_message: >- matrix-registration result: @@ -21,10 +21,10 @@ check_mode: false - name: Inject result message into matrix_playbook_runtime_results - set_fact: + ansible.builtin.set_fact: matrix_playbook_runtime_results: | {{ - matrix_playbook_runtime_results|default([]) + matrix_playbook_runtime_results | default([]) + [matrix_registration_api_result_message] }} diff --git a/roles/matrix-registration/tasks/main.yml b/roles/matrix-registration/tasks/main.yml index ca5743846..99b89e3da 100644 --- a/roles/matrix-registration/tasks/main.yml +++ b/roles/matrix-registration/tasks/main.yml @@ -1,33 +1,33 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: "run_setup|bool and matrix_registration_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup | bool and matrix_registration_enabled | bool" tags: - setup-all - setup-matrix-registration -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: "run_setup|bool and matrix_registration_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup | bool and matrix_registration_enabled | bool" tags: - setup-all - setup-matrix-registration -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: "run_setup|bool and not matrix_registration_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup | bool and not matrix_registration_enabled | bool" tags: - setup-all - setup-matrix-registration -- import_tasks: "{{ role_path }}/tasks/generate_token.yml" - when: "run_setup|bool and matrix_registration_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/generate_token.yml" + when: "run_setup | bool and matrix_registration_enabled | bool" tags: - generate-matrix-registration-token -- import_tasks: "{{ role_path }}/tasks/list_tokens.yml" - when: "run_setup|bool and matrix_registration_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/list_tokens.yml" + when: "run_setup | bool and matrix_registration_enabled | bool" tags: - list-matrix-registration-tokens diff --git a/roles/matrix-registration/tasks/setup_install.yml b/roles/matrix-registration/tasks/setup_install.yml index 36cd0fd4a..d3048337d 100644 --- a/roles/matrix-registration/tasks/setup_install.yml +++ b/roles/matrix-registration/tasks/setup_install.yml @@ -1,20 +1,20 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_registration_requires_restart: false - block: - name: Check if an SQLite database already exists - stat: + ansible.builtin.stat: path: "{{ matrix_registration_sqlite_database_path_local }}" register: matrix_registration_sqlite_database_path_local_stat_result - block: - - set_fact: + - ansible.builtin.set_fact: matrix_postgres_db_migration_request: src: "{{ matrix_registration_sqlite_database_path_local }}" dst: "{{ matrix_registration_database_connection_string }}" - caller: "{{ role_path|basename }}" + caller: "{{ role_path | basename }}" engine_variable_name: 'matrix_registration_database_engine' engine_old: 'sqlite' systemd_services_to_stop: ['matrix-registration.service'] @@ -24,15 +24,17 @@ - ALTER TABLE tokens ALTER COLUMN ex_date TYPE TIMESTAMP WITHOUT TIME ZONE; additional_psql_statements_db_name: "{{ matrix_registration_database_name }}" - - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + - ansible.builtin.import_role: + name: matrix-postgres + tasks_from: migrate_db_to_postgres - - set_fact: + - ansible.builtin.set_fact: matrix_registration_requires_restart: true - when: "matrix_registration_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_registration_sqlite_database_path_local_stat_result.stat.exists | bool" when: "matrix_registration_database_engine == 'postgres'" - name: Ensure matrix-registration paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -43,7 +45,7 @@ - {path: "{{ matrix_registration_config_path }}", when: true} - {path: "{{ matrix_registration_data_path }}", when: true} - {path: "{{ matrix_registration_docker_src_files_path }}", when: "{{ matrix_registration_container_image_self_build }}"} - when: "item.when|bool" + when: "item.when | bool" - name: Ensure matrix-registration image is pulled docker_image: @@ -51,14 +53,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_registration_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_registration_docker_image_force_pull }}" - when: "not matrix_registration_container_image_self_build|bool" + when: "not matrix_registration_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-registration repository is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_registration_container_image_self_build_repo }}" dest: "{{ matrix_registration_docker_src_files_path }}" version: "{{ matrix_registration_container_image_self_build_branch }}" @@ -66,15 +68,15 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_registration_git_pull_results - when: "matrix_registration_container_image_self_build|bool" + when: "matrix_registration_container_image_self_build | bool" # See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1864 - name: Patch setup.py to allow self-built version to work - lineinfile: + ansible.builtin.lineinfile: path: "{{ matrix_registration_docker_src_files_path }}/setup.py" regexp: 'flask-limiter' line: '"flask-limiter~=1.1.0", "Markupsafe<2.1",' - when: "matrix_registration_container_image_self_build|bool and matrix_registration_container_image_self_build_python_dependencies_patch_enabled|bool" + when: "matrix_registration_container_image_self_build | bool and matrix_registration_container_image_self_build_python_dependencies_patch_enabled | bool" - name: Ensure matrix-registration Docker image is built docker_image: @@ -86,30 +88,30 @@ dockerfile: Dockerfile path: "{{ matrix_registration_docker_src_files_path }}" pull: true - when: "matrix_registration_container_image_self_build|bool" + when: "matrix_registration_container_image_self_build | bool" - name: Ensure matrix-registration config installed - copy: - content: "{{ matrix_registration_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_registration_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_registration_config_path }}/config.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-registration.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-registration.service.j2" dest: "{{ matrix_systemd_path }}/matrix-registration.service" mode: 0644 register: matrix_registration_systemd_service_result - name: Ensure systemd reloaded after matrix-registration.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_registration_systemd_service_result.changed|bool" + when: "matrix_registration_systemd_service_result.changed | bool" - name: Ensure matrix-registration.service restarted, if necessary - service: + ansible.builtin.service: name: "matrix-registration.service" state: restarted - when: "matrix_registration_requires_restart|bool" + when: "matrix_registration_requires_restart | bool" diff --git a/roles/matrix-registration/tasks/setup_uninstall.yml b/roles/matrix-registration/tasks/setup_uninstall.yml index 4b7c195fe..e3d713dc5 100644 --- a/roles/matrix-registration/tasks/setup_uninstall.yml +++ b/roles/matrix-registration/tasks/setup_uninstall.yml @@ -1,29 +1,29 @@ --- - name: Check existence of matrix-registration service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-registration.service" register: matrix_registration_service_stat - name: Ensure matrix-registration is stopped - service: + ansible.builtin.service: name: matrix-registration state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_registration_service_stat.stat.exists|bool" + when: "matrix_registration_service_stat.stat.exists | bool" - name: Ensure matrix-registration.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-registration.service" state: absent - when: "matrix_registration_service_stat.stat.exists|bool" + when: "matrix_registration_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-registration.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_registration_service_stat.stat.exists|bool" + when: "matrix_registration_service_stat.stat.exists | bool" - name: Ensure matrix-registration Docker image doesn't exist docker_image: diff --git a/roles/matrix-registration/tasks/validate_config.yml b/roles/matrix-registration/tasks/validate_config.yml index 90466b46c..eb140d31e 100644 --- a/roles/matrix-registration/tasks/validate_config.yml +++ b/roles/matrix-registration/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required matrix-registration settings not defined - fail: + ansible.builtin.fail: msg: > You need to define a required configuration setting (`{{ item }}`) for using matrix-registration. when: "vars[item] == ''" @@ -11,7 +11,7 @@ - "matrix_registration_server_location" - name: (Deprecation) Catch and report renamed settings - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-sygnal/defaults/main.yml b/roles/matrix-sygnal/defaults/main.yml index b19ce6141..1268d6029 100644 --- a/roles/matrix-sygnal/defaults/main.yml +++ b/roles/matrix-sygnal/defaults/main.yml @@ -69,8 +69,8 @@ matrix_sygnal_configuration_extension_yaml: | # opentracing: # enabled: true -matrix_sygnal_configuration_extension: "{{ matrix_sygnal_configuration_extension_yaml|from_yaml if matrix_sygnal_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_sygnal_configuration_extension: "{{ matrix_sygnal_configuration_extension_yaml | from_yaml if matrix_sygnal_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final sygnal configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_sygnal_configuration_yaml`. -matrix_sygnal_configuration: "{{ matrix_sygnal_configuration_yaml|from_yaml|combine(matrix_sygnal_configuration_extension, recursive=True) }}" +matrix_sygnal_configuration: "{{ matrix_sygnal_configuration_yaml | from_yaml | combine(matrix_sygnal_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-sygnal/tasks/init.yml b/roles/matrix-sygnal/tasks/init.yml index efa17a4d6..dae7a299c 100644 --- a/roles/matrix-sygnal/tasks/init.yml +++ b/roles/matrix-sygnal/tasks/init.yml @@ -1,5 +1,5 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-sygnal.service'] }}" - when: matrix_sygnal_enabled|bool + when: matrix_sygnal_enabled | bool diff --git a/roles/matrix-sygnal/tasks/main.yml b/roles/matrix-sygnal/tasks/main.yml index 385798225..b001bb825 100644 --- a/roles/matrix-sygnal/tasks/main.yml +++ b/roles/matrix-sygnal/tasks/main.yml @@ -1,23 +1,23 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool tags: - setup-all - setup-sygnal -- import_tasks: "{{ role_path }}/tasks/setup_install.yml" - when: run_setup|bool and matrix_sygnal_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: run_setup | bool and matrix_sygnal_enabled | bool tags: - setup-all - setup-sygnal -- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" - when: run_setup|bool and not matrix_sygnal_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: run_setup | bool and not matrix_sygnal_enabled | bool tags: - setup-all - setup-sygnal diff --git a/roles/matrix-sygnal/tasks/setup_install.yml b/roles/matrix-sygnal/tasks/setup_install.yml index 1a6ce186f..8f5f69377 100644 --- a/roles/matrix-sygnal/tasks/setup_install.yml +++ b/roles/matrix-sygnal/tasks/setup_install.yml @@ -12,7 +12,7 @@ until: result is not failed - name: Ensure Sygnal paths exists - file: + ansible.builtin.file: path: "{{ item }}" state: directory mode: 0750 @@ -24,21 +24,21 @@ - "{{ matrix_sygnal_data_path }}" - name: Ensure Sygnal config installed - copy: - content: "{{ matrix_sygnal_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_sygnal_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_sygnal_config_path }}/sygnal.yaml" mode: 0640 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure matrix-sygnal.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-sygnal.service.j2" dest: "{{ matrix_systemd_path }}/matrix-sygnal.service" mode: 0644 register: matrix_sygnal_systemd_service_result - name: Ensure systemd reloaded after matrix-sygnal.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_sygnal_systemd_service_result.changed|bool" + when: "matrix_sygnal_systemd_service_result.changed | bool" diff --git a/roles/matrix-sygnal/tasks/setup_uninstall.yml b/roles/matrix-sygnal/tasks/setup_uninstall.yml index 5a81a1b29..eff4a74b8 100644 --- a/roles/matrix-sygnal/tasks/setup_uninstall.yml +++ b/roles/matrix-sygnal/tasks/setup_uninstall.yml @@ -1,32 +1,32 @@ --- - name: Check existence of matrix-sygnal service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-sygnal.service" register: matrix_sygnal_service_stat - name: Ensure matrix-sygnal is stopped - service: + ansible.builtin.service: name: matrix-sygnal state: stopped enabled: false daemon_reload: true register: stopping_result - when: "matrix_sygnal_service_stat.stat.exists|bool" + when: "matrix_sygnal_service_stat.stat.exists | bool" - name: Ensure matrix-sygnal.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-sygnal.service" state: absent - when: "matrix_sygnal_service_stat.stat.exists|bool" + when: "matrix_sygnal_service_stat.stat.exists | bool" - name: Ensure systemd reloaded after matrix-sygnal.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_sygnal_service_stat.stat.exists|bool" + when: "matrix_sygnal_service_stat.stat.exists | bool" - name: Ensure Sygnal base directory doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_sygnal_base_path }}" state: absent diff --git a/roles/matrix-sygnal/tasks/validate_config.yml b/roles/matrix-sygnal/tasks/validate_config.yml index 2121edf45..b2c380109 100644 --- a/roles/matrix-sygnal/tasks/validate_config.yml +++ b/roles/matrix-sygnal/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if no Sygnal apps defined - fail: + ansible.builtin.fail: msg: >- Enabling Sygnal requires that you specify at least one app in `matrix_sygnal_apps` when: "matrix_sygnal_enabled and matrix_sygnal_apps|length == 0" diff --git a/roles/matrix-synapse-admin/tasks/init.yml b/roles/matrix-synapse-admin/tasks/init.yml index de8c00466..4d8a5eb0b 100644 --- a/roles/matrix-synapse-admin/tasks/init.yml +++ b/roles/matrix-synapse-admin/tasks/init.yml @@ -2,31 +2,31 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Element 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_synapse_admin_container_image_self_build and matrix_synapse_admin_enabled" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-synapse-admin.service'] }}" - when: matrix_synapse_admin_enabled|bool + when: matrix_synapse_admin_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Synapse Admin'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-synapse-admin role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate Synapse Admin proxying configuration for matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_synapse_admin_matrix_nginx_proxy_configuration: | rewrite ^{{ matrix_synapse_admin_public_endpoint }}$ {{ matrix_nginx_proxy_x_forwarded_proto_value }}://$server_name{{ matrix_synapse_admin_public_endpoint }}/ permanent; location ~ ^{{ matrix_synapse_admin_public_endpoint }}/(.*) { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-synapse-admin:80"; @@ -38,23 +38,23 @@ } - name: Register Synapse Admin proxying configuration with matrix-nginx-proxy - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks | default([]) + [matrix_synapse_admin_matrix_nginx_proxy_configuration] }} tags: - always - when: matrix_synapse_admin_enabled|bool + when: matrix_synapse_admin_enabled | bool - name: Warn about reverse-proxying if matrix-nginx-proxy not used - debug: + ansible.builtin.debug: msg: >- NOTE: You've enabled the Synapse Admin tool but are not using the matrix-nginx-proxy reverse proxy. Please make sure that you're proxying the `{{ matrix_synapse_admin_public_endpoint }}` URL endpoint to the matrix-synapse-admin container. You can expose the container's port using the `matrix_synapse_admin_container_http_host_bind_port` variable. - when: "matrix_synapse_admin_enabled|bool and not matrix_nginx_proxy_enabled|default(False)|bool" + when: "matrix_synapse_admin_enabled | bool and not matrix_nginx_proxy_enabled | default(False) | bool" diff --git a/roles/matrix-synapse-admin/tasks/main.yml b/roles/matrix-synapse-admin/tasks/main.yml index 0095f753a..0c6bd942c 100644 --- a/roles/matrix-synapse-admin/tasks/main.yml +++ b/roles/matrix-synapse-admin/tasks/main.yml @@ -1,16 +1,16 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool tags: - setup-all - setup-synapse-admin -- import_tasks: "{{ role_path }}/tasks/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup.yml" tags: - setup-all - setup-synapse-admin diff --git a/roles/matrix-synapse-admin/tasks/setup.yml b/roles/matrix-synapse-admin/tasks/setup.yml index f83ccdc3f..660212724 100644 --- a/roles/matrix-synapse-admin/tasks/setup.yml +++ b/roles/matrix-synapse-admin/tasks/setup.yml @@ -10,14 +10,14 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_synapse_admin_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_synapse_admin_docker_image_force_pull }}" - when: "matrix_synapse_admin_enabled|bool and not matrix_synapse_admin_container_image_self_build|bool" + when: "matrix_synapse_admin_enabled | bool and not matrix_synapse_admin_container_image_self_build | bool" register: result retries: "{{ matrix_container_retries_count }}" delay: "{{ matrix_container_retries_delay }}" until: result is not failed - name: Ensure matrix-synapse-admin repository is present when self-building - git: + ansible.builtin.git: repo: "{{ matrix_synapse_admin_container_image_self_build_repo }}" dest: "{{ matrix_synapse_admin_docker_src_files_path }}" version: "{{ matrix_synapse_admin_docker_image.split(':')[1] }}" @@ -25,7 +25,7 @@ become: true become_user: "{{ matrix_user_username }}" register: matrix_synapse_admin_git_pull_results - when: "matrix_synapse_admin_enabled|bool and matrix_synapse_admin_container_image_self_build|bool" + when: "matrix_synapse_admin_enabled | bool and matrix_synapse_admin_container_image_self_build | bool" - name: Ensure matrix-synapse-admin Docker image is built docker_image: @@ -37,52 +37,52 @@ dockerfile: Dockerfile path: "{{ matrix_synapse_admin_docker_src_files_path }}" pull: true - when: "matrix_synapse_admin_enabled|bool and matrix_synapse_admin_container_image_self_build|bool" + when: "matrix_synapse_admin_enabled | bool and matrix_synapse_admin_container_image_self_build | bool" - name: Ensure matrix-synapse-admin.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-synapse-admin.service.j2" dest: "{{ matrix_systemd_path }}/matrix-synapse-admin.service" mode: 0644 register: matrix_synapse_admin_systemd_service_result - when: matrix_synapse_admin_enabled|bool + when: matrix_synapse_admin_enabled | bool - name: Ensure systemd reloaded after matrix-synapse-admin.service installation - service: + ansible.builtin.service: daemon_reload: true - when: "matrix_synapse_admin_enabled|bool and matrix_synapse_admin_systemd_service_result.changed" + when: "matrix_synapse_admin_enabled | bool and matrix_synapse_admin_systemd_service_result.changed" # # Tasks related to getting rid of matrix-synapse-admin (if it was previously enabled) # - name: Check existence of matrix-synapse-admin service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-synapse-admin.service" register: matrix_synapse_admin_service_stat - name: Ensure matrix-synapse-admin is stopped - service: + ansible.builtin.service: name: matrix-synapse-admin state: stopped enabled: false daemon_reload: true register: stopping_result - when: "not matrix_synapse_admin_enabled|bool and matrix_synapse_admin_service_stat.stat.exists" + when: "not matrix_synapse_admin_enabled | bool and matrix_synapse_admin_service_stat.stat.exists" - name: Ensure matrix-synapse-admin.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-synapse-admin.service" state: absent - when: "not matrix_synapse_admin_enabled|bool and matrix_synapse_admin_service_stat.stat.exists" + when: "not matrix_synapse_admin_enabled | bool and matrix_synapse_admin_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-synapse-admin.service removal - service: + ansible.builtin.service: daemon_reload: true - when: "not matrix_synapse_admin_enabled|bool and matrix_synapse_admin_service_stat.stat.exists" + when: "not matrix_synapse_admin_enabled | bool and matrix_synapse_admin_service_stat.stat.exists" - name: Ensure matrix-synapse-admin Docker image doesn't exist docker_image: name: "{{ matrix_synapse_admin_docker_image }}" state: absent - when: "not matrix_synapse_admin_enabled|bool" + when: "not matrix_synapse_admin_enabled | bool" diff --git a/roles/matrix-synapse-admin/tasks/validate_config.yml b/roles/matrix-synapse-admin/tasks/validate_config.yml index 20a5c170f..bf5fe69e1 100644 --- a/roles/matrix-synapse-admin/tasks/validate_config.yml +++ b/roles/matrix-synapse-admin/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: (Deprecation) Catch and report renamed settings - fail: + ansible.builtin.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 }}`). diff --git a/roles/matrix-synapse/defaults/main.yml b/roles/matrix-synapse/defaults/main.yml index de8bfdcac..87ef3d6a6 100644 --- a/roles/matrix-synapse/defaults/main.yml +++ b/roles/matrix-synapse/defaults/main.yml @@ -521,11 +521,11 @@ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret: "" matrix_synapse_ext_password_provider_shared_secret_auth_m_login_password_support_enabled: true # We'd like to enable this, but it causes trouble for Element: https://github.com/vector-im/element-web/issues/19605 matrix_synapse_ext_password_provider_shared_secret_auth_com_devture_shared_secret_auth_support_enabled: false -matrix_synapse_ext_password_provider_shared_secret_config: "{{ matrix_synapse_ext_password_provider_shared_secret_config_yaml|from_yaml }}" +matrix_synapse_ext_password_provider_shared_secret_config: "{{ matrix_synapse_ext_password_provider_shared_secret_config_yaml | from_yaml }}" matrix_synapse_ext_password_provider_shared_secret_config_yaml: | - shared_secret: {{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret|string|to_json }} - m_login_password_support_enabled: {{ matrix_synapse_ext_password_provider_shared_secret_auth_m_login_password_support_enabled|to_json }} - com_devture_shared_secret_auth_support_enabled: {{ matrix_synapse_ext_password_provider_shared_secret_auth_com_devture_shared_secret_auth_support_enabled|to_json }} + shared_secret: {{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret | string | to_json }} + m_login_password_support_enabled: {{ matrix_synapse_ext_password_provider_shared_secret_auth_m_login_password_support_enabled | to_json }} + com_devture_shared_secret_auth_support_enabled: {{ matrix_synapse_ext_password_provider_shared_secret_auth_com_devture_shared_secret_auth_support_enabled | to_json }} # Enable this to activate LDAP password provider matrix_synapse_ext_password_provider_ldap_enabled: false @@ -586,11 +586,11 @@ matrix_synapse_ext_encryption_disabler_deny_encryption_for_rooms_of: ["{{ matrix # Enabling this may have incompatiblity consequences with servers / clients. # Familiarize yourself with the caveats upstream: https://github.com/digitalentity/matrix_encryption_disabler matrix_synapse_ext_encryption_disabler_patch_power_levels: false -matrix_synapse_ext_encryption_config: "{{ matrix_synapse_ext_encryption_config_yaml|from_yaml }}" +matrix_synapse_ext_encryption_config: "{{ matrix_synapse_ext_encryption_config_yaml | from_yaml }}" matrix_synapse_ext_encryption_config_yaml: | - deny_encryption_for_users_of: {{ matrix_synapse_ext_encryption_disabler_deny_encryption_for_users_of|to_json }} - deny_encryption_for_rooms_of: {{ matrix_synapse_ext_encryption_disabler_deny_encryption_for_rooms_of|to_json }} - patch_power_levels: {{ matrix_synapse_ext_encryption_disabler_patch_power_levels|to_json }} + deny_encryption_for_users_of: {{ matrix_synapse_ext_encryption_disabler_deny_encryption_for_users_of | to_json }} + deny_encryption_for_rooms_of: {{ matrix_synapse_ext_encryption_disabler_deny_encryption_for_rooms_of | to_json }} + patch_power_levels: {{ matrix_synapse_ext_encryption_disabler_patch_power_levels | to_json }} matrix_s3_media_store_enabled: false @@ -678,8 +678,8 @@ matrix_synapse_configuration_extension_yaml: | # system_mxid_avatar_url: "mxc://server.com/oumMVlgDnLYFaPVkExemNVVZ" # room_name: "Server Notices" -matrix_synapse_configuration_extension: "{{ matrix_synapse_configuration_extension_yaml|from_yaml if matrix_synapse_configuration_extension_yaml|from_yaml is mapping else {} }}" +matrix_synapse_configuration_extension: "{{ matrix_synapse_configuration_extension_yaml | from_yaml if matrix_synapse_configuration_extension_yaml | from_yaml is mapping else {} }}" # Holds the final Synapse configuration (a combination of the default and its extension). # You most likely don't need to touch this variable. Instead, see `matrix_synapse_configuration_yaml`. -matrix_synapse_configuration: "{{ matrix_synapse_configuration_yaml|from_yaml|combine(matrix_synapse_configuration_extension, recursive=True) }}" +matrix_synapse_configuration: "{{ matrix_synapse_configuration_yaml | from_yaml | combine(matrix_synapse_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup.yml b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup.yml index 8fda082da..e0e61df8e 100644 --- a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup.yml +++ b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup_install.yml" - when: matrix_synapse_ext_encryption_disabler_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup_install.yml" + when: matrix_synapse_ext_encryption_disabler_enabled | bool -- import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup_uninstall.yml" - when: "not matrix_synapse_ext_encryption_disabler_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup_uninstall.yml" + when: "not matrix_synapse_ext_encryption_disabler_enabled | bool" diff --git a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_install.yml b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_install.yml index cdcdd0828..00cc1650c 100644 --- a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_install.yml +++ b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Download matrix_encryption_disabler - get_url: + ansible.builtin.get_url: url: "{{ matrix_synapse_ext_encryption_disabler_download_url }}" dest: "{{ matrix_synapse_ext_path }}/matrix_e2ee_filter.py" force: true @@ -13,10 +13,10 @@ delay: "{{ matrix_geturl_retries_delay }}" until: result is not failed -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_modules: | {{ - matrix_synapse_modules|default([]) + matrix_synapse_modules | default([]) + [ { @@ -28,7 +28,7 @@ matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_synapse_ext_path }}/matrix_e2ee_filter.py,dst={{ matrix_synapse_in_container_python_packages_path }}/matrix_e2ee_filter.py,ro"] }} diff --git a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_uninstall.yml b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_uninstall.yml index a532464d8..c223f6e85 100644 --- a/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/ext/encryption-disabler/setup_uninstall.yml @@ -1,6 +1,6 @@ --- - name: Ensure matrix_encryption_disabler doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_ext_path }}/matrix_e2ee_filter.py" state: absent diff --git a/roles/matrix-synapse/tasks/ext/ldap-auth/setup.yml b/roles/matrix-synapse/tasks/ext/ldap-auth/setup.yml index b483f688a..5d648c848 100644 --- a/roles/matrix-synapse/tasks/ext/ldap-auth/setup.yml +++ b/roles/matrix-synapse/tasks/ext/ldap-auth/setup.yml @@ -1,6 +1,6 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_password_providers_enabled: true matrix_synapse_additional_loggers: > @@ -9,4 +9,4 @@ + [{'name': 'ldap_auth_provider', 'level': 'INFO'}] }} - when: matrix_synapse_ext_password_provider_ldap_enabled|bool + when: matrix_synapse_ext_password_provider_ldap_enabled | bool diff --git a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup.yml b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup.yml index 6c45f4693..1a3e097dc 100644 --- a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup.yml +++ b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup_install.yml" - when: matrix_synapse_ext_spam_checker_mjolnir_antispam_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup_install.yml" + when: matrix_synapse_ext_spam_checker_mjolnir_antispam_enabled | bool -- import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup_uninstall.yml" - when: "not matrix_synapse_ext_spam_checker_mjolnir_antispam_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup_uninstall.yml" + when: "not matrix_synapse_ext_spam_checker_mjolnir_antispam_enabled | bool" diff --git a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_install.yml b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_install.yml index 1d224bc92..3869f1aa7 100644 --- a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_install.yml +++ b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Ensure git installed (RedHat) - yum: + ansible.builtin.yum: name: - git state: present @@ -9,7 +9,7 @@ when: "ansible_os_family == 'RedHat'" - name: Ensure git installed (Debian) - apt: + ansible.builtin.apt: name: - git state: present @@ -25,14 +25,14 @@ when: "ansible_distribution == 'Archlinux'" - name: Clone mjolnir-antispam git repository - git: + ansible.builtin.git: repo: "{{ matrix_synapse_ext_spam_checker_mjolnir_antispam_git_repository_url }}" version: "{{ matrix_synapse_ext_spam_checker_mjolnir_antispam_git_version }}" dest: "{{ matrix_synapse_ext_path }}/mjolnir" become: true become_user: "{{ matrix_user_username }}" -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_spam_checker: > {{ matrix_synapse_spam_checker @@ -50,7 +50,7 @@ matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_synapse_ext_path }}/mjolnir/synapse_antispam/mjolnir,dst={{ matrix_synapse_in_container_python_packages_path }}/mjolnir,ro"] }} diff --git a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_uninstall.yml b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_uninstall.yml index f8439a873..8211d51ae 100644 --- a/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/ext/mjolnir-antispam/setup_uninstall.yml @@ -1,6 +1,6 @@ --- - name: Ensure mjolnir-antispam doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_ext_path }}/mjolnir" state: absent diff --git a/roles/matrix-synapse/tasks/ext/rest-auth/setup.yml b/roles/matrix-synapse/tasks/ext/rest-auth/setup.yml index 0270784ad..6df360ce9 100644 --- a/roles/matrix-synapse/tasks/ext/rest-auth/setup.yml +++ b/roles/matrix-synapse/tasks/ext/rest-auth/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup_install.yml" - when: matrix_synapse_ext_password_provider_rest_auth_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup_install.yml" + when: matrix_synapse_ext_password_provider_rest_auth_enabled | bool -- import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup_uninstall.yml" - when: "not matrix_synapse_ext_password_provider_rest_auth_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup_uninstall.yml" + when: "not matrix_synapse_ext_password_provider_rest_auth_enabled | bool" diff --git a/roles/matrix-synapse/tasks/ext/rest-auth/setup_install.yml b/roles/matrix-synapse/tasks/ext/rest-auth/setup_install.yml index 22ad318de..489f11405 100644 --- a/roles/matrix-synapse/tasks/ext/rest-auth/setup_install.yml +++ b/roles/matrix-synapse/tasks/ext/rest-auth/setup_install.yml @@ -1,12 +1,12 @@ --- - name: Fail if REST Auth endpoint not configured - fail: + ansible.builtin.fail: msg: "You have enabled the REST Auth password provider, but have not configured its endpoint in the `matrix_synapse_ext_password_provider_rest_auth_endpoint` variable. Consult the documentation." when: "matrix_synapse_ext_password_provider_rest_auth_endpoint == ''" - name: Download matrix-synapse-rest-auth - get_url: + ansible.builtin.get_url: url: "{{ matrix_synapse_ext_password_provider_rest_auth_download_url }}" dest: "{{ matrix_synapse_ext_path }}/rest_auth_provider.py" force: true @@ -18,12 +18,12 @@ delay: "{{ matrix_geturl_retries_delay }}" until: result is not failed -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_password_providers_enabled: true matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_synapse_ext_path }}/rest_auth_provider.py,dst={{ matrix_synapse_in_container_python_packages_path }}/rest_auth_provider.py,ro"] }} diff --git a/roles/matrix-synapse/tasks/ext/rest-auth/setup_uninstall.yml b/roles/matrix-synapse/tasks/ext/rest-auth/setup_uninstall.yml index be8ad600b..d95dd1c7c 100644 --- a/roles/matrix-synapse/tasks/ext/rest-auth/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/ext/rest-auth/setup_uninstall.yml @@ -1,6 +1,6 @@ --- - name: Ensure matrix-synapse-rest-auth doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_ext_path }}/rest_auth_provider.py" state: absent diff --git a/roles/matrix-synapse/tasks/ext/setup.yml b/roles/matrix-synapse/tasks/ext/setup.yml index 25c8809d3..d944f2574 100644 --- a/roles/matrix-synapse/tasks/ext/setup.yml +++ b/roles/matrix-synapse/tasks/ext/setup.yml @@ -1,13 +1,13 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/encryption-disabler/setup.yml" -- import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/rest-auth/setup.yml" -- import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup.yml" -- import_tasks: "{{ role_path }}/tasks/ext/ldap-auth/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/ldap-auth/setup.yml" -- import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup.yml" -- import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/mjolnir-antispam/setup.yml" diff --git a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup.yml b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup.yml index ed8d01978..6dc385d37 100644 --- a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup.yml +++ b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup_install.yml" - when: matrix_synapse_ext_password_provider_shared_secret_auth_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup_install.yml" + when: matrix_synapse_ext_password_provider_shared_secret_auth_enabled | bool -- import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup_uninstall.yml" - when: "not matrix_synapse_ext_password_provider_shared_secret_auth_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/shared-secret-auth/setup_uninstall.yml" + when: "not matrix_synapse_ext_password_provider_shared_secret_auth_enabled | bool" diff --git a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_install.yml b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_install.yml index 091b0eb2f..055d671ac 100644 --- a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_install.yml +++ b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_install.yml @@ -1,17 +1,17 @@ --- - name: Fail if Shared Secret Auth secret not set - fail: + ansible.builtin.fail: msg: "Shared Secret Auth is enabled, but no secret has been set in matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret" when: "matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret == ''" - name: Fail if no Shared Secret Auth login types enabled - fail: + ansible.builtin.fail: msg: "Shared Secret Auth is enabled, but none of the login types are" when: "not (matrix_synapse_ext_password_provider_shared_secret_auth_m_login_password_support_enabled or matrix_synapse_ext_password_provider_shared_secret_auth_com_devture_shared_secret_auth_support_enabled)" - name: Download matrix-synapse-shared-secret-auth - get_url: + ansible.builtin.get_url: url: "{{ matrix_synapse_ext_password_provider_shared_secret_auth_download_url }}" dest: "{{ matrix_synapse_ext_path }}/shared_secret_authenticator.py" force: true @@ -23,10 +23,10 @@ delay: "{{ matrix_geturl_retries_delay }}" until: result is not failed -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_modules: | {{ - matrix_synapse_modules|default([]) + matrix_synapse_modules | default([]) + [ { @@ -38,7 +38,7 @@ matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_synapse_ext_path }}/shared_secret_authenticator.py,dst={{ matrix_synapse_in_container_python_packages_path }}/shared_secret_authenticator.py,ro"] }} diff --git a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_uninstall.yml b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_uninstall.yml index e564909e7..b2f909443 100644 --- a/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/ext/shared-secret-auth/setup_uninstall.yml @@ -1,6 +1,6 @@ --- - name: Ensure matrix-synapse-shared-secret-auth doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_ext_path }}/shared_secret_authenticator.py" state: absent diff --git a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup.yml b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup.yml index efd4a0271..038eea749 100644 --- a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup.yml +++ b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup_install.yml" - when: matrix_synapse_ext_spam_checker_synapse_simple_antispam_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup_install.yml" + when: matrix_synapse_ext_spam_checker_synapse_simple_antispam_enabled | bool -- import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup_uninstall.yml" - when: "not matrix_synapse_ext_spam_checker_synapse_simple_antispam_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/synapse-simple-antispam/setup_uninstall.yml" + when: "not matrix_synapse_ext_spam_checker_synapse_simple_antispam_enabled | bool" diff --git a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_install.yml b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_install.yml index 579a707c6..23a382f26 100644 --- a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_install.yml +++ b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_install.yml @@ -1,12 +1,12 @@ --- - name: Fail if Synapse Simple Antispam blocked homeservers is not set - fail: + ansible.builtin.fail: msg: "Synapse Simple Antispam is enabled, but no blocked homeservers have been set in matrix_synapse_ext_spam_checker_synapse_simple_antispam_config_blocked_homeservers" when: "matrix_synapse_ext_spam_checker_synapse_simple_antispam_config_blocked_homeservers|length == 0" - name: Ensure git installed (RedHat) - yum: + ansible.builtin.yum: name: - git state: present @@ -14,7 +14,7 @@ when: "ansible_os_family == 'RedHat'" - name: Ensure git installed (Debian) - apt: + ansible.builtin.apt: name: - git state: present @@ -30,14 +30,14 @@ when: "ansible_distribution == 'Archlinux'" - name: Clone synapse-simple-antispam git repository - git: + ansible.builtin.git: repo: "{{ matrix_synapse_ext_spam_checker_synapse_simple_antispam_git_repository_url }}" version: "{{ matrix_synapse_ext_spam_checker_synapse_simple_antispam_git_version }}" dest: "{{ matrix_synapse_ext_path }}/synapse-simple-antispam" become: true become_user: "{{ matrix_user_username }}" -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_modules: > {{ matrix_synapse_modules @@ -52,7 +52,7 @@ matrix_synapse_container_extra_arguments: > {{ - matrix_synapse_container_extra_arguments|default([]) + matrix_synapse_container_extra_arguments | default([]) + ["--mount type=bind,src={{ matrix_synapse_ext_path }}/synapse-simple-antispam/synapse_simple_antispam,dst={{ matrix_synapse_in_container_python_packages_path }}/synapse_simple_antispam,ro"] }} diff --git a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_uninstall.yml b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_uninstall.yml index 14cefc72d..b1d558aa5 100644 --- a/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/ext/synapse-simple-antispam/setup_uninstall.yml @@ -1,6 +1,6 @@ --- - name: Ensure synapse-simple-antispam doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_ext_path }}/synapse-simple-antispam" state: absent diff --git a/roles/matrix-synapse/tasks/goofys/setup.yml b/roles/matrix-synapse/tasks/goofys/setup.yml index 6370408d0..2f9eaa870 100644 --- a/roles/matrix-synapse/tasks/goofys/setup.yml +++ b/roles/matrix-synapse/tasks/goofys/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/goofys/setup_install.yml" - when: matrix_s3_media_store_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/goofys/setup_install.yml" + when: matrix_s3_media_store_enabled | bool -- import_tasks: "{{ role_path }}/tasks/goofys/setup_uninstall.yml" - when: "not matrix_s3_media_store_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/goofys/setup_uninstall.yml" + when: "not matrix_s3_media_store_enabled | bool" diff --git a/roles/matrix-synapse/tasks/goofys/setup_install.yml b/roles/matrix-synapse/tasks/goofys/setup_install.yml index d37815203..e3c341502 100644 --- a/roles/matrix-synapse/tasks/goofys/setup_install.yml +++ b/roles/matrix-synapse/tasks/goofys/setup_install.yml @@ -1,6 +1,6 @@ --- -- import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_fuse_installed.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_fuse_installed.yml" - name: Ensure Goofys Docker image is pulled docker_image: @@ -15,13 +15,13 @@ # This will throw a Permission Denied error if already mounted - name: Check Matrix Goofys external storage mountpoint path - stat: + ansible.builtin.stat: path: "{{ matrix_s3_media_store_path }}" register: local_path_matrix_s3_media_store_path_stat ignore_errors: true - name: Ensure Matrix Goofys external storage mountpoint exists - file: + ansible.builtin.file: path: "{{ matrix_s3_media_store_path }}" state: directory mode: 0750 @@ -30,20 +30,20 @@ when: "not local_path_matrix_s3_media_store_path_stat.failed and not local_path_matrix_s3_media_store_path_stat.stat.exists" - name: Ensure goofys environment variables file created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/goofys/env-goofys.j2" dest: "{{ matrix_synapse_config_dir_path }}/env-goofys" owner: root mode: 0600 - name: Ensure matrix-goofys.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/goofys/systemd/matrix-goofys.service.j2" dest: "{{ matrix_systemd_path }}/matrix-goofys.service" mode: 0644 register: matrix_goofys_systemd_service_result - name: Ensure systemd reloaded after matrix-goofys.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_goofys_systemd_service_result.changed" diff --git a/roles/matrix-synapse/tasks/goofys/setup_uninstall.yml b/roles/matrix-synapse/tasks/goofys/setup_uninstall.yml index c00206eff..da78003f5 100644 --- a/roles/matrix-synapse/tasks/goofys/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/goofys/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-goofys service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-goofys.service" register: matrix_goofys_service_stat - name: Ensure matrix-goofys is stopped - service: + ansible.builtin.service: name: matrix-goofys state: stopped enabled: false @@ -15,18 +15,18 @@ when: "matrix_goofys_service_stat.stat.exists" - name: Ensure matrix-goofys.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-goofys.service" state: absent when: "matrix_goofys_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-goofys.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_goofys_service_stat.stat.exists" - name: Ensure goofys environment variables file doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_config_dir_path }}/env-goofys" state: absent diff --git a/roles/matrix-synapse/tasks/import_media_store.yml b/roles/matrix-synapse/tasks/import_media_store.yml index 8e9626806..133debe33 100644 --- a/roles/matrix-synapse/tasks/import_media_store.yml +++ b/roles/matrix-synapse/tasks/import_media_store.yml @@ -3,37 +3,37 @@ # Pre-checks - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `server_path_media_store` variable needs to be provided to this playbook, via --extra-vars" when: "server_path_media_store is not defined or server_path_media_store.startswith('<')" - name: Fail if media store is on Amazon S3 - fail: + ansible.builtin.fail: msg: "Your media store is on Amazon S3. Due to technical limitations, restoring is not supported." - when: matrix_s3_media_store_enabled|bool + when: matrix_s3_media_store_enabled | bool - name: Check if the provided media store directory exists - stat: + ansible.builtin.stat: path: "{{ server_path_media_store }}" register: server_path_media_store_stat - name: Fail if provided media store directory doesn't exist on the server - fail: + ansible.builtin.fail: msg: "{{ server_path_media_store }} cannot be found on the server" when: "not server_path_media_store_stat.stat.exists or not server_path_media_store_stat.stat.isdir" - name: Check if media store contains local_content - stat: + ansible.builtin.stat: path: "{{ server_path_media_store }}/local_content" register: server_path_media_store_local_content_stat - name: Check if media store contains remote_content - stat: + ansible.builtin.stat: path: "{{ server_path_media_store }}/remote_content" register: server_path_media_store_remote_content_stat - name: Fail if media store directory doesn't look okay (lacking remote and local content) - fail: + ansible.builtin.fail: msg: "{{ server_path_media_store }} contains neither local_content nor remote_content directories. It's most likely a mistake and is not a media store directory." when: "not server_path_media_store_local_content_stat.stat.exists and not server_path_media_store_remote_content_stat.stat.exists" @@ -41,7 +41,7 @@ # Actual import work - name: Ensure matrix-synapse is stopped - service: + ansible.builtin.service: name: matrix-synapse state: stopped enabled: false @@ -57,25 +57,25 @@ delete: true # It's wasteful to preserve owner/group now. We chown below anyway. owner: false - group: false + ansible.builtin.group: false times: true delegate_to: "{{ inventory_hostname }}" # This is for the generic case and fails in other cases (remote file systems), # because in such cases the base path (matrix_synapse_media_store_path) is a mount point. - name: Ensure media store permissions are correct (generic case) - file: + ansible.builtin.file: path: "{{ matrix_synapse_media_store_path }}" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" recurse: true - when: "not matrix_s3_media_store_enabled|bool" + when: "not matrix_s3_media_store_enabled | bool" # We don't chown for Goofys, because due to the way it's mounted, # all files become owned by whoever needs to own them. - name: Ensure Synapse is started (if it previously was) - service: + ansible.builtin.service: name: "{{ item }}" state: started daemon_reload: true diff --git a/roles/matrix-synapse/tasks/init.yml b/roles/matrix-synapse/tasks/init.yml index ffaec05fd..77696bced 100644 --- a/roles/matrix-synapse/tasks/init.yml +++ b/roles/matrix-synapse/tasks/init.yml @@ -2,45 +2,45 @@ # 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 - fail: + ansible.builtin.fail: msg: "To self-build the Synapse 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_synapse_container_image_self_build and matrix_synapse_enabled" # Unless `matrix_synapse_workers_enabled_list` is explicitly defined, # we'll generate it dynamically. -- import_tasks: "{{ role_path }}/tasks/synapse/workers/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/synapse/workers/init.yml" when: "matrix_synapse_enabled and matrix_synapse_workers_enabled and matrix_synapse_workers_enabled_list|length == 0" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-synapse.service'] }}" - when: matrix_synapse_enabled|bool + when: matrix_synapse_enabled | bool - name: Ensure systemd services for workers are injected - include_tasks: "{{ role_path }}/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml" with_items: "{{ matrix_synapse_workers_enabled_list }}" loop_control: loop_var: matrix_synapse_worker_details - when: matrix_synapse_enabled|bool and matrix_synapse_workers_enabled|bool + when: matrix_synapse_enabled | bool and matrix_synapse_workers_enabled | bool -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-goofys.service'] }}" - when: matrix_s3_media_store_enabled|bool + when: matrix_s3_media_store_enabled | bool - block: - name: Fail if matrix-nginx-proxy role already executed - fail: + ansible.builtin.fail: msg: >- Trying to append Synapse'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-synapse role. - when: matrix_nginx_proxy_role_executed|default(False)|bool + when: matrix_nginx_proxy_role_executed | default(False) | bool - name: Generate synapse metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/synapse/main-process) - set_fact: + ansible.builtin.set_fact: matrix_synapse_nginx_metrics_configuration_block: | location /metrics/synapse/main-process { - {% if matrix_nginx_proxy_enabled|default(False) %} + {% 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-synapse:{{ matrix_synapse_metrics_port }}"; @@ -52,16 +52,16 @@ } - name: Register synapse metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/synapse/main-process) - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + [matrix_synapse_nginx_metrics_configuration_block] }} - name: Generate synapse worker metrics proxying configuration for matrix-nginx-proxy (matrix.DOMAIN/metrics/synapse/worker) - set_fact: + ansible.builtin.set_fact: matrix_synapse_worker_nginx_metrics_configuration_block: | {% for worker in matrix_synapse_workers_enabled_list %} {% if worker.metrics_port != 0 %} @@ -76,12 +76,12 @@ when: matrix_synapse_workers_enabled_list|length > 0 - name: Register synapse worker metrics proxying configuration with matrix-nginx-proxy (matrix.DOMAIN/metrics/synapse/worker) - set_fact: + ansible.builtin.set_fact: matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks: | {{ - matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks|default([]) + matrix_nginx_proxy_proxy_matrix_metrics_additional_system_location_configuration_blocks | default([]) + [matrix_synapse_worker_nginx_metrics_configuration_block] }} when: matrix_synapse_workers_enabled_list|length > 0 - when: matrix_synapse_enabled|bool and matrix_synapse_metrics_proxying_enabled|bool + when: matrix_synapse_enabled | bool and matrix_synapse_metrics_proxying_enabled | bool diff --git a/roles/matrix-synapse/tasks/main.yml b/roles/matrix-synapse/tasks/main.yml index 552358434..7068dcefc 100644 --- a/roles/matrix-synapse/tasks/main.yml +++ b/roles/matrix-synapse/tasks/main.yml @@ -1,57 +1,57 @@ --- -- import_tasks: "{{ role_path }}/tasks/init.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml" tags: - always -- import_tasks: "{{ role_path }}/tasks/validate_config.yml" - when: run_setup|bool and matrix_synapse_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: run_setup | bool and matrix_synapse_enabled | bool tags: - setup-all - setup-synapse -- import_tasks: "{{ role_path }}/tasks/setup_synapse.yml" - when: run_setup|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_synapse.yml" + when: run_setup | bool tags: - setup-all - setup-synapse -- import_tasks: "{{ role_path }}/tasks/import_media_store.yml" - when: run_synapse_import_media_store|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/import_media_store.yml" + when: run_synapse_import_media_store | bool tags: - import-synapse-media-store -- import_tasks: "{{ role_path }}/tasks/register_user.yml" - when: run_synapse_register_user|bool and matrix_synapse_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/register_user.yml" + when: run_synapse_register_user | bool and matrix_synapse_enabled | bool tags: - register-user -- import_tasks: "{{ role_path }}/tasks/self_check_client_api.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_client_api.yml" delegate_to: 127.0.0.1 become: false - when: run_self_check|bool + when: run_self_check | bool tags: - self-check -- import_tasks: "{{ role_path }}/tasks/self_check_federation_api.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/self_check_federation_api.yml" delegate_to: 127.0.0.1 become: false - when: run_self_check|bool + when: run_self_check | bool tags: - self-check -- import_tasks: "{{ role_path }}/tasks/update_user_password.yml" - when: run_synapse_update_user_password|bool and matrix_synapse_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/update_user_password.yml" + when: run_synapse_update_user_password | bool and matrix_synapse_enabled | bool tags: - update-user-password -- import_tasks: "{{ role_path }}/tasks/rust-synapse-compress-state/main.yml" - when: run_synapse_rust_synapse_compress_state|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/rust-synapse-compress-state/main.yml" + when: run_synapse_rust_synapse_compress_state | bool tags: - rust-synapse-compress-state - name: Mark matrix-synapse role as executed - set_fact: + ansible.builtin.set_fact: matrix_synapse_role_executed: true tags: - always diff --git a/roles/matrix-synapse/tasks/register_user.yml b/roles/matrix-synapse/tasks/register_user.yml index 2a1c57082..8c344b2de 100644 --- a/roles/matrix-synapse/tasks/register_user.yml +++ b/roles/matrix-synapse/tasks/register_user.yml @@ -1,31 +1,33 @@ --- - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `username` variable needs to be provided to this playbook, via --extra-vars" when: "username is not defined or username == ''" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `password` variable needs to be provided to this playbook, via --extra-vars" when: "password is not defined or password == ''" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `admin` variable needs to be provided to this playbook, via --extra-vars" when: "admin is not defined or admin not in ['yes', 'no']" - name: Ensure matrix-synapse is started - service: + ansible.builtin.service: name: matrix-synapse state: started daemon_reload: true register: start_result - name: Wait a while, so that Synapse can manage to start - pause: + ansible.builtin.pause: seconds: 7 when: "start_result.changed" - name: Register user - command: "{{ matrix_local_bin_path }}/matrix-synapse-register-user {{ username|quote }} {{ password|quote }} {{ '1' if admin == 'yes' else '0' }}" + ansible.builtin.command: "{{ matrix_local_bin_path }}/matrix-synapse-register-user {{ username|quote }} {{ password|quote }} {{ '1' if admin == 'yes' else '0' }}" + register: matrix_synapse_register_user_result + changed_when: matrix_synapse_register_user_result.rc == 0 diff --git a/roles/matrix-synapse/tasks/rust-synapse-compress-state/compress_room.yml b/roles/matrix-synapse/tasks/rust-synapse-compress-state/compress_room.yml index e1386c752..221a75700 100644 --- a/roles/matrix-synapse/tasks/rust-synapse-compress-state/compress_room.yml +++ b/roles/matrix-synapse/tasks/rust-synapse-compress-state/compress_room.yml @@ -1,10 +1,10 @@ --- -- debug: +- ansible.builtin.debug: msg: "Compressing room `{{ room_details.room_id }}` having {{ room_details.count }} state group rows" - name: Generate rust-synapse-compress-state room compression command - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_compress_room_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-rust-synapse-compress-state-compress-room --user={{ matrix_user_uid }}:{{ matrix_user_gid }} @@ -17,15 +17,16 @@ -r '{{ room_details.room_id }}' - name: Run rust-synapse-compress-state room compression command (SQL generation) - command: "{{ matrix_synapse_rust_synapse_compress_state_compress_room_command }}" + ansible.builtin.command: "{{ matrix_synapse_rust_synapse_compress_state_compress_room_command }}" async: "{{ matrix_synapse_rust_synapse_compress_state_compress_room_time }}" poll: 10 register: matrix_synapse_rust_synapse_compress_state_compress_room_command_result + changed_when: matrix_synapse_rust_synapse_compress_state_compress_room_command_result.rc == 0 -- debug: var="matrix_synapse_rust_synapse_compress_state_compress_room_command_result" +- ansible.builtin.debug: var="matrix_synapse_rust_synapse_compress_state_compress_room_command_result" - name: Generate Postgres compression SQL import command - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_psql_import_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-rust-synapse-compress-state-psql-import --user={{ matrix_user_uid }}:{{ matrix_user_gid }} @@ -39,12 +40,13 @@ psql -v ON_ERROR_STOP=1 -h matrix-postgres -d {{ matrix_synapse_database_database }}" - name: Import compression SQL into Postgres - command: "{{ matrix_synapse_rust_synapse_compress_state_psql_import_command }}" + ansible.builtin.command: "{{ matrix_synapse_rust_synapse_compress_state_psql_import_command }}" async: "{{ matrix_synapse_rust_synapse_compress_state_psql_import_time }}" poll: 10 register: matrix_synapse_rust_synapse_compress_state_psql_import_command_result + changed_when: matrix_synapse_rust_synapse_compress_state_psql_import_command_result.rc == 0 - name: Clean up - file: + ansible.builtin.file: path: "{{ matrix_synapse_rust_synapse_compress_state_base_path }}/state-compressor.sql" state: absent diff --git a/roles/matrix-synapse/tasks/rust-synapse-compress-state/main.yml b/roles/matrix-synapse/tasks/rust-synapse-compress-state/main.yml index 219f1c986..fcea86064 100644 --- a/roles/matrix-synapse/tasks/rust-synapse-compress-state/main.yml +++ b/roles/matrix-synapse/tasks/rust-synapse-compress-state/main.yml @@ -2,40 +2,40 @@ # Pre-checks - name: Fail if Postgres not enabled - fail: + ansible.builtin.fail: msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot use rust-synapse-compress-state." - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" # Defaults - name: Set matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time, if not provided - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time: 1800 - when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time|default('') == ''" + when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time | default('') == ''" - name: Set matrix_synapse_rust_synapse_compress_state_compress_room_time, if not provided - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_compress_room_time: 3600 - when: "matrix_synapse_rust_synapse_compress_state_compress_room_time|default('') == ''" + when: "matrix_synapse_rust_synapse_compress_state_compress_room_time | default('') == ''" - name: Set matrix_synapse_rust_synapse_compress_state_psql_import_time, if not provided - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_psql_import_time: 3600 - when: "matrix_synapse_rust_synapse_compress_state_psql_import_time|default('') == ''" + when: "matrix_synapse_rust_synapse_compress_state_psql_import_time | default('') == ''" - name: Set matrix_synapse_rust_synapse_compress_state_min_state_groups_required, if not provided - set_fact: + ansible.builtin.set_fact: # The minimum number of state groups we're looking for before we consider a room eligible for compression. # Rooms with a smaller state groups count will not be compressed. matrix_synapse_rust_synapse_compress_state_min_state_groups_required: 100000 - when: "matrix_synapse_rust_synapse_compress_state_min_state_groups_required|default('') == ''" + when: "matrix_synapse_rust_synapse_compress_state_min_state_groups_required | default('') == ''" # Actual compression work - name: Ensure rust-synapse-compress-state paths exist - file: + ansible.builtin.file: path: "{{ matrix_synapse_rust_synapse_compress_state_base_path }}" state: directory mode: 0750 @@ -54,7 +54,7 @@ until: result is not failed - name: Generate rust-synapse-compress-state room find command - set_fact: + ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_find_rooms_command: >- {{ matrix_host_command_docker }} run --rm --name matrix-rust-synapse-compress-state-find-rooms --user={{ matrix_user_uid }}:{{ matrix_user_gid }} @@ -66,10 +66,11 @@ 'SELECT array_to_json(array_agg(row_to_json (r))) FROM (SELECT room_id, count(*) AS count FROM state_groups_state GROUP BY room_id HAVING count(*) > {{ matrix_synapse_rust_synapse_compress_state_min_state_groups_required }} ORDER BY count DESC) r;' - name: Find rooms eligible for compression with rust-synapse-compress-state - command: "{{ matrix_synapse_rust_synapse_compress_state_find_rooms_command }}" + ansible.builtin.command: "{{ matrix_synapse_rust_synapse_compress_state_find_rooms_command }}" async: "{{ matrix_synapse_rust_synapse_compress_state_find_rooms_command_wait_time }}" poll: 10 register: matrix_synapse_rust_synapse_compress_state_find_rooms_command_result + changed_when: false # We expect the output to be like this: # @@ -85,10 +86,10 @@ # Row 3 contains a space when there's no result. - block: - - debug: var="matrix_synapse_rust_synapse_compress_state_find_rooms_command_result" + - ansible.builtin.debug: var="matrix_synapse_rust_synapse_compress_state_find_rooms_command_result" - name: Fail if room find result is not what we expect - fail: + ansible.builtin.fail: msg: >- Expecting 4 lines in the "find rooms" result. when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.failed or matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.stdout_lines|length != 4" @@ -96,11 +97,11 @@ - block: # matrix_synapse_rust_synapse_compress_state_eligible_rooms is a list # of dictionaries like this: {'room_id': '!some-id', 'count': 2461329} - - set_fact: + - ansible.builtin.set_fact: matrix_synapse_rust_synapse_compress_state_eligible_rooms: "{{ matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.stdout_lines[2] | from_json }}" - name: Display rooms that will be compressed - debug: + ansible.builtin.debug: msg: >- The following rooms contain more than {{ matrix_synapse_rust_synapse_compress_state_min_state_groups_required }} state group rows (configurable via `matrix_synapse_rust_synapse_compress_state_min_state_groups_required`) @@ -108,14 +109,14 @@ {{ matrix_synapse_rust_synapse_compress_state_eligible_rooms }} - name: Compress room state - include_tasks: "{{ role_path }}/tasks/rust-synapse-compress-state/compress_room.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/rust-synapse-compress-state/compress_room.yml" with_items: "{{ matrix_synapse_rust_synapse_compress_state_eligible_rooms }}" loop_control: loop_var: room_details when: "matrix_synapse_rust_synapse_compress_state_find_rooms_command_result.stdout_lines[2] != ' '" - name: Show notice about lack of rooms to compress - debug: + ansible.builtin.debug: msg: >- No rooms were found to contain more than {{ matrix_synapse_rust_synapse_compress_state_min_state_groups_required }} state group rows (configurable via `matrix_synapse_rust_synapse_compress_state_min_state_groups_required`), diff --git a/roles/matrix-synapse/tasks/self_check_client_api.yml b/roles/matrix-synapse/tasks/self_check_client_api.yml index 407a79ff6..1c03ba5b0 100644 --- a/roles/matrix-synapse/tasks/self_check_client_api.yml +++ b/roles/matrix-synapse/tasks/self_check_client_api.yml @@ -1,21 +1,21 @@ --- - name: Check Matrix Client API - uri: + ansible.builtin.uri: url: "{{ matrix_synapse_client_api_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_synapse_self_check_validate_certificates }}" register: result_matrix_synapse_client_api ignore_errors: true check_mode: false - when: matrix_synapse_enabled|bool + when: matrix_synapse_enabled | bool - name: Fail if Matrix Client API not working - fail: + ansible.builtin.fail: msg: "Failed checking Matrix Client API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_synapse_client_api_url_endpoint_public }}`). Is Synapse running? Is port 443 open in your firewall? Full error: {{ result_matrix_synapse_client_api }}" - when: "matrix_synapse_enabled|bool and (result_matrix_synapse_client_api.failed or 'json' not in result_matrix_synapse_client_api)" + when: "matrix_synapse_enabled | bool and (result_matrix_synapse_client_api.failed or 'json' not in result_matrix_synapse_client_api)" - name: Report working Matrix Client API - debug: + ansible.builtin.debug: msg: "The Matrix Client API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_synapse_client_api_url_endpoint_public }}`) is working" - when: matrix_synapse_enabled|bool + when: matrix_synapse_enabled | bool diff --git a/roles/matrix-synapse/tasks/self_check_federation_api.yml b/roles/matrix-synapse/tasks/self_check_federation_api.yml index 322493721..80ec4fc21 100644 --- a/roles/matrix-synapse/tasks/self_check_federation_api.yml +++ b/roles/matrix-synapse/tasks/self_check_federation_api.yml @@ -1,26 +1,26 @@ --- - name: Check Matrix Federation API - uri: + ansible.builtin.uri: url: "{{ matrix_synapse_federation_api_url_endpoint_public }}" follow_redirects: none validate_certs: "{{ matrix_synapse_self_check_validate_certificates }}" register: result_matrix_synapse_federation_api ignore_errors: true check_mode: false - when: matrix_synapse_enabled|bool + when: matrix_synapse_enabled | bool - name: Fail if Matrix Federation API not working - fail: + ansible.builtin.fail: msg: "Failed checking Matrix Federation API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_synapse_federation_api_url_endpoint_public }}`). Is Synapse running? Is port {{ matrix_federation_public_port }} open in your firewall? Full error: {{ result_matrix_synapse_federation_api }}" - when: "matrix_synapse_enabled|bool and matrix_synapse_federation_enabled|bool and (result_matrix_synapse_federation_api.failed or 'json' not in result_matrix_synapse_federation_api)" + when: "matrix_synapse_enabled | bool and matrix_synapse_federation_enabled | bool and (result_matrix_synapse_federation_api.failed or 'json' not in result_matrix_synapse_federation_api)" - name: Fail if Matrix Federation API unexpectedly enabled - fail: + ansible.builtin.fail: msg: "Matrix Federation API is up at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_synapse_federation_api_url_endpoint_public }}`) despite being disabled." - when: "matrix_synapse_enabled|bool and not matrix_synapse_federation_enabled|bool and not result_matrix_synapse_federation_api.failed" + when: "matrix_synapse_enabled | bool and not matrix_synapse_federation_enabled | bool and not result_matrix_synapse_federation_api.failed" - name: Report working Matrix Federation API - debug: + ansible.builtin.debug: msg: "The Matrix Federation API at `{{ matrix_server_fqn_matrix }}` (checked endpoint: `{{ matrix_synapse_federation_api_url_endpoint_public }}`) is working" - when: "matrix_synapse_enabled|bool and matrix_synapse_federation_enabled|bool" + when: "matrix_synapse_enabled | bool and matrix_synapse_federation_enabled | bool" diff --git a/roles/matrix-synapse/tasks/setup_synapse.yml b/roles/matrix-synapse/tasks/setup_synapse.yml index 47e404f41..d4e6ae95a 100644 --- a/roles/matrix-synapse/tasks/setup_synapse.yml +++ b/roles/matrix-synapse/tasks/setup_synapse.yml @@ -1,7 +1,7 @@ --- - name: Ensure Synapse paths exist - file: + ansible.builtin.file: path: "{{ item.path }}" state: directory mode: 0750 @@ -14,12 +14,12 @@ # We handle matrix_synapse_media_store_path elsewhere (in ./synapse/setup_install.yml), # because if it's using Goofys and it's already mounted (from before), # trying to chown/chmod it here will cause trouble. - when: "(matrix_synapse_enabled|bool or matrix_s3_media_store_enabled|bool) and item.when" + when: "(matrix_synapse_enabled | bool or matrix_s3_media_store_enabled | bool) and item.when" -- import_tasks: "{{ role_path }}/tasks/ext/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/ext/setup.yml" -- import_tasks: "{{ role_path }}/tasks/synapse/workers/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/synapse/workers/setup.yml" -- import_tasks: "{{ role_path }}/tasks/synapse/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/synapse/setup.yml" -- import_tasks: "{{ role_path }}/tasks/goofys/setup.yml" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/goofys/setup.yml" diff --git a/roles/matrix-synapse/tasks/synapse/setup.yml b/roles/matrix-synapse/tasks/synapse/setup.yml index b5d27c36c..80f761e59 100644 --- a/roles/matrix-synapse/tasks/synapse/setup.yml +++ b/roles/matrix-synapse/tasks/synapse/setup.yml @@ -1,7 +1,7 @@ --- -- import_tasks: "{{ role_path }}/tasks/synapse/setup_install.yml" - when: matrix_synapse_enabled|bool +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/synapse/setup_install.yml" + when: matrix_synapse_enabled | bool -- import_tasks: "{{ role_path }}/tasks/synapse/setup_uninstall.yml" - when: "not matrix_synapse_enabled|bool" +- ansible.builtin.import_tasks: "{{ role_path }}/tasks/synapse/setup_uninstall.yml" + when: "not matrix_synapse_enabled | bool" diff --git a/roles/matrix-synapse/tasks/synapse/setup_install.yml b/roles/matrix-synapse/tasks/synapse/setup_install.yml index 1aaaf7b3f..e4ec0f670 100644 --- a/roles/matrix-synapse/tasks/synapse/setup_install.yml +++ b/roles/matrix-synapse/tasks/synapse/setup_install.yml @@ -2,7 +2,7 @@ # This will throw a Permission Denied error if already mounted using fuse - name: Check Synapse media store path - stat: + ansible.builtin.stat: path: "{{ matrix_synapse_media_store_path }}" register: local_path_media_store_stat ignore_errors: true @@ -10,7 +10,7 @@ # This is separate and conditional, to ensure we don't execute it # if the path already exists or we failed to check, because it's mounted using fuse. - name: Ensure Synapse media store path exists - file: + ansible.builtin.file: path: "{{ matrix_synapse_media_store_path }}" state: directory mode: 0750 @@ -20,7 +20,7 @@ - block: - name: Ensure Synapse repository is present on self-build - git: + ansible.builtin.git: repo: "{{ matrix_synapse_container_image_self_build_repo }}" dest: "{{ matrix_synapse_docker_src_files_path }}" version: "{{ matrix_synapse_docker_image.split(':')[1] }}" @@ -30,14 +30,15 @@ register: matrix_synapse_git_pull_results - name: Check if Synapse Docker image exists - command: "{{ matrix_host_command_docker }} images --quiet --filter 'reference={{ matrix_synapse_docker_image }}'" + ansible.builtin.command: "{{ matrix_host_command_docker }} images --quiet --filter 'reference={{ matrix_synapse_docker_image }}'" register: matrix_synapse_docker_image_check_result + changed_when: false # Invoking the `docker build` command here, instead of calling the `docker_image` Ansible module, # because the latter does not support BuildKit. # See: https://github.com/ansible-collections/community.general/issues/514 - name: Ensure Synapse Docker image is built - shell: + ansible.builtin.shell: chdir: "{{ matrix_synapse_docker_src_files_path }}" cmd: | {{ matrix_host_command_docker }} build \ @@ -46,8 +47,8 @@ . environment: DOCKER_BUILDKIT: 1 - when: "matrix_synapse_git_pull_results.changed|bool or matrix_synapse_docker_image_check_result.stdout == ''" - when: "matrix_synapse_container_image_self_build|bool" + when: "matrix_synapse_git_pull_results.changed | bool or matrix_synapse_docker_image_check_result.stdout == ''" + when: "matrix_synapse_container_image_self_build | bool" - name: Ensure Synapse Docker image is pulled docker_image: @@ -62,7 +63,7 @@ until: result is not failed - name: Check if a Synapse signing key exists - stat: + ansible.builtin.stat: path: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.signing.key" register: matrix_synapse_signing_key_stat @@ -74,7 +75,7 @@ # We don't use the `docker_container` module, because using it with `cap_drop` requires # a very recent docker-py version, which is not available for a lot of people yet. - name: Generate initial Synapse config and signing key - command: | + ansible.builtin.command: | docker run --rm --name=matrix-config @@ -89,42 +90,42 @@ when: "not matrix_synapse_signing_key_stat.stat.exists" - name: Ensure Synapse homeserver config installed - copy: - content: "{{ matrix_synapse_configuration|to_nice_yaml(indent=2, width=999999) }}" + ansible.builtin.copy: + content: "{{ matrix_synapse_configuration | to_nice_yaml(indent=2, width=999999) }}" dest: "{{ matrix_synapse_config_dir_path }}/homeserver.yaml" mode: 0644 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - name: Ensure Synapse log config installed - template: + ansible.builtin.template: src: "{{ matrix_synapse_template_synapse_log }}" dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_server_fqn_matrix }}.log.config" mode: 0644 - name: Ensure matrix-synapse.service installed - template: + ansible.builtin.template: src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse.service.j2" dest: "{{ matrix_systemd_path }}/matrix-synapse.service" mode: 0644 register: matrix_synapse_systemd_service_result - name: Ensure systemd reloaded after matrix-synapse.service installation - service: + ansible.builtin.service: daemon_reload: true when: "matrix_synapse_systemd_service_result.changed" - name: Ensure matrix-synapse-register-user script created - template: + ansible.builtin.template: src: "{{ role_path }}/templates/synapse/usr-local-bin/matrix-synapse-register-user.j2" dest: "{{ matrix_local_bin_path }}/matrix-synapse-register-user" mode: 0755 - name: Generate sample prometheus.yml for external scraping - template: + ansible.builtin.template: src: "{{ role_path }}/templates/synapse/prometheus/external_prometheus.yml.example.j2" dest: "{{ matrix_synapse_base_path }}/external_prometheus.yml.example" owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" mode: 0644 - when: matrix_synapse_metrics_proxying_enabled|bool + when: matrix_synapse_metrics_proxying_enabled | bool diff --git a/roles/matrix-synapse/tasks/synapse/setup_uninstall.yml b/roles/matrix-synapse/tasks/synapse/setup_uninstall.yml index 1d4fe7ad2..17b1b8c45 100644 --- a/roles/matrix-synapse/tasks/synapse/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/synapse/setup_uninstall.yml @@ -1,12 +1,12 @@ --- - name: Check existence of matrix-synapse service - stat: + ansible.builtin.stat: path: "{{ matrix_systemd_path }}/matrix-synapse.service" register: matrix_synapse_service_stat - name: Ensure matrix-synapse is stopped - service: + ansible.builtin.service: name: matrix-synapse state: stopped enabled: false @@ -15,13 +15,13 @@ when: "matrix_synapse_service_stat.stat.exists" - name: Ensure matrix-synapse.service doesn't exist - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-synapse.service" state: absent when: "matrix_synapse_service_stat.stat.exists" - name: Ensure systemd reloaded after matrix-synapse.service removal - service: + ansible.builtin.service: daemon_reload: true when: "matrix_synapse_service_stat.stat.exists" @@ -31,7 +31,7 @@ state: absent - name: Ensure sample prometheus.yml for external scraping is deleted - file: + ansible.builtin.file: path: "{{ matrix_synapse_base_path }}/external_prometheus.yml.example" state: absent - when: "not matrix_synapse_metrics_proxying_enabled|bool" + when: "not matrix_synapse_metrics_proxying_enabled | bool" diff --git a/roles/matrix-synapse/tasks/synapse/workers/init.yml b/roles/matrix-synapse/tasks/synapse/workers/init.yml index f59313bde..4b007bc30 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/init.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/init.yml @@ -5,69 +5,69 @@ # so we're forced to do something much uglier. - name: Build generic workers - set_fact: + ansible.builtin.set_fact: worker: type: 'generic_worker' instanceId: "{{ matrix_synapse_workers_generic_workers_port_range_start + item }}" port: "{{ matrix_synapse_workers_generic_workers_port_range_start + item }}" metrics_port: "{{ matrix_synapse_workers_generic_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_generic_workers" - loop: "{{ range(0, matrix_synapse_workers_generic_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_generic_workers_count | int) | list }}" - name: Build federation sender workers - set_fact: + ansible.builtin.set_fact: worker: type: 'federation_sender' instanceId: "{{ item }}" port: 0 metrics_port: "{{ matrix_synapse_workers_federation_sender_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_federation_sender_workers" - loop: "{{ range(0, matrix_synapse_workers_federation_sender_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_federation_sender_workers_count | int) | list }}" # This type of worker can only have a count of 1, at most - name: Build pusher workers - set_fact: + ansible.builtin.set_fact: worker: type: 'pusher' instanceId: "{{ item }}" port: 0 metrics_port: "{{ matrix_synapse_workers_pusher_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_pusher_workers" - loop: "{{ range(0, matrix_synapse_workers_pusher_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_pusher_workers_count | int) | list }}" # This type of worker can only have a count of 1, at most - name: Build appservice workers - set_fact: + ansible.builtin.set_fact: worker: type: 'appservice' instanceId: "{{ item }}" port: 0 metrics_port: "{{ matrix_synapse_workers_appservice_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_appservice_workers" - loop: "{{ range(0, matrix_synapse_workers_appservice_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_appservice_workers_count | int) | list }}" - name: Build media_repository workers - set_fact: + ansible.builtin.set_fact: worker: type: 'media_repository' instanceId: "{{ matrix_synapse_workers_media_repository_workers_port_range_start + item }}" port: "{{ matrix_synapse_workers_media_repository_workers_port_range_start + item }}" metrics_port: "{{ matrix_synapse_workers_media_repository_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_media_repository_workers" - loop: "{{ range(0, matrix_synapse_workers_media_repository_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_media_repository_workers_count | int) | list }}" - name: Build frontend_proxy workers - set_fact: + ansible.builtin.set_fact: worker: type: 'frontend_proxy' instanceId: "{{ matrix_synapse_workers_frontend_proxy_workers_port_range_start + item }}" port: "{{ matrix_synapse_workers_frontend_proxy_workers_port_range_start + item }}" metrics_port: "{{ matrix_synapse_workers_frontend_proxy_workers_metrics_range_start + item }}" register: "matrix_synapse_workers_list_results_frontend_proxy_workers" - loop: "{{ range(0, matrix_synapse_workers_frontend_proxy_workers_count|int)|list }}" + loop: "{{ range(0, matrix_synapse_workers_frontend_proxy_workers_count | int) | list }}" -- set_fact: - matrix_synapse_dynamic_workers_list: "{{ matrix_synapse_dynamic_workers_list|default([]) + [item.ansible_facts.worker] }}" +- ansible.builtin.set_fact: + matrix_synapse_dynamic_workers_list: "{{ matrix_synapse_dynamic_workers_list | default([]) + [item.ansible_facts.worker] }}" with_items: | {{ matrix_synapse_workers_list_results_generic_workers.results @@ -83,5 +83,5 @@ matrix_synapse_workers_list_results_frontend_proxy_workers.results }} -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_workers_enabled_list: "{{ matrix_synapse_dynamic_workers_list }}" diff --git a/roles/matrix-synapse/tasks/synapse/workers/setup.yml b/roles/matrix-synapse/tasks/synapse/workers/setup.yml index ce66a2e40..836d5a668 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/setup.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/setup.yml @@ -3,19 +3,19 @@ # A previous version of the worker setup used this. # This is a temporary cleanup for people who ran that version. - name: Ensure old matrix-synapse.service.wants directory is gone - file: + ansible.builtin.file: path: "{{ matrix_systemd_path }}/matrix-synapse.service.wants" state: absent # Same. This was part of a previous version of the worker setup. # No longer necessary. - name: Ensure matrix-synapse-worker-write-pid script is removed - file: + ansible.builtin.file: path: "{{ matrix_local_bin_path }}/matrix-synapse-worker-write-pid" state: absent -- include_tasks: "{{ role_path }}/tasks/synapse/workers/setup_install.yml" - when: "matrix_synapse_enabled|bool and matrix_synapse_workers_enabled|bool" +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/synapse/workers/setup_install.yml" + when: "matrix_synapse_enabled | bool and matrix_synapse_workers_enabled | bool" -- include_tasks: "{{ role_path }}/tasks/synapse/workers/setup_uninstall.yml" - when: "not matrix_synapse_workers_enabled|bool" +- ansible.builtin.include_tasks: "{{ role_path }}/tasks/synapse/workers/setup_uninstall.yml" + when: "not matrix_synapse_workers_enabled | bool" diff --git a/roles/matrix-synapse/tasks/synapse/workers/setup_install.yml b/roles/matrix-synapse/tasks/synapse/workers/setup_install.yml index 983f1876f..c264805ae 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/setup_install.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/setup_install.yml @@ -1,7 +1,7 @@ --- - name: Determine current worker configs - find: + ansible.builtin.find: path: "{{ matrix_synapse_config_dir_path }}" patterns: "worker.*.yaml" use_regex: true @@ -9,34 +9,34 @@ # This also deletes some things which we need. They will be recreated below. - name: Ensure previous worker configs are cleaned - file: + ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ matrix_synapse_workers_current_config_files.files }}" - name: Determine current worker systemd services - find: + ansible.builtin.find: path: "{{ matrix_systemd_path }}" patterns: "matrix-synapse-worker.*.service" use_regex: true register: matrix_synapse_workers_current_systemd_services - name: Ensure unnecessary worker systemd services are stopped and disabled - service: - name: "{{ item.path|basename }}" + ansible.builtin.service: + name: "{{ item.path | basename }}" state: stopped enabled: false with_items: "{{ matrix_synapse_workers_current_systemd_services.files }}" - when: "not ansible_check_mode and item.path|basename not in matrix_systemd_services_list" + when: "not ansible_check_mode and item.path | basename not in matrix_systemd_services_list" - name: Ensure unnecessary worker systemd services are cleaned - file: + ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ matrix_synapse_workers_current_systemd_services.files }}" - name: Ensure creation of worker systemd service files and configuration files - include_tasks: "{{ role_path }}/tasks/synapse/workers/util/setup_files_for_worker.yml" + ansible.builtin.include_tasks: "{{ role_path }}/tasks/synapse/workers/util/setup_files_for_worker.yml" with_items: "{{ matrix_synapse_workers_enabled_list }}" loop_control: loop_var: matrix_synapse_worker_details diff --git a/roles/matrix-synapse/tasks/synapse/workers/setup_uninstall.yml b/roles/matrix-synapse/tasks/synapse/workers/setup_uninstall.yml index f03576112..98c81a2e5 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/setup_uninstall.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/setup_uninstall.yml @@ -1,37 +1,37 @@ --- - name: Populate service facts - service_facts: + ansible.builtin.service_facts: - name: Ensure any worker services are stopped - service: + ansible.builtin.service: name: "{{ item.key }}" state: stopped - with_dict: "{{ ansible_facts.services|default({})|dict2items|selectattr('key', 'match', 'matrix-synapse-worker-.+\\.service')|list|items2dict }}" + with_dict: "{{ ansible_facts.services | default({}) | dict2items | selectattr('key', 'match', 'matrix-synapse-worker-.+\\.service') | list | items2dict }}" when: "item.value['status'] != 'not-found'" # see https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1461 - name: Find worker configs to be cleaned - find: + ansible.builtin.find: path: "{{ matrix_synapse_config_dir_path }}" patterns: "worker.*.yaml" use_regex: true register: matrix_synapse_workers_current_config_files - name: Ensure previous worker configs are cleaned - file: + ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ matrix_synapse_workers_current_config_files.files }}" - name: Find worker systemd services to be cleaned - find: + ansible.builtin.find: path: "{{ matrix_systemd_path }}" patterns: "matrix-synapse-worker.*.service" use_regex: true register: matrix_synapse_workers_current_systemd_services - name: Ensure previous worker systemd services are cleaned - file: + ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ matrix_synapse_workers_current_systemd_services.files }}" diff --git a/roles/matrix-synapse/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml b/roles/matrix-synapse/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml index 2669e1491..2ecb3f2bf 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/util/inject_systemd_services_for_worker.yml @@ -8,12 +8,12 @@ # In the future, it should be possible to remove this check. # Our own code which dynamically builds `matrix_synapse_workers_enabled_list` does things right. - name: Fail if instanceId not defined for worker - fail: - msg: "Synapse workers (like {{ matrix_synapse_worker_details|to_json }}) need to define an instanceId property (type + instanceId must be unique)" + ansible.builtin.fail: + msg: "Synapse workers (like {{ matrix_synapse_worker_details | to_json }}) need to define an instanceId property (type + instanceId must be unique)" when: "'instanceId' not in matrix_synapse_worker_details" -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_worker_systemd_service_name: "matrix-synapse-worker-{{ matrix_synapse_worker_details.type }}-{{ matrix_synapse_worker_details.instanceId }}.service" -- set_fact: +- ansible.builtin.set_fact: matrix_systemd_services_list: "{{ matrix_systemd_services_list + [matrix_synapse_worker_systemd_service_name] }}" diff --git a/roles/matrix-synapse/tasks/synapse/workers/util/setup_files_for_worker.yml b/roles/matrix-synapse/tasks/synapse/workers/util/setup_files_for_worker.yml index 2247cd894..d6d4924fb 100644 --- a/roles/matrix-synapse/tasks/synapse/workers/util/setup_files_for_worker.yml +++ b/roles/matrix-synapse/tasks/synapse/workers/util/setup_files_for_worker.yml @@ -1,21 +1,24 @@ --- -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_worker_systemd_service_name: "matrix-synapse-worker-{{ matrix_synapse_worker_details.type }}-{{ matrix_synapse_worker_details.instanceId }}" -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_worker_container_name: "{{ matrix_synapse_worker_systemd_service_name }}" -- set_fact: +- ansible.builtin.set_fact: matrix_synapse_worker_config_file_name: "worker.{{ matrix_synapse_worker_details.type }}_{{ matrix_synapse_worker_details.instanceId }}.yaml" - name: Ensure configuration exists for {{ matrix_synapse_worker_systemd_service_name }} - template: + ansible.builtin.template: src: "{{ role_path }}/templates/synapse/worker.yaml.j2" dest: "{{ matrix_synapse_config_dir_path }}/{{ matrix_synapse_worker_config_file_name }}" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" - name: Ensure systemd service exists for {{ matrix_synapse_worker_systemd_service_name }} - template: + ansible.builtin.template: src: "{{ role_path }}/templates/synapse/systemd/matrix-synapse-worker.service.j2" dest: "{{ matrix_systemd_path }}/{{ matrix_synapse_worker_systemd_service_name }}.service" mode: 0644 diff --git a/roles/matrix-synapse/tasks/update_user_password.yml b/roles/matrix-synapse/tasks/update_user_password.yml index fd348d9db..586bf51b3 100644 --- a/roles/matrix-synapse/tasks/update_user_password.yml +++ b/roles/matrix-synapse/tasks/update_user_password.yml @@ -1,29 +1,29 @@ --- - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `username` variable needs to be provided to this playbook, via --extra-vars" when: "username is not defined or username == ''" - name: Fail if playbook called incorrectly - fail: + ansible.builtin.fail: msg: "The `password` variable needs to be provided to this playbook, via --extra-vars" when: "password is not defined or password == ''" - name: Fail if not using matrix-postgres container - fail: + ansible.builtin.fail: msg: "This command is working only when matrix-postgres container is being used" - when: "not matrix_postgres_enabled|bool" + when: "not matrix_postgres_enabled | bool" - name: Ensure matrix-synapse is started - service: + ansible.builtin.service: name: matrix-synapse state: started daemon_reload: true register: start_result - name: Ensure matrix-postgres is started - service: + ansible.builtin.service: name: matrix-postgres state: started daemon_reload: true @@ -31,13 +31,16 @@ - name: Wait a while, so that Matrix Synapse can manage to start - pause: + ansible.builtin.pause: seconds: 7 when: "start_result.changed or postgres_start_result.changed" - name: Generate password hash - shell: "{{ matrix_host_command_docker }} exec matrix-synapse /usr/local/bin/hash_password -c /data/homeserver.yaml -p {{ password|quote }}" + ansible.builtin.shell: "{{ matrix_host_command_docker }} exec matrix-synapse /usr/local/bin/hash_password -c /data/homeserver.yaml -p {{ password|quote }}" register: password_hash + changed_when: false - name: Update user password hash - command: "{{ matrix_local_bin_path }}/matrix-postgres-update-user-password-hash {{ username|quote }} {{ password_hash.stdout|quote }}" + ansible.builtin.command: "{{ matrix_local_bin_path }}/matrix-postgres-update-user-password-hash {{ username|quote }} {{ password_hash.stdout|quote }}" + register: matrix_synapse_update_user_password_result + changed_when: matrix_synapse_update_user_password_result.rc == 0 diff --git a/roles/matrix-synapse/tasks/validate_config.yml b/roles/matrix-synapse/tasks/validate_config.yml index ab0ca3a7e..ba60abf8a 100644 --- a/roles/matrix-synapse/tasks/validate_config.yml +++ b/roles/matrix-synapse/tasks/validate_config.yml @@ -1,7 +1,7 @@ --- - name: Fail if required Synapse settings not defined - fail: + ansible.builtin.fail: msg: >- You need to define a required configuration setting (`{{ item }}`) for using Synapse. when: "vars[item] == ''" @@ -13,7 +13,7 @@ - "matrix_synapse_database_database" - name: Fail if asking to configure deprecaed workers (appservice, userdir) - fail: + ansible.builtin.fail: msg: >- `{{ item }}` cannot be more than 0. This type of worker has been deprecated since Synapse v1.59. @@ -25,7 +25,7 @@ - "matrix_synapse_workers_user_dir_workers_count" - name: Fail if asking for more than 1 instance of single-instance workers - fail: + ansible.builtin.fail: msg: >- `{{ item }}` cannot be more than 1. This is a single-instance worker. when: "vars[item]|int > 1" @@ -34,7 +34,7 @@ - "matrix_synapse_workers_federation_sender_workers_count" - name: (Deprecation) Catch and report renamed settings - fail: + ansible.builtin.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 }}`). @@ -63,7 +63,7 @@ - {'old': 'matrix_synapse_enable_group_creation', 'new': ''} - name: (Deprecation) Catch and report renamed settings in matrix_synapse_configuration_extension_yaml - fail: + ansible.builtin.fail: msg: >- Your matrix_synapse_configuration_extension_yaml configuration contains a variable, which now has a different name. Please change your configuration to rename the variable (`{{ item.old }}` -> `{{ item.new }}`). diff --git a/roles/matrix-synapse/templates/synapse/homeserver.yaml.j2 b/roles/matrix-synapse/templates/synapse/homeserver.yaml.j2 index c2364650d..87cedb404 100644 --- a/roles/matrix-synapse/templates/synapse/homeserver.yaml.j2 +++ b/roles/matrix-synapse/templates/synapse/homeserver.yaml.j2 @@ -352,13 +352,13 @@ worker_app: synapse.app.homeserver # thx https://oznetnerd.com/2017/04/18/jinja2-selectattr-filter/ # reduce the main worker's offerings to core homeserver business -{% if matrix_synapse_workers_enabled_list|selectattr('type', 'equalto', 'federation_sender')|list %} +{% if matrix_synapse_workers_enabled_list | selectattr('type', 'equalto', 'federation_sender') | list %} send_federation: false {% endif %} -{% if matrix_synapse_workers_enabled_list|selectattr('type', 'equalto', 'media_repository')|list %} +{% if matrix_synapse_workers_enabled_list | selectattr('type', 'equalto', 'media_repository') | list %} enable_media_repo: false {% endif %} -{% if matrix_synapse_workers_enabled_list|selectattr('type', 'equalto', 'pusher')|list %} +{% if matrix_synapse_workers_enabled_list | selectattr('type', 'equalto', 'pusher') | list %} start_pushers: false {% endif %} @@ -870,8 +870,8 @@ database: name: "psycopg2" txn_limit: {{ matrix_synapse_database_txn_limit }} args: - user: {{ matrix_synapse_database_user|string|to_json }} - password: {{ matrix_synapse_database_password|string|to_json }} + user: {{ matrix_synapse_database_user | string|to_json }} + password: {{ matrix_synapse_database_password | string|to_json }} database: "{{ matrix_synapse_database_database }}" host: "{{ matrix_synapse_database_host }}" port: {{ matrix_synapse_database_port }} @@ -1256,7 +1256,7 @@ turn_uris: {{ matrix_synapse_turn_uris|to_json }} # The shared secret used to compute passwords for the TURN server # -turn_shared_secret: {{ matrix_synapse_turn_shared_secret|string|to_json }} +turn_shared_secret: {{ matrix_synapse_turn_shared_secret | string|to_json }} # The Username and password if the TURN server needs them and # does not use a token @@ -1393,7 +1393,7 @@ registration_requires_token: {{ matrix_synapse_registration_requires_token|to_js # If set, allows registration of standard or admin accounts by anyone who # has the shared secret, even if registration is otherwise disabled. # -registration_shared_secret: {{ matrix_synapse_registration_shared_secret|string|to_json }} +registration_shared_secret: {{ matrix_synapse_registration_shared_secret | string|to_json }} # Set the number of bcrypt rounds used to generate password hash. # Larger numbers increase the work factor needed to generate the hash. @@ -1657,13 +1657,13 @@ app_service_config_files: {{ matrix_synapse_app_service_config_files|to_json }} # the registration_shared_secret is used, if one is given; otherwise, # a secret key is derived from the signing key. # -macaroon_secret_key: {{ matrix_synapse_macaroon_secret_key|string|to_json }} +macaroon_secret_key: {{ matrix_synapse_macaroon_secret_key | string|to_json }} # a secret which is used to calculate HMACs for form values, to stop # falsification of values. Must be specified for the User Consent # forms to work. # -form_secret: {{ matrix_synapse_form_secret|string|to_json }} +form_secret: {{ matrix_synapse_form_secret | string|to_json }} ## Signing Keys ## @@ -2263,7 +2263,7 @@ password_config: # Uncomment and change to a secret random string for extra security. # DO NOT CHANGE THIS AFTER INITIAL SETUP! # - pepper: {{ matrix_synapse_password_config_pepper|string|to_json }} + pepper: {{ matrix_synapse_password_config_pepper | string|to_json }} # Define and enforce a password policy. Each parameter is optional. # This is an implementation of MSC2000. @@ -2330,7 +2330,7 @@ email: # The hostname of the outgoing SMTP server to use. Defaults to 'localhost'. # #smtp_host: mail.server - smtp_host: {{ matrix_synapse_email_smtp_host|string|to_json }} + smtp_host: {{ matrix_synapse_email_smtp_host | string|to_json }} # The port on the mail server for outgoing SMTP. Defaults to 25. # @@ -2340,8 +2340,8 @@ email: # Username/password for authentication to the SMTP server. By default, no # authentication is attempted. {% if matrix_synapse_email_smtp_user %} - smtp_user: {{ matrix_synapse_email_smtp_user|string|to_json }} - smtp_pass: {{ matrix_synapse_email_smtp_pass|string|to_json }} + smtp_user: {{ matrix_synapse_email_smtp_user | string|to_json }} + smtp_pass: {{ matrix_synapse_email_smtp_pass | string|to_json }} {% endif %} # Uncomment the following to require TLS transport security for SMTP. @@ -2371,7 +2371,7 @@ email: # trailing 's'. # #notif_from: "Your Friendly %(app)s homeserver " - notif_from: {{ matrix_synapse_email_notif_from|string|to_json }} + notif_from: {{ matrix_synapse_email_notif_from | string|to_json }} # app_name defines the default value for '%(app)s' in notif_from and email # subjects. It defaults to 'Matrix'. @@ -2398,7 +2398,7 @@ email: # supported for backwards-compatibility but is now deprecated.) # #client_base_url: "http://localhost/riot" - client_base_url: {{ matrix_synapse_email_client_base_url|string|to_json }} + client_base_url: {{ matrix_synapse_email_client_base_url | string|to_json }} # Configure the time that a validation email will expire after sending. # Defaults to 1h. @@ -2409,7 +2409,7 @@ email: # to the identity server as the org.matrix.web_client_location key. Defaults # to unset, giving no guidance to the identity server. # - invite_client_location: {{ matrix_synapse_email_invite_client_location|string|to_json }} + invite_client_location: {{ matrix_synapse_email_invite_client_location | string|to_json }} # Subjects to use when sending emails from Synapse. # @@ -2510,7 +2510,7 @@ password_providers: {% if matrix_synapse_ext_password_provider_rest_auth_enabled %} - module: "rest_auth_provider.RestAuthProvider" config: - endpoint: {{ matrix_synapse_ext_password_provider_rest_auth_endpoint|string|to_json }} + endpoint: {{ matrix_synapse_ext_password_provider_rest_auth_endpoint | string|to_json }} policy: registration: username: @@ -2525,20 +2525,20 @@ password_providers: - module: "ldap_auth_provider.LdapAuthProvider" config: enabled: true - uri: {{ matrix_synapse_ext_password_provider_ldap_uri|string|to_json }} + uri: {{ matrix_synapse_ext_password_provider_ldap_uri | string|to_json }} start_tls: {{ matrix_synapse_ext_password_provider_ldap_start_tls|to_json }} - base: {{ matrix_synapse_ext_password_provider_ldap_base|string|to_json }} + base: {{ matrix_synapse_ext_password_provider_ldap_base | string|to_json }} active_directory: {{ matrix_synapse_ext_password_provider_ldap_active_directory|to_json }} - default_domain: {{ matrix_synapse_ext_password_provider_ldap_default_domain|string|to_json }} + default_domain: {{ matrix_synapse_ext_password_provider_ldap_default_domain | string|to_json }} attributes: - uid: {{ matrix_synapse_ext_password_provider_ldap_attributes_uid|string|to_json }} - mail: {{ matrix_synapse_ext_password_provider_ldap_attributes_mail|string|to_json }} - name: {{ matrix_synapse_ext_password_provider_ldap_attributes_name|string|to_json }} + uid: {{ matrix_synapse_ext_password_provider_ldap_attributes_uid | string|to_json }} + mail: {{ matrix_synapse_ext_password_provider_ldap_attributes_mail | string|to_json }} + name: {{ matrix_synapse_ext_password_provider_ldap_attributes_name | string|to_json }} {% if matrix_synapse_ext_password_provider_ldap_bind_dn %} - bind_dn: {{ matrix_synapse_ext_password_provider_ldap_bind_dn|string|to_json }} - bind_password: {{ matrix_synapse_ext_password_provider_ldap_bind_password|string|to_json }} + bind_dn: {{ matrix_synapse_ext_password_provider_ldap_bind_dn | string|to_json }} + bind_password: {{ matrix_synapse_ext_password_provider_ldap_bind_password | string|to_json }} {% endif %} - filter: {{ matrix_synapse_ext_password_provider_ldap_filter|string|to_json }} + filter: {{ matrix_synapse_ext_password_provider_ldap_filter | string|to_json }} {% endif %} {% endif %} diff --git a/roles/matrix-synapse/vars/main.yml b/roles/matrix-synapse/vars/main.yml index 5839aa81b..2d9b62cf7 100644 --- a/roles/matrix-synapse/vars/main.yml +++ b/roles/matrix-synapse/vars/main.yml @@ -6,7 +6,7 @@ matrix_synapse_federation_api_url_endpoint_public: "https://{{ matrix_server_fqn # Tells whether this role had executed or not. Toggled to `true` during runtime. matrix_synapse_role_executed: false -matrix_synapse_media_store_directory_name: "{{ matrix_synapse_media_store_path|basename }}" +matrix_synapse_media_store_directory_name: "{{ matrix_synapse_media_store_path | basename }}" # A Synapse generic worker can handle both federation and client-server API endpoints. # We wish to split these, as we normally serve federation separately and don't want them mixed up. @@ -24,11 +24,15 @@ matrix_synapse_media_store_directory_name: "{{ matrix_synapse_media_store_path|b # so it's not that important whether we forward them or not. # # Basically, we aim to cover most things. Skipping `/_synapse/client` or a few other minor things doesn't matter too much. -matrix_synapse_workers_generic_worker_client_server_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints|default([]) | map('regex_search', '.*/_matrix/client.*')| list | difference([none]) }}" +matrix_synapse_workers_generic_worker_client_server_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints | default([]) | map('regex_search', '.*/_matrix/client.*') | list | difference([none]) }}" # A Synapse generic worker can handle both federation and client-server API endpoints. # We wish to split these, as we normally serve federation separately and don't want them mixed up. # # This is some ugly Ansible/Jinja2 hack (seen here: https://stackoverflow.com/a/47831492), # which takes a list of various strings and removes the ones NOT containing `/_matrix/federation` or `/_matrix/key` anywhere in them. -matrix_synapse_workers_generic_worker_federation_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints|default([]) | map('regex_search', '.*(/_matrix/federation|/_matrix/key).*')| list | difference([none]) }}" +matrix_synapse_workers_generic_worker_federation_endpoints: "{{ matrix_synapse_workers_generic_worker_endpoints | default([]) | map('regex_search', matrix_synapse_workers_generic_worker_federation_endpoints_regex) | list | difference([none]) }}" + +# matrix_synapse_workers_generic_worker_federation_endpoints_regex contains the regex used in matrix_synapse_workers_generic_worker_federation_endpoints. +# It's intentionally put in a separate variable, to avoid tripping ansible-lint's var-spacing rule. +matrix_synapse_workers_generic_worker_federation_endpoints_regex: '.*(/_matrix/federation|/_matrix/key).*'