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

130 строки
5.6 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. fail:
  6. msg: >-
  7. The matrix-bridge-mautrix-facebook role needs to execute before the matrix-synapse role.
  8. when: "matrix_synapse_role_executed|default(False)"
  9. - set_fact:
  10. matrix_mautrix_facebook_requires_restart: false
  11. - block:
  12. - name: Check if an SQLite database already exists
  13. stat:
  14. path: "{{ matrix_mautrix_facebook_sqlite_database_path_local }}"
  15. register: matrix_mautrix_facebook_sqlite_database_path_local_stat_result
  16. - block:
  17. - set_fact:
  18. matrix_postgres_db_migration_request:
  19. src: "{{ matrix_mautrix_facebook_sqlite_database_path_local }}"
  20. dst: "{{ matrix_mautrix_facebook_database_connection_string }}"
  21. caller: "{{ role_path|basename }}"
  22. engine_variable_name: 'matrix_mautrix_facebook_database_engine'
  23. engine_old: 'sqlite'
  24. systemd_services_to_stop: ['matrix-mautrix-facebook.service']
  25. - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
  26. - set_fact:
  27. matrix_mautrix_facebook_requires_restart: true
  28. when: "matrix_mautrix_facebook_sqlite_database_path_local_stat_result.stat.exists|bool"
  29. when: "matrix_mautrix_facebook_database_engine == 'postgres'"
  30. - name: Ensure Mautrix Facebook image is pulled
  31. docker_image:
  32. name: "{{ matrix_mautrix_facebook_docker_image }}"
  33. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  34. force_source: "{{ matrix_mautrix_facebook_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  35. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_facebook_docker_image_force_pull }}"
  36. when: matrix_mautrix_facebook_enabled|bool and not matrix_mautrix_facebook_container_image_self_build
  37. - name: Ensure Mautrix Facebook paths exist
  38. file:
  39. path: "{{ item.path }}"
  40. state: directory
  41. mode: 0750
  42. owner: "{{ matrix_user_username }}"
  43. group: "{{ matrix_user_groupname }}"
  44. with_items:
  45. - { path: "{{ matrix_mautrix_facebook_base_path }}", when: true }
  46. - { path: "{{ matrix_mautrix_facebook_config_path }}", when: true }
  47. - { path: "{{ matrix_mautrix_facebook_data_path }}", when: true }
  48. - { path: "{{ matrix_mautrix_facebook_docker_src_files_path }}", when: "{{ matrix_mautrix_facebook_container_image_self_build }}" }
  49. when: item.when|bool
  50. - name: Ensure Mautrix Facebook repository is present on self-build
  51. git:
  52. repo: "{{ matrix_mautrix_facebook_container_image_self_build_repo }}"
  53. dest: "{{ matrix_mautrix_facebook_docker_src_files_path }}"
  54. # version: "{{ matrix_coturn_docker_image.split(':')[1] }}"
  55. force: "yes"
  56. register: matrix_mautrix_facebook_git_pull_results
  57. when: "matrix_mautrix_facebook_enabled|bool and matrix_mautrix_facebook_container_image_self_build"
  58. - name: Ensure Mautrix Facebook Docker image is built
  59. docker_image:
  60. name: "{{ matrix_mautrix_facebook_docker_image }}"
  61. source: build
  62. force_source: "{{ matrix_mautrix_facebook_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  63. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_facebook_git_pull_results.changed }}"
  64. build:
  65. dockerfile: Dockerfile
  66. path: "{{ matrix_mautrix_facebook_docker_src_files_path }}"
  67. pull: yes
  68. when: "matrix_mautrix_facebook_enabled|bool and matrix_mautrix_facebook_container_image_self_build|bool"
  69. - name: Check if an old database file already exists
  70. stat:
  71. path: "{{ matrix_mautrix_facebook_base_path }}/mautrix-facebook.db"
  72. register: matrix_mautrix_facebook_stat_database
  73. - name: (Data relocation) Ensure matrix-mautrix-facebook.service is stopped
  74. service:
  75. name: matrix-mautrix-facebook
  76. state: stopped
  77. daemon_reload: yes
  78. failed_when: false
  79. when: "matrix_mautrix_facebook_stat_database.stat.exists"
  80. - name: (Data relocation) Move mautrix-facebook database file to ./data directory
  81. command: "mv {{ matrix_mautrix_facebook_base_path }}/mautrix-facebook.db {{ matrix_mautrix_facebook_data_path }}/mautrix-facebook.db"
  82. when: "matrix_mautrix_facebook_stat_database.stat.exists"
  83. - name: Ensure mautrix-facebook config.yaml installed
  84. copy:
  85. content: "{{ matrix_mautrix_facebook_configuration|to_nice_yaml }}"
  86. dest: "{{ matrix_mautrix_facebook_config_path }}/config.yaml"
  87. mode: 0644
  88. owner: "{{ matrix_user_username }}"
  89. group: "{{ matrix_user_groupname }}"
  90. - name: Ensure mautrix-facebook registration.yaml installed
  91. copy:
  92. content: "{{ matrix_mautrix_facebook_registration|to_nice_yaml }}"
  93. dest: "{{ matrix_mautrix_facebook_config_path }}/registration.yaml"
  94. mode: 0644
  95. owner: "{{ matrix_user_username }}"
  96. group: "{{ matrix_user_groupname }}"
  97. - name: Ensure matrix-mautrix-facebook.service installed
  98. template:
  99. src: "{{ role_path }}/templates/systemd/matrix-mautrix-facebook.service.j2"
  100. dest: "{{ matrix_systemd_path }}/matrix-mautrix-facebook.service"
  101. mode: 0644
  102. register: matrix_mautrix_facebook_systemd_service_result
  103. - name: Ensure systemd reloaded after matrix-mautrix-facebook.service installation
  104. service:
  105. daemon_reload: yes
  106. when: "matrix_mautrix_facebook_systemd_service_result.changed"
  107. - name: Ensure matrix-mautrix-facebook.service restarted, if necessary
  108. service:
  109. name: "matrix-mautrix-facebook.service"
  110. state: restarted
  111. when: "matrix_mautrix_facebook_requires_restart|bool"