Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

162 lines
7.5 KiB

  1. ---
  2. # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist.
  3. # We don't want to fail in such cases.
  4. - name: Fail if matrix-synapse role already executed
  5. ansible.builtin.fail:
  6. msg: >-
  7. The matrix-bridge-mautrix-telegram role needs to execute before the matrix-synapse role.
  8. when: "matrix_synapse_role_executed | default(False)"
  9. - ansible.builtin.set_fact:
  10. matrix_mautrix_telegram_requires_restart: false
  11. - block:
  12. - name: Check if an SQLite database already exists
  13. ansible.builtin.stat:
  14. path: "{{ matrix_mautrix_telegram_sqlite_database_path_local }}"
  15. register: matrix_mautrix_telegram_sqlite_database_path_local_stat_result
  16. - block:
  17. - ansible.builtin.set_fact:
  18. matrix_postgres_db_migration_request:
  19. src: "{{ matrix_mautrix_telegram_sqlite_database_path_local }}"
  20. dst: "{{ matrix_mautrix_telegram_database_connection_string }}"
  21. caller: "{{ role_path | basename }}"
  22. engine_variable_name: 'matrix_mautrix_telegram_database_engine'
  23. engine_old: 'sqlite'
  24. systemd_services_to_stop: ['matrix-mautrix-telegram.service']
  25. - ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
  26. - ansible.builtin.set_fact:
  27. matrix_mautrix_telegram_requires_restart: true
  28. when: "matrix_mautrix_telegram_sqlite_database_path_local_stat_result.stat.exists | bool"
  29. when: "matrix_mautrix_telegram_database_engine == 'postgres'"
  30. - name: Ensure Mautrix Telegram paths exist
  31. ansible.builtin.file:
  32. path: "{{ item.path }}"
  33. state: directory
  34. mode: 0750
  35. owner: "{{ matrix_user_username }}"
  36. group: "{{ matrix_user_groupname }}"
  37. with_items:
  38. - {path: "{{ matrix_mautrix_telegram_base_path }}", when: true}
  39. - {path: "{{ matrix_mautrix_telegram_config_path }}", when: true}
  40. - {path: "{{ matrix_mautrix_telegram_data_path }}", when: true}
  41. - {path: "{{ matrix_mautrix_telegram_docker_src_files_path }}", when: "{{ matrix_mautrix_telegram_container_image_self_build }}"}
  42. when: item.when | bool
  43. - name: Ensure Mautrix Telegram image is pulled
  44. docker_image:
  45. name: "{{ matrix_mautrix_telegram_docker_image }}"
  46. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  47. force_source: "{{ matrix_mautrix_telegram_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_mautrix_telegram_docker_image_force_pull }}"
  49. when: "not matrix_mautrix_telegram_container_image_self_build | bool"
  50. register: result
  51. retries: "{{ matrix_container_retries_count }}"
  52. delay: "{{ matrix_container_retries_delay }}"
  53. until: result is not failed
  54. - name: Ensure lottieconverter is present when self-building
  55. ansible.builtin.git:
  56. repo: "{{ matrix_telegram_lottieconverter_docker_repo }}"
  57. version: "{{ matrix_telegram_lottieconverter_docker_repo_version }}"
  58. dest: "{{ matrix_telegram_lottieconverter_docker_src_files_path }}"
  59. force: "yes"
  60. become: true
  61. become_user: "{{ matrix_user_username }}"
  62. register: matrix_telegram_lottieconverter_git_pull_results
  63. when: "matrix_telegram_lottieconverter_container_image_self_build | bool and matrix_mautrix_telegram_container_image_self_build | bool"
  64. - name: Ensure lottieconverter Docker image is built
  65. docker_image:
  66. name: "{{ matrix_telegram_lottieconverter_docker_image }}"
  67. source: build
  68. force_source: "{{ matrix_telegram_lottieconverter_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  69. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_telegram_lottieconverter_git_pull_results.changed }}"
  70. build:
  71. dockerfile: Dockerfile
  72. path: "{{ matrix_telegram_lottieconverter_docker_src_files_path }}"
  73. pull: true
  74. 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"
  75. - name: Ensure matrix-mautrix-telegram repository is present when self-building
  76. ansible.builtin.git:
  77. repo: "{{ matrix_mautrix_telegram_docker_repo }}"
  78. version: "{{ matrix_mautrix_telegram_docker_repo_version }}"
  79. dest: "{{ matrix_mautrix_telegram_docker_src_files_path }}"
  80. force: "yes"
  81. become: true
  82. become_user: "{{ matrix_user_username }}"
  83. register: matrix_mautrix_telegram_git_pull_results
  84. when: "matrix_mautrix_telegram_container_image_self_build | bool"
  85. - name: Ensure matrix-mautrix-telegram Docker image is built
  86. docker_image:
  87. name: "{{ matrix_mautrix_telegram_docker_image }}"
  88. source: build
  89. force_source: "{{ matrix_mautrix_telegram_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  90. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_telegram_git_pull_results.changed }}"
  91. build:
  92. dockerfile: Dockerfile
  93. path: "{{ matrix_mautrix_telegram_docker_src_files_path }}"
  94. pull: "{{ not matrix_telegram_lottieconverter_container_image_self_build_mask_arch | bool }}"
  95. args:
  96. TARGETARCH: ""
  97. when: "matrix_mautrix_telegram_container_image_self_build | bool and matrix_mautrix_telegram_git_pull_results.changed"
  98. - name: Check if an old database file already exists
  99. ansible.builtin.stat:
  100. path: "{{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db"
  101. register: matrix_mautrix_telegram_stat_database
  102. - name: (Data relocation) Ensure matrix-mautrix-telegram.service is stopped
  103. ansible.builtin.service:
  104. name: matrix-mautrix-telegram
  105. state: stopped
  106. enabled: false
  107. daemon_reload: true
  108. failed_when: false
  109. when: "matrix_mautrix_telegram_stat_database.stat.exists"
  110. - name: (Data relocation) Move mautrix-telegram database file to ./data directory
  111. ansible.builtin.command: "mv {{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db {{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db"
  112. when: "matrix_mautrix_telegram_stat_database.stat.exists"
  113. - name: Ensure mautrix-telegram config.yaml installed
  114. ansible.builtin.copy:
  115. content: "{{ matrix_mautrix_telegram_configuration | to_nice_yaml(indent=2, width=999999) }}"
  116. dest: "{{ matrix_mautrix_telegram_config_path }}/config.yaml"
  117. mode: 0644
  118. owner: "{{ matrix_user_username }}"
  119. group: "{{ matrix_user_groupname }}"
  120. - name: Ensure mautrix-telegram registration.yaml installed
  121. ansible.builtin.copy:
  122. content: "{{ matrix_mautrix_telegram_registration | to_nice_yaml(indent=2, width=999999) }}"
  123. dest: "{{ matrix_mautrix_telegram_config_path }}/registration.yaml"
  124. mode: 0644
  125. owner: "{{ matrix_user_username }}"
  126. group: "{{ matrix_user_groupname }}"
  127. - name: Ensure matrix-mautrix-telegram.service installed
  128. ansible.builtin.template:
  129. src: "{{ role_path }}/templates/systemd/matrix-mautrix-telegram.service.j2"
  130. dest: "{{ matrix_systemd_path }}/matrix-mautrix-telegram.service"
  131. mode: 0644
  132. register: matrix_mautrix_telegram_systemd_service_result
  133. - name: Ensure systemd reloaded after matrix-mautrix-telegram.service installation
  134. ansible.builtin.service:
  135. daemon_reload: true
  136. when: "matrix_mautrix_telegram_systemd_service_result.changed"
  137. - name: Ensure matrix-mautrix-telegram.service restarted, if necessary
  138. ansible.builtin.service:
  139. name: "matrix-mautrix-telegram.service"
  140. state: restarted
  141. when: "matrix_mautrix_telegram_requires_restart | bool"