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.
 
 

160 lines
7.1 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. 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. - set_fact:
  10. matrix_mautrix_telegram_requires_restart: false
  11. - block:
  12. - name: Check if an SQLite database already exists
  13. stat:
  14. path: "{{ matrix_mautrix_telegram_sqlite_database_path_local }}"
  15. register: matrix_mautrix_telegram_sqlite_database_path_local_stat_result
  16. - block:
  17. - 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. - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
  26. - 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. 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. git:
  56. repo: "{{ matrix_telegram_lottieconverter_docker_repo }}"
  57. dest: "{{ matrix_telegram_lottieconverter_docker_src_files_path }}"
  58. force: "yes"
  59. become: true
  60. become_user: "{{ matrix_user_username }}"
  61. register: matrix_telegram_lottieconverter_git_pull_results
  62. when: "matrix_telegram_lottieconverter_container_image_self_build|bool and matrix_mautrix_telegram_container_image_self_build|bool"
  63. - name: Ensure lottieconverter Docker image is built
  64. docker_image:
  65. name: "{{ matrix_telegram_lottieconverter_docker_image }}"
  66. source: build
  67. force_source: "{{ matrix_telegram_lottieconverter_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  68. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_telegram_lottieconverter_git_pull_results.changed }}"
  69. build:
  70. dockerfile: Dockerfile
  71. path: "{{ matrix_telegram_lottieconverter_docker_src_files_path }}"
  72. pull: true
  73. 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"
  74. - name: Ensure matrix-mautrix-telegram repository is present when self-building
  75. git:
  76. repo: "{{ matrix_mautrix_telegram_docker_repo }}"
  77. dest: "{{ matrix_mautrix_telegram_docker_src_files_path }}"
  78. force: "yes"
  79. become: true
  80. become_user: "{{ matrix_user_username }}"
  81. register: matrix_mautrix_telegram_git_pull_results
  82. when: "matrix_mautrix_telegram_container_image_self_build|bool"
  83. - name: Ensure matrix-mautrix-telegram Docker image is built
  84. docker_image:
  85. name: "{{ matrix_mautrix_telegram_docker_image }}"
  86. source: build
  87. force_source: "{{ matrix_mautrix_telegram_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  88. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_telegram_git_pull_results.changed }}"
  89. build:
  90. dockerfile: Dockerfile
  91. path: "{{ matrix_mautrix_telegram_docker_src_files_path }}"
  92. pull: "{{ not matrix_telegram_lottieconverter_container_image_self_build_mask_arch|bool }}"
  93. args:
  94. TARGETARCH: ""
  95. when: "matrix_mautrix_telegram_container_image_self_build|bool and matrix_mautrix_telegram_git_pull_results.changed"
  96. - name: Check if an old database file already exists
  97. stat:
  98. path: "{{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db"
  99. register: matrix_mautrix_telegram_stat_database
  100. - name: (Data relocation) Ensure matrix-mautrix-telegram.service is stopped
  101. service:
  102. name: matrix-mautrix-telegram
  103. state: stopped
  104. enabled: false
  105. daemon_reload: true
  106. failed_when: false
  107. when: "matrix_mautrix_telegram_stat_database.stat.exists"
  108. - name: (Data relocation) Move mautrix-telegram database file to ./data directory
  109. command: "mv {{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db {{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db"
  110. when: "matrix_mautrix_telegram_stat_database.stat.exists"
  111. - name: Ensure mautrix-telegram config.yaml installed
  112. copy:
  113. content: "{{ matrix_mautrix_telegram_configuration|to_nice_yaml(indent=2, width=999999) }}"
  114. dest: "{{ matrix_mautrix_telegram_config_path }}/config.yaml"
  115. mode: 0644
  116. owner: "{{ matrix_user_username }}"
  117. group: "{{ matrix_user_groupname }}"
  118. - name: Ensure mautrix-telegram registration.yaml installed
  119. copy:
  120. content: "{{ matrix_mautrix_telegram_registration|to_nice_yaml(indent=2, width=999999) }}"
  121. dest: "{{ matrix_mautrix_telegram_config_path }}/registration.yaml"
  122. mode: 0644
  123. owner: "{{ matrix_user_username }}"
  124. group: "{{ matrix_user_groupname }}"
  125. - name: Ensure matrix-mautrix-telegram.service installed
  126. template:
  127. src: "{{ role_path }}/templates/systemd/matrix-mautrix-telegram.service.j2"
  128. dest: "{{ matrix_systemd_path }}/matrix-mautrix-telegram.service"
  129. mode: 0644
  130. register: matrix_mautrix_telegram_systemd_service_result
  131. - name: Ensure systemd reloaded after matrix-mautrix-telegram.service installation
  132. service:
  133. daemon_reload: true
  134. when: "matrix_mautrix_telegram_systemd_service_result.changed"
  135. - name: Ensure matrix-mautrix-telegram.service restarted, if necessary
  136. service:
  137. name: "matrix-mautrix-telegram.service"
  138. state: restarted
  139. when: "matrix_mautrix_telegram_requires_restart|bool"