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

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