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.
 
 

128 wiersze
5.2 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. - { 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_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_self_build|bool"
  50. - name: Ensure matrix-mautrix-telegram repository is present when self-building
  51. git:
  52. repo: "{{ matrix_mautrix_telegram_docker_repo }}"
  53. dest: "{{ matrix_mautrix_telegram_docker_src_files_path }}"
  54. force: "yes"
  55. register: matrix_mautrix_telegram_git_pull_results
  56. when: "matrix_mautrix_telegram_container_self_build|bool"
  57. - name: Ensure matrix-mautrix-telegram Docker image is build
  58. docker_image:
  59. name: "{{ matrix_mautrix_telegram_docker_image }}"
  60. source: build
  61. force_source: yes
  62. build:
  63. dockerfile: Dockerfile
  64. path: "{{ matrix_mautrix_telegram_docker_src_files_path }}"
  65. pull: yes
  66. when: "matrix_mautrix_telegram_container_self_build|bool and matrix_mautrix_telegram_git_pull_results.changed"
  67. - name: Check if an old database file already exists
  68. stat:
  69. path: "{{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db"
  70. register: matrix_mautrix_telegram_stat_database
  71. - name: (Data relocation) Ensure matrix-mautrix-telegram.service is stopped
  72. service:
  73. name: matrix-mautrix-telegram
  74. state: stopped
  75. daemon_reload: yes
  76. failed_when: false
  77. when: "matrix_mautrix_telegram_stat_database.stat.exists"
  78. - name: (Data relocation) Move mautrix-telegram database file to ./data directory
  79. command: "mv {{ matrix_mautrix_telegram_base_path }}/mautrix-telegram.db {{ matrix_mautrix_telegram_data_path }}/mautrix-telegram.db"
  80. when: "matrix_mautrix_telegram_stat_database.stat.exists"
  81. - name: Ensure mautrix-telegram config.yaml installed
  82. copy:
  83. content: "{{ matrix_mautrix_telegram_configuration|to_nice_yaml }}"
  84. dest: "{{ matrix_mautrix_telegram_config_path }}/config.yaml"
  85. mode: 0644
  86. owner: "{{ matrix_user_username }}"
  87. group: "{{ matrix_user_groupname }}"
  88. - name: Ensure mautrix-telegram registration.yaml installed
  89. copy:
  90. content: "{{ matrix_mautrix_telegram_registration|to_nice_yaml }}"
  91. dest: "{{ matrix_mautrix_telegram_config_path }}/registration.yaml"
  92. mode: 0644
  93. owner: "{{ matrix_user_username }}"
  94. group: "{{ matrix_user_groupname }}"
  95. - name: Ensure matrix-mautrix-telegram.service installed
  96. template:
  97. src: "{{ role_path }}/templates/systemd/matrix-mautrix-telegram.service.j2"
  98. dest: "{{ matrix_systemd_path }}/matrix-mautrix-telegram.service"
  99. mode: 0644
  100. register: matrix_mautrix_telegram_systemd_service_result
  101. - name: Ensure systemd reloaded after matrix-mautrix-telegram.service installation
  102. service:
  103. daemon_reload: yes
  104. when: "matrix_mautrix_telegram_systemd_service_result.changed"
  105. - name: Ensure matrix-mautrix-telegram.service restarted, if necessary
  106. service:
  107. name: "matrix-mautrix-telegram.service"
  108. state: restarted
  109. when: "matrix_mautrix_telegram_requires_restart|bool"