Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

158 строки
7.0 KiB

  1. # SPDX-FileCopyrightText: 2024 MDAD Team and contributors
  2. #
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. ---
  5. - name: Ensure ma1sd paths exist
  6. ansible.builtin.file:
  7. path: "{{ item.path }}"
  8. state: directory
  9. mode: 0750
  10. owner: "{{ matrix_user_username }}"
  11. group: "{{ matrix_user_groupname }}"
  12. with_items:
  13. - {path: "{{ matrix_ma1sd_config_path }}", when: true}
  14. - {path: "{{ matrix_ma1sd_data_path }}", when: true}
  15. - {path: "{{ matrix_ma1sd_docker_src_files_path }}", when: "{{ matrix_ma1sd_container_image_self_build }}"}
  16. when: "item.when | bool"
  17. # These (SQLite -> Postgres) migration tasks are usually at the top,
  18. # but we'd like to run them after `migrate_mxisd.yml`, which requires the ma1sd paths to exist.
  19. - ansible.builtin.set_fact:
  20. matrix_ma1sd_requires_restart: false
  21. - when: "matrix_ma1sd_database_engine == 'postgres'"
  22. block:
  23. - name: Check if an SQLite database already exists
  24. ansible.builtin.stat:
  25. path: "{{ matrix_ma1sd_sqlite_database_path_local }}"
  26. register: matrix_ma1sd_sqlite_database_path_local_stat_result
  27. - when: "matrix_ma1sd_sqlite_database_path_local_stat_result.stat.exists | bool"
  28. block:
  29. - ansible.builtin.include_role:
  30. name: galaxy/postgres
  31. tasks_from: migrate_db_to_postgres
  32. vars:
  33. postgres_db_migration_request:
  34. src: "{{ matrix_ma1sd_sqlite_database_path_local }}"
  35. dst: "{{ matrix_ma1sd_database_connection_string }}"
  36. caller: "{{ role_path | basename }}"
  37. engine_variable_name: 'matrix_ma1sd_database_engine'
  38. engine_old: 'sqlite'
  39. systemd_services_to_stop: ['matrix-ma1sd.service']
  40. pgloader_options: ['--with "quote identifiers"']
  41. - ansible.builtin.set_fact:
  42. matrix_ma1sd_requires_restart: true
  43. - name: Ensure ma1sd image is pulled
  44. community.docker.docker_image:
  45. name: "{{ matrix_ma1sd_docker_image }}"
  46. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  47. force_source: "{{ matrix_ma1sd_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  48. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_ma1sd_docker_image_force_pull }}"
  49. when: "not matrix_ma1sd_container_image_self_build | bool"
  50. register: result
  51. retries: "{{ devture_playbook_help_container_retries_count }}"
  52. delay: "{{ devture_playbook_help_container_retries_delay }}"
  53. until: result is not failed
  54. - when: "matrix_ma1sd_container_image_self_build | bool"
  55. block:
  56. - name: Ensure ma1sd repository is present on self-build
  57. ansible.builtin.git:
  58. repo: "{{ matrix_ma1sd_container_image_self_build_repo }}"
  59. dest: "{{ matrix_ma1sd_docker_src_files_path }}"
  60. version: "{{ matrix_ma1sd_container_image_self_build_branch }}"
  61. force: "yes"
  62. become: true
  63. become_user: "{{ matrix_user_username }}"
  64. register: matrix_ma1sd_git_pull_results
  65. - name: Ensure ma1sd container image is built
  66. ansible.builtin.command:
  67. cmd: |-
  68. {{ devture_systemd_docker_base_host_command_docker }} buildx build
  69. --tag={{ matrix_ma1sd_docker_image }}
  70. --file={{ matrix_ma1sd_docker_src_files_path }}/Dockerfile
  71. {{ matrix_ma1sd_docker_src_files_path }}
  72. changed_when: true
  73. - name: Ensure ma1sd config installed
  74. ansible.builtin.copy:
  75. content: "{{ matrix_ma1sd_configuration | to_nice_yaml(indent=2, width=999999) }}"
  76. dest: "{{ matrix_ma1sd_config_path }}/ma1sd.yaml"
  77. mode: 0644
  78. owner: "{{ matrix_user_username }}"
  79. group: "{{ matrix_user_groupname }}"
  80. - name: Ensure custom view templates are installed, if any
  81. ansible.builtin.copy:
  82. content: "{{ item.value }}"
  83. dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}"
  84. mode: 0644
  85. owner: "{{ matrix_user_username }}"
  86. group: "{{ matrix_user_groupname }}"
  87. with_items:
  88. - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_success_template }}", location: 'tokenSubmitSuccess.html'}
  89. - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_failure_template }}", location: 'tokenSubmitFailure.html'}
  90. when: "matrix_ma1sd_view_session_custom_templates_enabled | bool and item.value"
  91. - name: Ensure custom email templates are installed, if any
  92. ansible.builtin.copy:
  93. content: "{{ item.value }}"
  94. dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}"
  95. mode: 0644
  96. owner: "{{ matrix_user_username }}"
  97. group: "{{ matrix_user_groupname }}"
  98. with_items:
  99. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_invite_template }}", location: 'invite-template.eml'}
  100. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'}
  101. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'}
  102. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'}
  103. when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled | bool and item.value"
  104. # Only cleaning up for people who define the respective templates
  105. - name: (Cleanup) Ensure custom email templates are not in data/ anymore (we've put them in config/)
  106. ansible.builtin.file:
  107. path: "{{ matrix_ma1sd_data_path }}/{{ item.location }}"
  108. state: absent
  109. with_items:
  110. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_invite_template }}", location: 'invite-template.eml'}
  111. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'}
  112. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'}
  113. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'}
  114. when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled | bool and item.value"
  115. - name: Ensure ma1sd support files installed
  116. ansible.builtin.template:
  117. src: "{{ role_path }}/templates/{{ item }}.j2"
  118. dest: "{{ matrix_ma1sd_base_path }}/{{ item }}"
  119. mode: 0640
  120. owner: "{{ matrix_user_username }}"
  121. group: "{{ matrix_user_groupname }}"
  122. with_items:
  123. - labels
  124. - name: Ensure ma1sd container network is created
  125. community.general.docker_network:
  126. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  127. name: "{{ matrix_ma1sd_container_network }}"
  128. driver: bridge
  129. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  130. - name: Ensure matrix-ma1sd.service installed
  131. ansible.builtin.template:
  132. src: "{{ role_path }}/templates/systemd/matrix-ma1sd.service.j2"
  133. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-ma1sd.service"
  134. mode: 0644
  135. - name: Ensure matrix-ma1sd.service restarted, if necessary
  136. ansible.builtin.service:
  137. name: "matrix-ma1sd.service"
  138. state: restarted
  139. daemon_reload: true
  140. when: "matrix_ma1sd_requires_restart | bool"