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.
 
 

103 wiersze
4.8 KiB

  1. ---
  2. - block:
  3. - name: Check if an SQLite database already exists
  4. stat:
  5. path: "{{ matrix_appservice_discord_sqlite_database_path_local }}"
  6. register: matrix_appservice_discord_sqlite_database_path_local_stat_result
  7. - name: Fail if an SQLite database already exists when using Postgres
  8. fail:
  9. msg: >-
  10. matrix_appservice_discord_database_engine has been set to `postgres` (which is our new default now).
  11. However, we've discovered an existing SQLite database in {{ matrix_appservice_discord_sqlite_database_path_local }}.
  12. It appears that you've been using this bridge with the SQLite engine until now.
  13. To continue using SQLite, opt into it explicitly: add `matrix_appservice_discord_database_engine: sqlite` to your vars.yml file and re-run this same command.
  14. Alternatively, to migrate your existing SQLite database to Postgres:
  15. 1. Stop all services (`ansible-playbook -i inventory/hosts setup.yml --tags=stop`)
  16. 2. Import the SQLite database into Postgres (`ansible-playbook -v -i inventory/hosts setup.yml --tags=import-generic-sqlite-db --extra-vars='sqlite_database_path={{ matrix_appservice_discord_sqlite_database_path_local }} postgres_connection_string_variable_name=matrix_appservice_discord_database_connString'`)
  17. 3. Re-run the playbook (`ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start`)
  18. when: "matrix_appservice_discord_sqlite_database_path_local_stat_result.stat.exists"
  19. when: "matrix_appservice_discord_database_engine == 'postgres'"
  20. - name: Ensure Appservice Discord image is pulled
  21. docker_image:
  22. name: "{{ matrix_appservice_discord_docker_image }}"
  23. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  24. force_source: "{{ matrix_appservice_discord_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  25. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_discord_docker_image_force_pull }}"
  26. - name: Ensure AppService Discord paths exist
  27. file:
  28. path: "{{ item }}"
  29. state: directory
  30. mode: 0750
  31. owner: "{{ matrix_user_username }}"
  32. group: "{{ matrix_user_groupname }}"
  33. with_items:
  34. - "{{ matrix_appservice_discord_base_path }}"
  35. - "{{ matrix_appservice_discord_config_path }}"
  36. - "{{ matrix_appservice_discord_data_path }}"
  37. - name: Check if an old database file already exists
  38. stat:
  39. path: "{{ matrix_appservice_discord_base_path }}/discord.db"
  40. register: matrix_appservice_discord_stat_db
  41. - name: (Data relocation) Ensure matrix-appservice-discord.service is stopped
  42. service:
  43. name: matrix-appservice-discord
  44. state: stopped
  45. daemon_reload: yes
  46. failed_when: false
  47. when: "matrix_appservice_discord_stat_db.stat.exists"
  48. - name: (Data relocation) Move AppService Discord discord.db file to ./data directory
  49. command: "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}"
  50. with_items:
  51. - discord.db
  52. - user-store.db
  53. - room-store.db
  54. when: "matrix_appservice_discord_stat_db.stat.exists"
  55. - name: Ensure AppService Discord config.yaml installed
  56. copy:
  57. content: "{{ matrix_appservice_discord_configuration|to_nice_yaml }}"
  58. dest: "{{ matrix_appservice_discord_config_path }}/config.yaml"
  59. mode: 0644
  60. owner: "{{ matrix_user_username }}"
  61. group: "{{ matrix_user_groupname }}"
  62. - name: Ensure AppService Discord registration.yaml installed
  63. copy:
  64. content: "{{ matrix_appservice_discord_registration|to_nice_yaml }}"
  65. dest: "{{ matrix_appservice_discord_config_path }}/registration.yaml"
  66. mode: 0644
  67. owner: "{{ matrix_user_username }}"
  68. group: "{{ matrix_user_groupname }}"
  69. # If `matrix_appservice_discord_client_id` hasn't changed, the same invite link would be generated.
  70. # We intentionally suppress Ansible changes.
  71. - name: Generate AppService Discord invite link
  72. shell: >-
  73. {{ matrix_host_command_docker }} run --rm --name matrix-appservice-discord-link-gen
  74. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  75. --cap-drop=ALL
  76. --mount type=bind,src={{ matrix_appservice_discord_config_path }},dst=/cfg
  77. -w /cfg
  78. {{ matrix_appservice_discord_docker_image }}
  79. /bin/sh -c "node /build/tools/addbot.js > /cfg/invite_link"
  80. changed_when: false
  81. - name: Ensure matrix-appservice-discord.service installed
  82. template:
  83. src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2"
  84. dest: "{{ matrix_systemd_path }}/matrix-appservice-discord.service"
  85. mode: 0644
  86. register: matrix_appservice_discord_systemd_service_result
  87. - name: Ensure systemd reloaded after matrix-appservice-discord.service installation
  88. service:
  89. daemon_reload: yes
  90. when: "matrix_appservice_discord_systemd_service_result.changed"