Matrix Docker Ansible eploy
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

116 lignes
4.6 KiB

  1. ---
  2. - set_fact:
  3. matrix_appservice_discord_requires_restart: false
  4. - block:
  5. - name: Check if an SQLite database already exists
  6. stat:
  7. path: "{{ matrix_appservice_discord_sqlite_database_path_local }}"
  8. register: matrix_appservice_discord_sqlite_database_path_local_stat_result
  9. - block:
  10. - set_fact:
  11. matrix_postgres_db_migration_request:
  12. src: "{{ matrix_appservice_discord_sqlite_database_path_local }}"
  13. dst: "{{ matrix_appservice_discord_database_connString }}"
  14. caller: "{{ role_path|basename }}"
  15. engine_variable_name: 'matrix_appservice_discord_database_engine'
  16. engine_old: 'sqlite'
  17. systemd_services_to_stop: ['matrix-appservice-discord.service']
  18. - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
  19. - set_fact:
  20. matrix_appservice_discord_requires_restart: true
  21. when: "matrix_appservice_discord_sqlite_database_path_local_stat_result.stat.exists|bool"
  22. when: "matrix_appservice_discord_database_engine == 'postgres'"
  23. - name: Ensure Appservice Discord image is pulled
  24. docker_image:
  25. name: "{{ matrix_appservice_discord_docker_image }}"
  26. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  27. force_source: "{{ matrix_appservice_discord_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  28. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_discord_docker_image_force_pull }}"
  29. - name: Ensure AppService Discord paths exist
  30. file:
  31. path: "{{ item }}"
  32. state: directory
  33. mode: 0750
  34. owner: "{{ matrix_user_username }}"
  35. group: "{{ matrix_user_groupname }}"
  36. with_items:
  37. - "{{ matrix_appservice_discord_base_path }}"
  38. - "{{ matrix_appservice_discord_config_path }}"
  39. - "{{ matrix_appservice_discord_data_path }}"
  40. - name: Check if an old database file already exists
  41. stat:
  42. path: "{{ matrix_appservice_discord_base_path }}/discord.db"
  43. register: matrix_appservice_discord_stat_db
  44. - name: (Data relocation) Ensure matrix-appservice-discord.service is stopped
  45. service:
  46. name: matrix-appservice-discord
  47. state: stopped
  48. enabled: false
  49. daemon_reload: true
  50. failed_when: false
  51. when: "matrix_appservice_discord_stat_db.stat.exists"
  52. - name: (Data relocation) Move AppService Discord discord.db file to ./data directory
  53. command: "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}"
  54. with_items:
  55. - discord.db
  56. - user-store.db
  57. - room-store.db
  58. when: "matrix_appservice_discord_stat_db.stat.exists"
  59. - name: Ensure AppService Discord config.yaml installed
  60. copy:
  61. content: "{{ matrix_appservice_discord_configuration|to_nice_yaml }}"
  62. dest: "{{ matrix_appservice_discord_config_path }}/config.yaml"
  63. mode: 0644
  64. owner: "{{ matrix_user_username }}"
  65. group: "{{ matrix_user_groupname }}"
  66. - name: Ensure AppService Discord registration.yaml installed
  67. copy:
  68. content: "{{ matrix_appservice_discord_registration|to_nice_yaml }}"
  69. dest: "{{ matrix_appservice_discord_config_path }}/registration.yaml"
  70. mode: 0644
  71. owner: "{{ matrix_user_username }}"
  72. group: "{{ matrix_user_groupname }}"
  73. # If `matrix_appservice_discord_client_id` hasn't changed, the same invite link would be generated.
  74. # We intentionally suppress Ansible changes.
  75. - name: Generate AppService Discord invite link
  76. shell: >-
  77. {{ matrix_host_command_docker }} run --rm --name matrix-appservice-discord-link-gen
  78. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  79. --cap-drop=ALL
  80. --mount type=bind,src={{ matrix_appservice_discord_config_path }},dst=/cfg
  81. -w /cfg
  82. {{ matrix_appservice_discord_docker_image }}
  83. /bin/sh -c "node /build/tools/addbot.js > /cfg/invite_link"
  84. changed_when: false
  85. - name: Ensure matrix-appservice-discord.service installed
  86. template:
  87. src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2"
  88. dest: "{{ matrix_systemd_path }}/matrix-appservice-discord.service"
  89. mode: 0644
  90. register: matrix_appservice_discord_systemd_service_result
  91. - name: Ensure systemd reloaded after matrix-appservice-discord.service installation
  92. service:
  93. daemon_reload: true
  94. when: "matrix_appservice_discord_systemd_service_result.changed"
  95. - name: Ensure matrix-appservice-discord.service restarted, if necessary
  96. service:
  97. name: "matrix-appservice-discord.service"
  98. state: restarted
  99. when: "matrix_appservice_discord_requires_restart|bool"