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

167 строки
7.1 KiB

  1. ---
  2. - name: Ensure ma1sd paths exist
  3. file:
  4. path: "{{ item.path }}"
  5. state: directory
  6. mode: 0750
  7. owner: "{{ matrix_user_username }}"
  8. group: "{{ matrix_user_groupname }}"
  9. with_items:
  10. - { path: "{{ matrix_ma1sd_config_path }}", when: true }
  11. - { path: "{{ matrix_ma1sd_data_path }}", when: true }
  12. - { path: "{{ matrix_ma1sd_docker_src_files_path }}", when: "{{ matrix_ma1sd_container_image_self_build }}"}
  13. when: "item.when|bool"
  14. - import_tasks: "{{ role_path }}/tasks/migrate_mxisd.yml"
  15. # These (SQLite -> Postgres) migration tasks are usually at the top,
  16. # but we'd like to run them after `migrate_mxisd.yml`, which requires the ma1sd paths to exist.
  17. - set_fact:
  18. matrix_ma1sd_requires_restart: false
  19. - block:
  20. - name: Check if an SQLite database already exists
  21. stat:
  22. path: "{{ matrix_ma1sd_sqlite_database_path_local }}"
  23. register: matrix_ma1sd_sqlite_database_path_local_stat_result
  24. - block:
  25. - set_fact:
  26. matrix_postgres_db_migration_request:
  27. src: "{{ matrix_ma1sd_sqlite_database_path_local }}"
  28. dst: "{{ matrix_ma1sd_database_connection_string }}"
  29. caller: "{{ role_path|basename }}"
  30. engine_variable_name: 'matrix_ma1sd_database_engine'
  31. engine_old: 'sqlite'
  32. systemd_services_to_stop: ['matrix-ma1sd.service']
  33. pgloader_options: ['--with "quote identifiers"']
  34. - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
  35. - set_fact:
  36. matrix_ma1sd_requires_restart: true
  37. when: "matrix_ma1sd_sqlite_database_path_local_stat_result.stat.exists|bool"
  38. when: "matrix_ma1sd_database_engine == 'postgres'"
  39. - name: Ensure ma1sd image is pulled
  40. docker_image:
  41. name: "{{ matrix_ma1sd_docker_image }}"
  42. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  43. force_source: "{{ matrix_ma1sd_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  44. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_ma1sd_docker_image_force_pull }}"
  45. when: "not matrix_ma1sd_container_image_self_build|bool"
  46. - block:
  47. - name: Ensure gradle is installed for self-building (Debian)
  48. apt:
  49. name:
  50. - gradle
  51. state: present
  52. update_cache: yes
  53. when: (ansible_os_family == 'Debian')
  54. - name: Ensure gradle is installed for self-building (CentOS)
  55. fail:
  56. msg: "Installing gradle on CentOS is currently not supported, so self-building ma1sd cannot happen at this time"
  57. when: ansible_distribution == 'CentOS'
  58. - name: Ensure gradle is installed for self-building (Archlinux)
  59. pacman:
  60. name:
  61. - gradle
  62. state: latest
  63. update_cache: yes
  64. when: ansible_distribution == 'Archlinux'
  65. - name: Ensure ma1sd repository is present on self-build
  66. git:
  67. repo: "{{ matrix_ma1sd_container_image_self_build_repo }}"
  68. dest: "{{ matrix_ma1sd_docker_src_files_path }}"
  69. version: "{{ matrix_ma1sd_docker_image.split(':')[1].split('-')[0] }}"
  70. force: "yes"
  71. register: matrix_ma1sd_git_pull_results
  72. - name: Ensure ma1sd Docker image is built
  73. shell: "./gradlew dockerBuild"
  74. args:
  75. chdir: "{{ matrix_ma1sd_docker_src_files_path }}"
  76. when: "matrix_ma1sd_git_pull_results.changed|bool"
  77. - name: Ensure ma1sd Docker image is tagged correctly
  78. docker_image:
  79. # The build script always tags the image with something like `ma1uta/ma1sd:2.4.0`.
  80. # Remove the `-{{ matrix_ma1sd_architecture }}` suffix and our `localhost/` prefix (applied when self-building)
  81. # to get to what has actually been built, so we can retag it as `{{ matrix_ma1sd_docker_image }}`.
  82. name: "{{ matrix_ma1sd_docker_image.split('-')[0].replace('localhost/', '') }}"
  83. repository: "{{ matrix_ma1sd_docker_image }}"
  84. force_tag: yes
  85. source: local
  86. when: "matrix_ma1sd_git_pull_results.changed|bool"
  87. when: "matrix_ma1sd_container_image_self_build|bool"
  88. - name: Ensure ma1sd config installed
  89. copy:
  90. content: "{{ matrix_ma1sd_configuration|to_nice_yaml }}"
  91. dest: "{{ matrix_ma1sd_config_path }}/ma1sd.yaml"
  92. mode: 0644
  93. owner: "{{ matrix_user_username }}"
  94. group: "{{ matrix_user_groupname }}"
  95. - name: Ensure custom view templates are installed, if any
  96. copy:
  97. content: "{{ item.value }}"
  98. dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}"
  99. mode: 0644
  100. owner: "{{ matrix_user_username }}"
  101. group: "{{ matrix_user_groupname }}"
  102. with_items:
  103. - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_success_template }}", location: 'tokenSubmitSuccess.html'}
  104. - {value: "{{ matrix_ma1sd_view_session_custom_onTokenSubmit_failure_template }}", location: 'tokenSubmitFailure.html'}
  105. when: "matrix_ma1sd_view_session_custom_templates_enabled|bool and item.value"
  106. - name: Ensure custom email templates are installed, if any
  107. copy:
  108. content: "{{ item.value }}"
  109. dest: "{{ matrix_ma1sd_config_path }}/{{ item.location }}"
  110. mode: 0644
  111. owner: "{{ matrix_user_username }}"
  112. group: "{{ matrix_user_groupname }}"
  113. with_items:
  114. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_invite_template }}", location: 'invite-template.eml'}
  115. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'}
  116. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'}
  117. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'}
  118. when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled|bool and item.value"
  119. # Only cleaning up for people who define the respective templates
  120. - name: (Cleanup) Ensure custom email templates are not in data/ anymore (we've put them in config/)
  121. file:
  122. path: "{{ matrix_ma1sd_data_path }}/{{ item.location }}"
  123. state: absent
  124. with_items:
  125. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_invite_template }}", location: 'invite-template.eml'}
  126. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_validation_template }}", location: 'validate-template.eml'}
  127. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_session_unbind_notification_template }}", location: 'unbind-notification.eml'}
  128. - {value: "{{ matrix_ma1sd_threepid_medium_email_custom_matrixid_template }}", location: 'mxid-template.eml'}
  129. when: "matrix_ma1sd_threepid_medium_email_custom_templates_enabled|bool and item.value"
  130. - name: Ensure matrix-ma1sd.service installed
  131. template:
  132. src: "{{ role_path }}/templates/systemd/matrix-ma1sd.service.j2"
  133. dest: "{{ matrix_systemd_path }}/matrix-ma1sd.service"
  134. mode: 0644
  135. register: matrix_ma1sd_systemd_service_result
  136. - name: Ensure systemd reloaded after matrix-ma1sd.service installation
  137. service:
  138. daemon_reload: yes
  139. when: "matrix_ma1sd_systemd_service_result.changed|bool"
  140. - name: Ensure matrix-ma1sd.service restarted, if necessary
  141. service:
  142. name: "matrix-ma1sd.service"
  143. state: restarted
  144. when: "matrix_ma1sd_requires_restart|bool"