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

136 строки
5.8 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-googlechat role needs to execute before the matrix-synapse role.
  8. when: "matrix_synapse_role_executed|default(False)"
  9. - set_fact:
  10. matrix_mautrix_googlechat_requires_restart: false
  11. - block:
  12. - name: Check if an SQLite database already exists
  13. stat:
  14. path: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}"
  15. register: matrix_mautrix_googlechat_sqlite_database_path_local_stat_result
  16. - block:
  17. - set_fact:
  18. matrix_postgres_db_migration_request:
  19. src: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}"
  20. dst: "{{ matrix_mautrix_googlechat_database_connection_string }}"
  21. caller: "{{ role_path|basename }}"
  22. engine_variable_name: 'matrix_mautrix_googlechat_database_engine'
  23. engine_old: 'sqlite'
  24. systemd_services_to_stop: ['matrix-mautrix-googlechat.service']
  25. - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
  26. - set_fact:
  27. matrix_mautrix_googlechat_requires_restart: true
  28. when: "matrix_mautrix_googlechat_sqlite_database_path_local_stat_result.stat.exists|bool"
  29. when: "matrix_mautrix_googlechat_database_engine == 'postgres'"
  30. - name: Ensure Mautrix googlechat image is pulled
  31. docker_image:
  32. name: "{{ matrix_mautrix_googlechat_docker_image }}"
  33. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  34. force_source: "{{ matrix_mautrix_googlechat_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  35. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_googlechat_docker_image_force_pull }}"
  36. when: not matrix_mautrix_googlechat_container_image_self_build
  37. register: result
  38. retries: "{{ matrix_container_retries_count }}"
  39. delay: "{{ matrix_container_retries_delay }}"
  40. until: result is not failed
  41. - name: Ensure Mautrix googlechat paths exist
  42. file:
  43. path: "{{ item.path }}"
  44. state: directory
  45. mode: 0750
  46. owner: "{{ matrix_user_username }}"
  47. group: "{{ matrix_user_groupname }}"
  48. with_items:
  49. - {path: "{{ matrix_mautrix_googlechat_base_path }}", when: true}
  50. - {path: "{{ matrix_mautrix_googlechat_config_path }}", when: true}
  51. - {path: "{{ matrix_mautrix_googlechat_data_path }}", when: true}
  52. - {path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}", when: "{{ matrix_mautrix_googlechat_container_image_self_build }}"}
  53. when: "item.when|bool"
  54. - name: Ensure Mautrix Hangots repository is present on self build
  55. git:
  56. repo: "{{ matrix_mautrix_googlechat_container_image_self_build_repo }}"
  57. dest: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  58. force: "yes"
  59. become: true
  60. become_user: "{{ matrix_user_username }}"
  61. register: matrix_mautrix_googlechat_git_pull_results
  62. when: "matrix_mautrix_googlechat_container_image_self_build|bool"
  63. - name: Ensure Mautrix googlechat Docker image is built
  64. docker_image:
  65. name: "{{ matrix_mautrix_googlechat_docker_image }}"
  66. source: build
  67. force_source: "{{ matrix_mautrix_googlechat_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_mautrix_googlechat_git_pull_results.changed }}"
  69. build:
  70. dockerfile: Dockerfile
  71. path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  72. pull: true
  73. when: "matrix_mautrix_googlechat_container_image_self_build|bool"
  74. - name: Check if an old database file already exists
  75. stat:
  76. path: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  77. register: matrix_mautrix_googlechat_stat_database
  78. - name: (Data relocation) Ensure matrix-mautrix-googlechat.service is stopped
  79. service:
  80. name: matrix-mautrix-googlechat
  81. state: stopped
  82. enabled: false
  83. daemon_reload: true
  84. failed_when: false
  85. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  86. - name: (Data relocation) Move mautrix-googlechat database file to ./data directory
  87. command: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  88. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  89. - name: Ensure mautrix-googlechat config.yaml installed
  90. copy:
  91. content: "{{ matrix_mautrix_googlechat_configuration|to_nice_yaml(indent=2, width=999999) }}"
  92. dest: "{{ matrix_mautrix_googlechat_config_path }}/config.yaml"
  93. mode: 0644
  94. owner: "{{ matrix_user_username }}"
  95. group: "{{ matrix_user_groupname }}"
  96. - name: Ensure mautrix-googlechat registration.yaml installed
  97. copy:
  98. content: "{{ matrix_mautrix_googlechat_registration|to_nice_yaml(indent=2, width=999999) }}"
  99. dest: "{{ matrix_mautrix_googlechat_config_path }}/registration.yaml"
  100. mode: 0644
  101. owner: "{{ matrix_user_username }}"
  102. group: "{{ matrix_user_groupname }}"
  103. - name: Ensure matrix-mautrix-googlechat.service installed
  104. template:
  105. src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2"
  106. dest: "{{ matrix_systemd_path }}/matrix-mautrix-googlechat.service"
  107. mode: 0644
  108. register: matrix_mautrix_googlechat_systemd_service_result
  109. - name: Ensure systemd reloaded after matrix-mautrix-googlechat.service installation
  110. service:
  111. daemon_reload: true
  112. when: "matrix_mautrix_googlechat_systemd_service_result.changed"
  113. - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary
  114. service:
  115. name: "matrix-mautrix-googlechat.service"
  116. state: restarted
  117. when: "matrix_mautrix_googlechat_requires_restart|bool"