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

137 строки
6.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. ansible.builtin.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. - ansible.builtin.set_fact:
  10. matrix_mautrix_googlechat_requires_restart: false
  11. - block:
  12. - name: Check if an SQLite database already exists
  13. ansible.builtin.stat:
  14. path: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}"
  15. register: matrix_mautrix_googlechat_sqlite_database_path_local_stat_result
  16. - block:
  17. - ansible.builtin.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. - ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
  26. - ansible.builtin.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. ansible.builtin.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. ansible.builtin.git:
  56. repo: "{{ matrix_mautrix_googlechat_container_image_self_build_repo }}"
  57. version: "{{ matrix_mautrix_googlechat_container_image_self_build_repo_version }}"
  58. dest: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  59. force: "yes"
  60. become: true
  61. become_user: "{{ matrix_user_username }}"
  62. register: matrix_mautrix_googlechat_git_pull_results
  63. when: "matrix_mautrix_googlechat_container_image_self_build | bool"
  64. - name: Ensure Mautrix googlechat Docker image is built
  65. docker_image:
  66. name: "{{ matrix_mautrix_googlechat_docker_image }}"
  67. source: build
  68. force_source: "{{ matrix_mautrix_googlechat_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  69. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_googlechat_git_pull_results.changed }}"
  70. build:
  71. dockerfile: Dockerfile
  72. path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  73. pull: true
  74. when: "matrix_mautrix_googlechat_container_image_self_build | bool"
  75. - name: Check if an old database file already exists
  76. ansible.builtin.stat:
  77. path: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  78. register: matrix_mautrix_googlechat_stat_database
  79. - name: (Data relocation) Ensure matrix-mautrix-googlechat.service is stopped
  80. ansible.builtin.service:
  81. name: matrix-mautrix-googlechat
  82. state: stopped
  83. enabled: false
  84. daemon_reload: true
  85. failed_when: false
  86. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  87. - name: (Data relocation) Move mautrix-googlechat database file to ./data directory
  88. ansible.builtin.command: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  89. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  90. - name: Ensure mautrix-googlechat config.yaml installed
  91. ansible.builtin.copy:
  92. content: "{{ matrix_mautrix_googlechat_configuration | to_nice_yaml(indent=2, width=999999) }}"
  93. dest: "{{ matrix_mautrix_googlechat_config_path }}/config.yaml"
  94. mode: 0644
  95. owner: "{{ matrix_user_username }}"
  96. group: "{{ matrix_user_groupname }}"
  97. - name: Ensure mautrix-googlechat registration.yaml installed
  98. ansible.builtin.copy:
  99. content: "{{ matrix_mautrix_googlechat_registration | to_nice_yaml(indent=2, width=999999) }}"
  100. dest: "{{ matrix_mautrix_googlechat_config_path }}/registration.yaml"
  101. mode: 0644
  102. owner: "{{ matrix_user_username }}"
  103. group: "{{ matrix_user_groupname }}"
  104. - name: Ensure matrix-mautrix-googlechat.service installed
  105. ansible.builtin.template:
  106. src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2"
  107. dest: "{{ matrix_systemd_path }}/matrix-mautrix-googlechat.service"
  108. mode: 0644
  109. register: matrix_mautrix_googlechat_systemd_service_result
  110. - name: Ensure systemd reloaded after matrix-mautrix-googlechat.service installation
  111. ansible.builtin.service:
  112. daemon_reload: true
  113. when: "matrix_mautrix_googlechat_systemd_service_result.changed"
  114. - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary
  115. ansible.builtin.service:
  116. name: "matrix-mautrix-googlechat.service"
  117. state: restarted
  118. when: "matrix_mautrix_googlechat_requires_restart | bool"