Matrix Docker Ansible eploy
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

115 líneas
4.5 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. daemon_reload: yes
  49. failed_when: false
  50. when: "matrix_appservice_discord_stat_db.stat.exists"
  51. - name: (Data relocation) Move AppService Discord discord.db file to ./data directory
  52. command: "mv {{ matrix_appservice_discord_base_path }}/{{ item }} {{ matrix_appservice_discord_data_path }}/{{ item }}"
  53. with_items:
  54. - discord.db
  55. - user-store.db
  56. - room-store.db
  57. when: "matrix_appservice_discord_stat_db.stat.exists"
  58. - name: Ensure AppService Discord config.yaml installed
  59. copy:
  60. content: "{{ matrix_appservice_discord_configuration|to_nice_yaml }}"
  61. dest: "{{ matrix_appservice_discord_config_path }}/config.yaml"
  62. mode: 0644
  63. owner: "{{ matrix_user_username }}"
  64. group: "{{ matrix_user_groupname }}"
  65. - name: Ensure AppService Discord registration.yaml installed
  66. copy:
  67. content: "{{ matrix_appservice_discord_registration|to_nice_yaml }}"
  68. dest: "{{ matrix_appservice_discord_config_path }}/registration.yaml"
  69. mode: 0644
  70. owner: "{{ matrix_user_username }}"
  71. group: "{{ matrix_user_groupname }}"
  72. # If `matrix_appservice_discord_client_id` hasn't changed, the same invite link would be generated.
  73. # We intentionally suppress Ansible changes.
  74. - name: Generate AppService Discord invite link
  75. shell: >-
  76. {{ matrix_host_command_docker }} run --rm --name matrix-appservice-discord-link-gen
  77. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  78. --cap-drop=ALL
  79. --mount type=bind,src={{ matrix_appservice_discord_config_path }},dst=/cfg
  80. -w /cfg
  81. {{ matrix_appservice_discord_docker_image }}
  82. /bin/sh -c "node /build/tools/addbot.js > /cfg/invite_link"
  83. changed_when: false
  84. - name: Ensure matrix-appservice-discord.service installed
  85. template:
  86. src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2"
  87. dest: "{{ matrix_systemd_path }}/matrix-appservice-discord.service"
  88. mode: 0644
  89. register: matrix_appservice_discord_systemd_service_result
  90. - name: Ensure systemd reloaded after matrix-appservice-discord.service installation
  91. service:
  92. daemon_reload: yes
  93. when: "matrix_appservice_discord_systemd_service_result.changed"
  94. - name: Ensure matrix-appservice-discord.service restarted, if necessary
  95. service:
  96. name: "matrix-appservice-discord.service"
  97. state: restarted
  98. when: "matrix_appservice_discord_requires_restart|bool"