Matrix Docker Ansible eploy
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

134 wiersze
5.7 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. register: matrix_mautrix_googlechat_git_pull_results
  60. when: "matrix_mautrix_googlechat_container_image_self_build|bool"
  61. - name: Ensure Mautrix googlechat Docker image is built
  62. docker_image:
  63. name: "{{ matrix_mautrix_googlechat_docker_image }}"
  64. source: build
  65. force_source: "{{ matrix_mautrix_googlechat_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  66. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_googlechat_git_pull_results.changed }}"
  67. build:
  68. dockerfile: Dockerfile
  69. path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  70. pull: true
  71. when: "matrix_mautrix_googlechat_container_image_self_build|bool"
  72. - name: Check if an old database file already exists
  73. stat:
  74. path: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  75. register: matrix_mautrix_googlechat_stat_database
  76. - name: (Data relocation) Ensure matrix-mautrix-googlechat.service is stopped
  77. service:
  78. name: matrix-mautrix-googlechat
  79. state: stopped
  80. enabled: false
  81. daemon_reload: true
  82. failed_when: false
  83. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  84. - name: (Data relocation) Move mautrix-googlechat database file to ./data directory
  85. command: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  86. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  87. - name: Ensure mautrix-googlechat config.yaml installed
  88. copy:
  89. content: "{{ matrix_mautrix_googlechat_configuration|to_nice_yaml(indent=2, width=999999) }}"
  90. dest: "{{ matrix_mautrix_googlechat_config_path }}/config.yaml"
  91. mode: 0644
  92. owner: "{{ matrix_user_username }}"
  93. group: "{{ matrix_user_groupname }}"
  94. - name: Ensure mautrix-googlechat registration.yaml installed
  95. copy:
  96. content: "{{ matrix_mautrix_googlechat_registration|to_nice_yaml(indent=2, width=999999) }}"
  97. dest: "{{ matrix_mautrix_googlechat_config_path }}/registration.yaml"
  98. mode: 0644
  99. owner: "{{ matrix_user_username }}"
  100. group: "{{ matrix_user_groupname }}"
  101. - name: Ensure matrix-mautrix-googlechat.service installed
  102. template:
  103. src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2"
  104. dest: "{{ matrix_systemd_path }}/matrix-mautrix-googlechat.service"
  105. mode: 0644
  106. register: matrix_mautrix_googlechat_systemd_service_result
  107. - name: Ensure systemd reloaded after matrix-mautrix-googlechat.service installation
  108. service:
  109. daemon_reload: true
  110. when: "matrix_mautrix_googlechat_systemd_service_result.changed"
  111. - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary
  112. service:
  113. name: "matrix-mautrix-googlechat.service"
  114. state: restarted
  115. when: "matrix_mautrix_googlechat_requires_restart|bool"