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

145 строки
6.2 KiB

  1. # SPDX-FileCopyrightText: 2022 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2022 MDAD project contributors
  3. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  4. # SPDX-FileCopyrightText: 2024 David Mehren
  5. #
  6. # SPDX-License-Identifier: AGPL-3.0-or-later
  7. ---
  8. - ansible.builtin.set_fact:
  9. matrix_mautrix_discord_migration_requires_restart: false
  10. - when: "matrix_mautrix_discord_database_engine == 'postgres'"
  11. block:
  12. - name: Check if an SQLite database already exists
  13. ansible.builtin.stat:
  14. path: "{{ matrix_mautrix_discord_sqlite_database_path_local }}"
  15. register: matrix_mautrix_discord_sqlite_database_path_local_stat_result
  16. - when: "matrix_mautrix_discord_sqlite_database_path_local_stat_result.stat.exists | bool"
  17. block:
  18. - ansible.builtin.include_role:
  19. name: galaxy/postgres
  20. tasks_from: migrate_db_to_postgres
  21. vars:
  22. postgres_db_migration_request:
  23. src: "{{ matrix_mautrix_discord_sqlite_database_path_local }}"
  24. dst: "{{ matrix_mautrix_discord_database_connection_string }}"
  25. caller: "{{ role_path | basename }}"
  26. engine_variable_name: 'matrix_mautrix_discord_database_engine'
  27. engine_old: 'sqlite'
  28. systemd_services_to_stop: ['matrix-mautrix-discord.service']
  29. pgloader_options: ['--with "quote identifiers"']
  30. - ansible.builtin.set_fact:
  31. matrix_mautrix_discord_migration_requires_restart: true
  32. - name: Ensure Mautrix Discord paths exists
  33. ansible.builtin.file:
  34. path: "{{ item.path }}"
  35. state: directory
  36. mode: '0750'
  37. owner: "{{ matrix_user_name }}"
  38. group: "{{ matrix_group_name }}"
  39. with_items:
  40. - {path: "{{ matrix_mautrix_discord_base_path }}", when: true}
  41. - {path: "{{ matrix_mautrix_discord_config_path }}", when: true}
  42. - {path: "{{ matrix_mautrix_discord_data_path }}", when: true}
  43. - {path: "{{ matrix_mautrix_discord_container_src_files_path }}", when: "{{ matrix_mautrix_discord_container_image_self_build }}"}
  44. when: item.when | bool
  45. - name: Ensure Mautrix Discord image is pulled
  46. community.docker.docker_image_pull:
  47. name: "{{ matrix_mautrix_discord_container_image }}"
  48. pull: always
  49. when: not matrix_mautrix_discord_container_image_self_build
  50. register: matrix_mautrix_discord_container_image_pull_result
  51. retries: "{{ devture_playbook_help_container_retries_count }}"
  52. delay: "{{ devture_playbook_help_container_retries_delay }}"
  53. until: matrix_mautrix_discord_container_image_pull_result is not failed
  54. - name: Ensure Mautrix discord repository is present on self-build
  55. ansible.builtin.git:
  56. repo: "{{ matrix_mautrix_discord_container_image_self_build_repo }}"
  57. dest: "{{ matrix_mautrix_discord_container_src_files_path }}"
  58. version: "{{ matrix_mautrix_discord_container_image_self_build_branch }}"
  59. force: "yes"
  60. become: true
  61. become_user: "{{ matrix_user_name }}"
  62. register: matrix_mautrix_discord_git_pull_results
  63. when: "matrix_mautrix_discord_container_image_self_build | bool"
  64. - name: Ensure Mautrix discord Docker image is built
  65. community.docker.docker_image_build:
  66. name: "{{ matrix_mautrix_discord_container_image }}"
  67. dockerfile: Dockerfile
  68. path: "{{ matrix_mautrix_discord_container_src_files_path }}"
  69. pull: true
  70. rebuild: "{{ 'always' if matrix_mautrix_discord_git_pull_results.changed | bool else 'never' }}"
  71. when: "matrix_mautrix_discord_container_image_self_build | bool"
  72. register: matrix_mautrix_discord_container_image_build_result
  73. - name: Ensure mautrix-discord config.yaml installed
  74. ansible.builtin.copy:
  75. content: "{{ matrix_mautrix_discord_configuration | to_nice_yaml(indent=2, width=999999) }}"
  76. dest: "{{ matrix_mautrix_discord_config_path }}/config.yaml"
  77. mode: '0644'
  78. owner: "{{ matrix_user_name }}"
  79. group: "{{ matrix_group_name }}"
  80. register: matrix_mautrix_discord_config_result
  81. - name: Ensure mautrix-discord registration.yaml installed
  82. ansible.builtin.copy:
  83. content: "{{ matrix_mautrix_discord_registration | to_nice_yaml(indent=2, width=999999) }}"
  84. dest: "{{ matrix_mautrix_discord_config_path }}/registration.yaml"
  85. mode: '0644'
  86. owner: "{{ matrix_user_name }}"
  87. group: "{{ matrix_group_name }}"
  88. register: matrix_mautrix_discord_registration_result
  89. - name: Ensure mautrix-discord support files installed
  90. ansible.builtin.template:
  91. src: "{{ role_path }}/templates/{{ item }}.j2"
  92. dest: "{{ matrix_mautrix_discord_base_path }}/{{ item }}"
  93. mode: '0640'
  94. owner: "{{ matrix_user_name }}"
  95. group: "{{ matrix_group_name }}"
  96. with_items:
  97. - labels
  98. register: matrix_mautrix_discord_support_files_result
  99. - name: Ensure mautrix-discord container network is created
  100. community.general.docker_network:
  101. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  102. name: "{{ matrix_mautrix_discord_container_network }}"
  103. driver: bridge
  104. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  105. - name: Ensure matrix-mautrix-discord.service installed
  106. ansible.builtin.template:
  107. src: "{{ role_path }}/templates/systemd/matrix-mautrix-discord.service.j2"
  108. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-mautrix-discord.service"
  109. mode: '0644'
  110. register: matrix_mautrix_discord_systemd_service_result
  111. - name: Determine whether matrix-mautrix-discord needs a restart
  112. ansible.builtin.set_fact:
  113. matrix_mautrix_discord_restart_necessary: >-
  114. {{
  115. matrix_mautrix_discord_migration_requires_restart | default(false)
  116. or matrix_mautrix_discord_config_result.changed | default(false)
  117. or matrix_mautrix_discord_registration_result.changed | default(false)
  118. or matrix_mautrix_discord_support_files_result.changed | default(false)
  119. or matrix_mautrix_discord_systemd_service_result.changed | default(false)
  120. or matrix_mautrix_discord_container_image_pull_result.changed | default(false)
  121. or matrix_mautrix_discord_container_image_build_result.changed | default(false)
  122. }}
  123. - name: Ensure matrix-mautrix-discord.service restarted, if necessary
  124. ansible.builtin.service:
  125. name: "matrix-mautrix-discord.service"
  126. state: restarted
  127. daemon_reload: true
  128. when: "matrix_mautrix_discord_migration_requires_restart | bool"