Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

140 rivejä
5.9 KiB

  1. # SPDX-FileCopyrightText: 2019 - 2020 MDAD project contributors
  2. # SPDX-FileCopyrightText: 2019 - 2024 Slavi Pantaleev
  3. # SPDX-FileCopyrightText: 2019 Dan Arnfield
  4. # SPDX-FileCopyrightText: 2020 Chris van Dijk
  5. # SPDX-FileCopyrightText: 2020 Stuart Mumford
  6. # SPDX-FileCopyrightText: 2022 Jim Myhrberg
  7. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  8. # SPDX-FileCopyrightText: 2022 Nikita Chernyi
  9. # SPDX-FileCopyrightText: 2022 Sebastian Gumprich
  10. # SPDX-FileCopyrightText: 2024 David Mehren
  11. #
  12. # SPDX-License-Identifier: AGPL-3.0-or-later
  13. ---
  14. - ansible.builtin.set_fact:
  15. matrix_appservice_discord_requires_restart: false
  16. - when: "matrix_appservice_discord_database_engine == 'postgres'"
  17. block:
  18. - name: Check if an SQLite database already exists
  19. ansible.builtin.stat:
  20. path: "{{ matrix_appservice_discord_sqlite_database_path_local }}"
  21. register: matrix_appservice_discord_sqlite_database_path_local_stat_result
  22. - when: "matrix_appservice_discord_sqlite_database_path_local_stat_result.stat.exists | bool"
  23. block:
  24. - ansible.builtin.include_role:
  25. name: galaxy/postgres
  26. tasks_from: migrate_db_to_postgres
  27. vars:
  28. postgres_db_migration_request:
  29. src: "{{ matrix_appservice_discord_sqlite_database_path_local }}"
  30. dst: "{{ matrix_appservice_discord_database_connString }}"
  31. caller: "{{ role_path | basename }}"
  32. engine_variable_name: 'matrix_appservice_discord_database_engine'
  33. engine_old: 'sqlite'
  34. systemd_services_to_stop: ['matrix-appservice-discord.service']
  35. - ansible.builtin.set_fact:
  36. matrix_appservice_discord_requires_restart: true
  37. - name: Ensure Appservice Discord image is pulled
  38. community.docker.docker_image:
  39. name: "{{ matrix_appservice_discord_docker_image }}"
  40. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  41. force_source: "{{ matrix_appservice_discord_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  42. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_discord_docker_image_force_pull }}"
  43. register: result
  44. retries: "{{ devture_playbook_help_container_retries_count }}"
  45. delay: "{{ devture_playbook_help_container_retries_delay }}"
  46. until: result is not failed
  47. - name: Ensure AppService Discord paths exist
  48. ansible.builtin.file:
  49. path: "{{ item }}"
  50. state: directory
  51. mode: 0750
  52. owner: "{{ matrix_user_name }}"
  53. group: "{{ matrix_group_name }}"
  54. with_items:
  55. - "{{ matrix_appservice_discord_base_path }}"
  56. - "{{ matrix_appservice_discord_config_path }}"
  57. - "{{ matrix_appservice_discord_data_path }}"
  58. - name: Check if an old database file already exists
  59. ansible.builtin.stat:
  60. path: "{{ matrix_appservice_discord_base_path }}/discord.db"
  61. register: matrix_appservice_discord_stat_db
  62. - name: (Data relocation) Ensure matrix-appservice-discord.service is stopped
  63. ansible.builtin.service:
  64. name: matrix-appservice-discord
  65. state: stopped
  66. enabled: false
  67. daemon_reload: true
  68. failed_when: false
  69. when: "matrix_appservice_discord_stat_db.stat.exists"
  70. - name: (Data relocation) Move AppService Discord discord.db file to ./data directory
  71. ansible.builtin.command:
  72. cmd: "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}"
  73. creates: "{{ matrix_appservice_discord_data_path }}/{{ item }}"
  74. removes: "{{ matrix_appservice_discord_base_path }}/{{ item }}"
  75. with_items:
  76. - discord.db
  77. - user-store.db
  78. - room-store.db
  79. when: "matrix_appservice_discord_stat_db.stat.exists"
  80. - name: Ensure AppService Discord config.yaml installed
  81. ansible.builtin.copy:
  82. content: "{{ matrix_appservice_discord_configuration | to_nice_yaml(indent=2, width=999999) }}"
  83. dest: "{{ matrix_appservice_discord_config_path }}/config.yaml"
  84. mode: 0644
  85. owner: "{{ matrix_user_name }}"
  86. group: "{{ matrix_group_name }}"
  87. - name: Ensure AppService Discord registration.yaml installed
  88. ansible.builtin.copy:
  89. content: "{{ matrix_appservice_discord_registration | to_nice_yaml(indent=2, width=999999) }}"
  90. dest: "{{ matrix_appservice_discord_config_path }}/registration.yaml"
  91. mode: 0644
  92. owner: "{{ matrix_user_name }}"
  93. group: "{{ matrix_group_name }}"
  94. # If `matrix_appservice_discord_client_id` hasn't changed, the same invite link would be generated.
  95. # We intentionally suppress Ansible changes.
  96. - name: Generate AppService Discord invite link
  97. ansible.builtin.shell: >-
  98. {{ devture_systemd_docker_base_host_command_docker }} run --rm --name matrix-appservice-discord-link-gen
  99. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  100. --cap-drop=ALL
  101. --mount type=bind,src={{ matrix_appservice_discord_config_path }},dst=/cfg
  102. -w /cfg
  103. {{ matrix_appservice_discord_docker_image }}
  104. /bin/sh -c "node /build/tools/addbot.js > /cfg/invite_link"
  105. changed_when: false
  106. - name: Ensure matrix-appservice-discord container network is created
  107. community.general.docker_network:
  108. enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"
  109. name: "{{ matrix_appservice_discord_container_network }}"
  110. driver: bridge
  111. driver_options: "{{ devture_systemd_docker_base_container_networks_driver_options }}"
  112. - name: Ensure matrix-appservice-discord.service installed
  113. ansible.builtin.template:
  114. src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2"
  115. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-discord.service"
  116. mode: 0644
  117. register: matrix_appservice_discord_systemd_service_result
  118. - name: Ensure matrix-appservice-discord.service restarted, if necessary
  119. ansible.builtin.service:
  120. name: "matrix-appservice-discord.service"
  121. state: restarted
  122. daemon_reload: true
  123. when: "matrix_appservice_discord_requires_restart | bool"