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

150 строки
7.0 KiB

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