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.
 
 

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