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

106 строки
4.9 KiB

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