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

120 строки
4.8 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. register: result
  30. retries: "{{ matrix_container_retries_count }}"
  31. delay: "{{ matrix_container_retries_delay }}"
  32. until: result is not failed
  33. - name: Ensure AppService Discord paths exist
  34. file:
  35. path: "{{ item }}"
  36. state: directory
  37. mode: 0750
  38. owner: "{{ matrix_user_username }}"
  39. group: "{{ matrix_user_groupname }}"
  40. with_items:
  41. - "{{ matrix_appservice_discord_base_path }}"
  42. - "{{ matrix_appservice_discord_config_path }}"
  43. - "{{ matrix_appservice_discord_data_path }}"
  44. - name: Check if an old database file already exists
  45. stat:
  46. path: "{{ matrix_appservice_discord_base_path }}/discord.db"
  47. register: matrix_appservice_discord_stat_db
  48. - name: (Data relocation) Ensure matrix-appservice-discord.service is stopped
  49. service:
  50. name: matrix-appservice-discord
  51. state: stopped
  52. enabled: false
  53. daemon_reload: true
  54. failed_when: false
  55. when: "matrix_appservice_discord_stat_db.stat.exists"
  56. - name: (Data relocation) Move AppService Discord discord.db file to ./data directory
  57. command: "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}"
  58. with_items:
  59. - discord.db
  60. - user-store.db
  61. - room-store.db
  62. when: "matrix_appservice_discord_stat_db.stat.exists"
  63. - name: Ensure AppService Discord config.yaml installed
  64. copy:
  65. content: "{{ matrix_appservice_discord_configuration|to_nice_yaml(indent=2, width=999999) }}"
  66. dest: "{{ matrix_appservice_discord_config_path }}/config.yaml"
  67. mode: 0644
  68. owner: "{{ matrix_user_username }}"
  69. group: "{{ matrix_user_groupname }}"
  70. - name: Ensure AppService Discord registration.yaml installed
  71. copy:
  72. content: "{{ matrix_appservice_discord_registration|to_nice_yaml(indent=2, width=999999) }}"
  73. dest: "{{ matrix_appservice_discord_config_path }}/registration.yaml"
  74. mode: 0644
  75. owner: "{{ matrix_user_username }}"
  76. group: "{{ matrix_user_groupname }}"
  77. # If `matrix_appservice_discord_client_id` hasn't changed, the same invite link would be generated.
  78. # We intentionally suppress Ansible changes.
  79. - name: Generate AppService Discord invite link
  80. shell: >-
  81. {{ matrix_host_command_docker }} run --rm --name matrix-appservice-discord-link-gen
  82. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  83. --cap-drop=ALL
  84. --mount type=bind,src={{ matrix_appservice_discord_config_path }},dst=/cfg
  85. -w /cfg
  86. {{ matrix_appservice_discord_docker_image }}
  87. /bin/sh -c "node /build/tools/addbot.js > /cfg/invite_link"
  88. changed_when: false
  89. - name: Ensure matrix-appservice-discord.service installed
  90. template:
  91. src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2"
  92. dest: "{{ matrix_systemd_path }}/matrix-appservice-discord.service"
  93. mode: 0644
  94. register: matrix_appservice_discord_systemd_service_result
  95. - name: Ensure systemd reloaded after matrix-appservice-discord.service installation
  96. service:
  97. daemon_reload: true
  98. when: "matrix_appservice_discord_systemd_service_result.changed"
  99. - name: Ensure matrix-appservice-discord.service restarted, if necessary
  100. service:
  101. name: "matrix-appservice-discord.service"
  102. state: restarted
  103. when: "matrix_appservice_discord_requires_restart|bool"