Matrix Docker Ansible eploy
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

153 wiersze
6.8 KiB

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