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.
 
 

146 lines
6.0 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 }}"
  33. state: directory
  34. mode: 0750
  35. owner: "{{ matrix_user_username }}"
  36. group: "{{ matrix_user_groupname }}"
  37. with_items:
  38. - "{{ matrix_mautrix_telegram_base_path }}"
  39. - "{{ matrix_mautrix_telegram_config_path }}"
  40. - "{{ matrix_mautrix_telegram_data_path }}"
  41. - name: Ensure Mautrix Telegram image is pulled
  42. docker_image:
  43. name: "{{ matrix_mautrix_telegram_docker_image }}"
  44. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  45. force_source: "{{ matrix_mautrix_telegram_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  46. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_telegram_docker_image_force_pull }}"
  47. when: "not matrix_mautrix_telegram_container_self_build|bool"
  48. - name: Ensure lottieconverter repository is present when self-building
  49. git:
  50. repo: "{{ matrix_mautrix_telegram_lottieconverter_docker_repo }}"
  51. dest: "{{ matrix_mautrix_telegram_lottieconverter_docker_src_files_path }}"
  52. force: "yes"
  53. register: matrix_mautrix_telegram_lottieconverter_git_pull_results
  54. when: "matrix_mautrix_telegram_container_self_build|bool"
  55. - name: Ensure lottieconverter Docker image is build
  56. docker_image:
  57. name: "{{ matrix_mautrix_telegram_lottieconverter_docker_image }}"
  58. source: build
  59. force_source: yes
  60. build:
  61. dockerfile: Dockerfile
  62. path: "{{ matrix_mautrix_telegram_lottieconverter_docker_src_files_path }}"
  63. pull: yes
  64. when: "matrix_mautrix_telegram_container_self_build|bool and matrix_mautrix_telegram_lottieconverter_git_pull_results.changed"
  65. - name: Ensure matrix-mautrix-telegram repository is present when self-building
  66. git:
  67. repo: "{{ matrix_mautrix_telegram_docker_repo }}"
  68. dest: "{{ matrix_mautrix_telegram_docker_src_files_path }}"
  69. force: "yes"
  70. register: matrix_mautrix_telegram_git_pull_results
  71. when: "matrix_mautrix_telegram_container_self_build|bool"
  72. - name: Ensure matrix-mautrix-telegram Docker image is built
  73. docker_image:
  74. name: "{{ matrix_mautrix_telegram_docker_image }}"
  75. source: build
  76. force_source: "{{ matrix_mautrix_telegram_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  77. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_telegram_git_pull_results.changed }}"
  78. build:
  79. dockerfile: Dockerfile
  80. path: "{{ matrix_mautrix_telegram_docker_src_files_path }}"
  81. pull: no
  82. when: "matrix_mautrix_telegram_container_self_build|bool and matrix_mautrix_telegram_git_pull_results.changed"
  83. - name: Check if an old database file already exists
  84. stat:
  85. path: "{{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db"
  86. register: matrix_mautrix_telegram_stat_database
  87. - name: (Data relocation) Ensure matrix-mautrix-telegram.service is stopped
  88. service:
  89. name: matrix-mautrix-telegram
  90. state: stopped
  91. daemon_reload: yes
  92. failed_when: false
  93. when: "matrix_mautrix_telegram_stat_database.stat.exists"
  94. - name: (Data relocation) Move mautrix-telegram database file to ./data directory
  95. command: "mv {{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db {{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db"
  96. when: "matrix_mautrix_telegram_stat_database.stat.exists"
  97. - name: Ensure mautrix-telegram config.yaml installed
  98. copy:
  99. content: "{{ matrix_mautrix_telegram_configuration|to_nice_yaml }}"
  100. dest: "{{ matrix_mautrix_telegram_config_path }}/config.yaml"
  101. mode: 0644
  102. owner: "{{ matrix_user_username }}"
  103. group: "{{ matrix_user_groupname }}"
  104. - name: Ensure mautrix-telegram registration.yaml installed
  105. copy:
  106. content: "{{ matrix_mautrix_telegram_registration|to_nice_yaml }}"
  107. dest: "{{ matrix_mautrix_telegram_config_path }}/registration.yaml"
  108. mode: 0644
  109. owner: "{{ matrix_user_username }}"
  110. group: "{{ matrix_user_groupname }}"
  111. - name: Ensure matrix-mautrix-telegram.service installed
  112. template:
  113. src: "{{ role_path }}/templates/systemd/matrix-mautrix-telegram.service.j2"
  114. dest: "{{ matrix_systemd_path }}/matrix-mautrix-telegram.service"
  115. mode: 0644
  116. register: matrix_mautrix_telegram_systemd_service_result
  117. - name: Ensure systemd reloaded after matrix-mautrix-telegram.service installation
  118. service:
  119. daemon_reload: yes
  120. when: "matrix_mautrix_telegram_systemd_service_result.changed"
  121. - name: Ensure matrix-mautrix-telegram.service restarted, if necessary
  122. service:
  123. name: "matrix-mautrix-telegram.service"
  124. state: restarted
  125. when: "matrix_mautrix_telegram_requires_restart|bool"