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

130 строки
5.6 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. - name: Ensure Mautrix googlechat paths exist
  38. file:
  39. path: "{{ item.path }}"
  40. state: directory
  41. mode: 0750
  42. owner: "{{ matrix_user_username }}"
  43. group: "{{ matrix_user_groupname }}"
  44. with_items:
  45. - { path: "{{ matrix_mautrix_googlechat_base_path }}", when: true }
  46. - { path: "{{ matrix_mautrix_googlechat_config_path }}", when: true }
  47. - { path: "{{ matrix_mautrix_googlechat_data_path }}", when: true }
  48. - { path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}", when: "{{ matrix_mautrix_googlechat_container_image_self_build }}" }
  49. when: "item.when|bool"
  50. - name: Ensure Mautrix Hangots repository is present on self build
  51. git:
  52. repo: "{{ matrix_mautrix_googlechat_container_image_self_build_repo }}"
  53. dest: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  54. force: "yes"
  55. register: matrix_mautrix_googlechat_git_pull_results
  56. when: "matrix_mautrix_googlechat_container_image_self_build|bool"
  57. - name: Ensure Mautrix googlechat Docker image is built
  58. docker_image:
  59. name: "{{ matrix_mautrix_googlechat_docker_image }}"
  60. source: build
  61. force_source: "{{ matrix_mautrix_googlechat_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_googlechat_git_pull_results.changed }}"
  63. build:
  64. dockerfile: Dockerfile
  65. path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  66. pull: yes
  67. when: "matrix_mautrix_googlechat_container_image_self_build|bool"
  68. - name: Check if an old database file already exists
  69. stat:
  70. path: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  71. register: matrix_mautrix_googlechat_stat_database
  72. - name: (Data relocation) Ensure matrix-mautrix-googlechat.service is stopped
  73. service:
  74. name: matrix-mautrix-googlechat
  75. state: stopped
  76. enabled: no
  77. daemon_reload: yes
  78. failed_when: false
  79. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  80. - name: (Data relocation) Move mautrix-googlechat database file to ./data directory
  81. command: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  82. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  83. - name: Ensure mautrix-googlechat config.yaml installed
  84. copy:
  85. content: "{{ matrix_mautrix_googlechat_configuration|to_nice_yaml }}"
  86. dest: "{{ matrix_mautrix_googlechat_config_path }}/config.yaml"
  87. mode: 0644
  88. owner: "{{ matrix_user_username }}"
  89. group: "{{ matrix_user_groupname }}"
  90. - name: Ensure mautrix-googlechat registration.yaml installed
  91. copy:
  92. content: "{{ matrix_mautrix_googlechat_registration|to_nice_yaml }}"
  93. dest: "{{ matrix_mautrix_googlechat_config_path }}/registration.yaml"
  94. mode: 0644
  95. owner: "{{ matrix_user_username }}"
  96. group: "{{ matrix_user_groupname }}"
  97. - name: Ensure matrix-mautrix-googlechat.service installed
  98. template:
  99. src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2"
  100. dest: "{{ matrix_systemd_path }}/matrix-mautrix-googlechat.service"
  101. mode: 0644
  102. register: matrix_mautrix_googlechat_systemd_service_result
  103. - name: Ensure systemd reloaded after matrix-mautrix-googlechat.service installation
  104. service:
  105. daemon_reload: yes
  106. when: "matrix_mautrix_googlechat_systemd_service_result.changed"
  107. - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary
  108. service:
  109. name: "matrix-mautrix-googlechat.service"
  110. state: restarted
  111. when: "matrix_mautrix_googlechat_requires_restart|bool"