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.
 
 

123 lignes
5.3 KiB

  1. ---
  2. # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist.
  3. # We don't want to fail in such cases.
  4. - name: Fail if matrix-synapse role already executed
  5. ansible.builtin.fail:
  6. msg: >-
  7. The matrix-bridge-mautrix-discord role needs to execute before the matrix-synapse role.
  8. when: "matrix_synapse_role_executed | default(False)"
  9. - ansible.builtin.set_fact:
  10. matrix_mautrix_discord_requires_restart: false
  11. - block:
  12. - name: Check if an SQLite database already exists
  13. ansible.builtin.stat:
  14. path: "{{ matrix_mautrix_discord_sqlite_database_path_local }}"
  15. register: matrix_mautrix_discord_sqlite_database_path_local_stat_result
  16. - block:
  17. - ansible.builtin.set_fact:
  18. matrix_postgres_db_migration_request:
  19. src: "{{ matrix_mautrix_discord_sqlite_database_path_local }}"
  20. dst: "{{ matrix_mautrix_discord_database_connection_string }}"
  21. caller: "{{ role_path | basename }}"
  22. engine_variable_name: 'matrix_mautrix_discord_database_engine'
  23. engine_old: 'sqlite'
  24. systemd_services_to_stop: ['matrix-mautrix-discord.service']
  25. pgloader_options: ['--with "quote identifiers"']
  26. - ansible.builtin.import_role:
  27. name: matrix-postgres
  28. tasks_from: migrate_db_to_postgres
  29. - ansible.builtin.set_fact:
  30. matrix_mautrix_discord_requires_restart: true
  31. when: "matrix_mautrix_discord_sqlite_database_path_local_stat_result.stat.exists | bool"
  32. when: "matrix_mautrix_discord_database_engine == 'postgres'"
  33. - name: Ensure Mautrix Discord paths exists
  34. ansible.builtin.file:
  35. path: "{{ item.path }}"
  36. state: directory
  37. mode: 0750
  38. owner: "{{ matrix_user_username }}"
  39. group: "{{ matrix_user_groupname }}"
  40. with_items:
  41. - {path: "{{ matrix_mautrix_discord_base_path }}", when: true}
  42. - {path: "{{ matrix_mautrix_discord_config_path }}", when: true}
  43. - {path: "{{ matrix_mautrix_discord_data_path }}", when: true}
  44. - {path: "{{ matrix_mautrix_discord_docker_src_files_path }}", when: "{{ matrix_mautrix_discord_container_image_self_build }}"}
  45. when: item.when | bool
  46. - name: Ensure Mautrix Discord image is pulled
  47. docker_image:
  48. name: "{{ matrix_mautrix_discord_docker_image }}"
  49. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  50. force_source: "{{ matrix_mautrix_discord_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  51. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_discord_docker_image_force_pull }}"
  52. when: not matrix_mautrix_discord_container_image_self_build
  53. register: result
  54. retries: "{{ matrix_container_retries_count }}"
  55. delay: "{{ matrix_container_retries_delay }}"
  56. until: result is not failed
  57. - name: Ensure Mautrix discord repository is present on self-build
  58. ansible.builtin.git:
  59. repo: "{{ matrix_mautrix_discord_container_image_self_build_repo }}"
  60. dest: "{{ matrix_mautrix_discord_docker_src_files_path }}"
  61. version: "{{ matrix_mautrix_discord_container_image_self_build_branch }}"
  62. force: "yes"
  63. become: true
  64. become_user: "{{ matrix_user_username }}"
  65. register: matrix_mautrix_discord_git_pull_results
  66. when: "matrix_mautrix_discord_container_image_self_build | bool"
  67. - name: Ensure Mautrix discord Docker image is built
  68. docker_image:
  69. name: "{{ matrix_mautrix_discord_docker_image }}"
  70. source: build
  71. force_source: "{{ matrix_mautrix_discord_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  72. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_discord_git_pull_results.changed }}"
  73. build:
  74. dockerfile: Dockerfile
  75. path: "{{ matrix_mautrix_discord_docker_src_files_path }}"
  76. pull: true
  77. when: "matrix_mautrix_discord_container_image_self_build | bool"
  78. - name: Ensure mautrix-discord config.yaml installed
  79. ansible.builtin.copy:
  80. content: "{{ matrix_mautrix_discord_configuration | to_nice_yaml(indent=2, width=999999) }}"
  81. dest: "{{ matrix_mautrix_discord_config_path }}/config.yaml"
  82. mode: 0644
  83. owner: "{{ matrix_user_username }}"
  84. group: "{{ matrix_user_groupname }}"
  85. - name: Ensure mautrix-discord registration.yaml installed
  86. ansible.builtin.copy:
  87. content: "{{ matrix_mautrix_discord_registration | to_nice_yaml(indent=2, width=999999) }}"
  88. dest: "{{ matrix_mautrix_discord_config_path }}/registration.yaml"
  89. mode: 0644
  90. owner: "{{ matrix_user_username }}"
  91. group: "{{ matrix_user_groupname }}"
  92. - name: Ensure matrix-mautrix-discord.service installed
  93. ansible.builtin.template:
  94. src: "{{ role_path }}/templates/systemd/matrix-mautrix-discord.service.j2"
  95. dest: "{{ matrix_systemd_path }}/matrix-mautrix-discord.service"
  96. mode: 0644
  97. register: matrix_mautrix_discord_systemd_service_result
  98. - name: Ensure systemd reloaded after matrix-mautrix-discord.service installation
  99. ansible.builtin.service:
  100. daemon_reload: true
  101. when: "matrix_mautrix_discord_systemd_service_result.changed"
  102. - name: Ensure matrix-mautrix-discord.service restarted, if necessary
  103. ansible.builtin.service:
  104. name: "matrix-mautrix-discord.service"
  105. state: restarted
  106. when: "matrix_mautrix_discord_requires_restart | bool"