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

156 строки
6.9 KiB

  1. # SPDX-FileCopyrightText: 2022 - 2024 Slavi Pantaleev
  2. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  3. # SPDX-FileCopyrightText: 2022 Vladimir Panteleev
  4. # SPDX-FileCopyrightText: 2024 David Mehren
  5. #
  6. # SPDX-License-Identifier: AGPL-3.0-or-later
  7. ---
  8. - ansible.builtin.set_fact:
  9. matrix_go_skype_bridge_requires_restart: false
  10. - when: "matrix_go_skype_bridge_database_engine == 'postgres'"
  11. block:
  12. - name: Check if an SQLite database already exists
  13. ansible.builtin.stat:
  14. path: "{{ matrix_go_skype_bridge_sqlite_database_path_local }}"
  15. register: matrix_go_skype_bridge_sqlite_database_path_local_stat_result
  16. - when: "matrix_go_skype_bridge_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_go_skype_bridge_sqlite_database_path_local }}"
  24. dst: "{{ matrix_go_skype_bridge_database_connection_string }}"
  25. caller: "{{ role_path | basename }}"
  26. engine_variable_name: 'matrix_go_skype_bridge_database_engine'
  27. engine_old: 'sqlite'
  28. systemd_services_to_stop: ['matrix-go-skype-bridge.service']
  29. pgloader_options: ['--with "quote identifiers"']
  30. - ansible.builtin.set_fact:
  31. matrix_go_skype_bridge_requires_restart: true
  32. - name: Ensure Go Skype Bridge paths exists
  33. ansible.builtin.file:
  34. path: "{{ item.path }}"
  35. state: directory
  36. mode: 0750
  37. owner: "{{ matrix_user_username }}"
  38. group: "{{ matrix_user_groupname }}"
  39. with_items:
  40. - {path: "{{ matrix_go_skype_bridge_base_path }}", when: true}
  41. - {path: "{{ matrix_go_skype_bridge_config_path }}", when: true}
  42. - {path: "{{ matrix_go_skype_bridge_data_path }}", when: true}
  43. - {path: "{{ matrix_go_skype_bridge_docker_src_files_path }}", when: "{{ matrix_go_skype_bridge_container_image_self_build }}"}
  44. when: item.when | bool
  45. - name: Ensure Go Skype Bridge image is pulled
  46. community.docker.docker_image:
  47. name: "{{ matrix_go_skype_bridge_docker_image }}"
  48. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  49. force_source: "{{ matrix_go_skype_bridge_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  50. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_go_skype_bridge_docker_image_force_pull }}"
  51. when: not matrix_go_skype_bridge_container_image_self_build
  52. register: result
  53. retries: "{{ devture_playbook_help_container_retries_count }}"
  54. delay: "{{ devture_playbook_help_container_retries_delay }}"
  55. until: result is not failed
  56. - name: Ensure Go Skype Bridge repository is present on self-build
  57. ansible.builtin.git:
  58. repo: "{{ matrix_go_skype_bridge_container_image_self_build_repo }}"
  59. dest: "{{ matrix_go_skype_bridge_docker_src_files_path }}"
  60. version: "{{ matrix_go_skype_bridge_container_image_self_build_branch }}"
  61. force: "yes"
  62. become: true
  63. become_user: "{{ matrix_user_username }}"
  64. register: matrix_go_skype_bridge_git_pull_results
  65. when: "matrix_go_skype_bridge_container_image_self_build | bool"
  66. - name: Ensure Go Skype Bridge Docker image is built
  67. community.docker.docker_image:
  68. name: "{{ matrix_go_skype_bridge_docker_image }}"
  69. source: build
  70. force_source: "{{ matrix_go_skype_bridge_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_go_skype_bridge_git_pull_results.changed }}"
  72. build:
  73. dockerfile: Dockerfile
  74. path: "{{ matrix_go_skype_bridge_docker_src_files_path }}"
  75. pull: true
  76. when: "matrix_go_skype_bridge_container_image_self_build | bool"
  77. - name: Check if an old database file exists
  78. ansible.builtin.stat:
  79. path: "{{ matrix_go_skype_bridge_base_path }}/go-skype-bridge.db"
  80. register: matrix_go_skype_bridge_stat_database
  81. - name: Check if an old Matrix state file exists
  82. ansible.builtin.stat:
  83. path: "{{ matrix_go_skype_bridge_base_path }}/mx-state.json"
  84. register: matrix_go_skype_bridge_stat_mx_state
  85. - name: (Data relocation) Ensure matrix-go-skype-bridge.service is stopped
  86. ansible.builtin.service:
  87. name: matrix-go-skype-bridge
  88. state: stopped
  89. enabled: false
  90. daemon_reload: true
  91. failed_when: false
  92. when: "matrix_go_skype_bridge_stat_database.stat.exists"
  93. - name: (Data relocation) Move go-skype-bridge database file to ./data directory
  94. ansible.builtin.command:
  95. cmd: "mv {{ matrix_go_skype_bridge_base_path }}/go-skype-bridge.db {{ matrix_go_skype_bridge_data_path }}/go-skype-bridge.db"
  96. creates: "{{ matrix_go_skype_bridge_data_path }}/go-skype-bridge.db"
  97. removes: "{{ matrix_go_skype_bridge_base_path }}/go-skype-bridge.db"
  98. when: "matrix_go_skype_bridge_stat_database.stat.exists"
  99. - name: (Data relocation) Move go-skype-bridge mx-state file to ./data directory
  100. ansible.builtin.command:
  101. cmd: "mv {{ matrix_go_skype_bridge_base_path }}/mx-state.json {{ matrix_go_skype_bridge_data_path }}/mx-state.json"
  102. creates: "{{ matrix_go_skype_bridge_data_path }}/mx-state.json"
  103. removes: "{{ matrix_go_skype_bridge_base_path }}/mx-state.json"
  104. when: "matrix_go_skype_bridge_stat_mx_state.stat.exists"
  105. - name: Ensure go-skype-bridge config.yaml installed
  106. ansible.builtin.copy:
  107. content: "{{ matrix_go_skype_bridge_configuration | to_nice_yaml(indent=2, width=999999) }}"
  108. dest: "{{ matrix_go_skype_bridge_config_path }}/config.yaml"
  109. mode: 0644
  110. owner: "{{ matrix_user_username }}"
  111. group: "{{ matrix_user_groupname }}"
  112. - name: Ensure go-skype-bridge registration.yaml installed
  113. ansible.builtin.copy:
  114. content: "{{ matrix_go_skype_bridge_registration | to_nice_yaml(indent=2, width=999999) }}"
  115. dest: "{{ matrix_go_skype_bridge_config_path }}/registration.yaml"
  116. mode: 0644
  117. owner: "{{ matrix_user_username }}"
  118. group: "{{ matrix_user_groupname }}"
  119. - name: Ensure matrix-go-skype-bridge container network is created
  120. community.general.docker_network:
  121. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  122. name: "{{ matrix_go_skype_bridge_container_network }}"
  123. driver: bridge
  124. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  125. - name: Ensure matrix-go-skype-bridge.service installed
  126. ansible.builtin.template:
  127. src: "{{ role_path }}/templates/systemd/matrix-go-skype-bridge.service.j2"
  128. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-go-skype-bridge.service"
  129. mode: 0644
  130. register: matrix_go_skype_bridge_systemd_service_result
  131. - name: Ensure matrix-go-skype-bridge.service restarted, if necessary
  132. ansible.builtin.service:
  133. name: "matrix-go-skype-bridge.service"
  134. state: restarted
  135. daemon_reload: true
  136. when: "matrix_go_skype_bridge_requires_restart | bool"