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

108 строки
4.7 KiB

  1. ---
  2. - set_fact:
  3. matrix_registration_requires_restart: false
  4. - block:
  5. - name: Check if an SQLite database already exists
  6. stat:
  7. path: "{{ matrix_registration_sqlite_database_path_local }}"
  8. register: matrix_registration_sqlite_database_path_local_stat_result
  9. - block:
  10. - set_fact:
  11. matrix_postgres_db_migration_request:
  12. src: "{{ matrix_registration_sqlite_database_path_local }}"
  13. dst: "{{ matrix_registration_database_connection_string }}"
  14. caller: "{{ role_path|basename }}"
  15. engine_variable_name: 'matrix_registration_database_engine'
  16. engine_old: 'sqlite'
  17. systemd_services_to_stop: ['matrix-registration.service']
  18. # pgloader makes `ex_date` of type `TIMESTAMP WITH TIMEZONE`,
  19. # which makes matrix-registration choke on it later on when comparing dates.
  20. additional_psql_statements_list:
  21. - ALTER TABLE tokens ALTER COLUMN ex_date TYPE TIMESTAMP WITHOUT TIME ZONE;
  22. additional_psql_statements_db_name: "{{ matrix_registration_database_name }}"
  23. - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
  24. - set_fact:
  25. matrix_registration_requires_restart: true
  26. when: "matrix_registration_sqlite_database_path_local_stat_result.stat.exists|bool"
  27. when: "matrix_registration_database_engine == 'postgres'"
  28. - name: Ensure matrix-registration paths exist
  29. file:
  30. path: "{{ item.path }}"
  31. state: directory
  32. mode: 0750
  33. owner: "{{ matrix_user_username }}"
  34. group: "{{ matrix_user_groupname }}"
  35. with_items:
  36. - {path: "{{ matrix_registration_base_path }}", when: true}
  37. - {path: "{{ matrix_registration_config_path }}", when: true}
  38. - {path: "{{ matrix_registration_data_path }}", when: true}
  39. - {path: "{{ matrix_registration_docker_src_files_path }}", when: "{{ matrix_registration_container_image_self_build }}"}
  40. when: "item.when|bool"
  41. - name: Ensure matrix-registration image is pulled
  42. docker_image:
  43. name: "{{ matrix_registration_docker_image }}"
  44. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  45. force_source: "{{ matrix_registration_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  46. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_registration_docker_image_force_pull }}"
  47. when: "not matrix_registration_container_image_self_build|bool"
  48. register: result
  49. retries: "{{ matrix_container_retries_count }}"
  50. delay: "{{ matrix_container_retries_delay }}"
  51. until: result is not failed
  52. - name: Ensure matrix-registration repository is present when self-building
  53. git:
  54. repo: "{{ matrix_registration_container_image_self_build_repo }}"
  55. dest: "{{ matrix_registration_docker_src_files_path }}"
  56. version: "{{ matrix_registration_container_image_self_build_branch }}"
  57. force: "yes"
  58. become: true
  59. become_user: "{{ matrix_user_username }}"
  60. register: matrix_registration_git_pull_results
  61. when: "matrix_registration_container_image_self_build|bool"
  62. - name: Ensure matrix-registration Docker image is built
  63. docker_image:
  64. name: "{{ matrix_registration_docker_image }}"
  65. source: build
  66. force_source: "{{ matrix_registration_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  67. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_registration_git_pull_results.changed }}"
  68. build:
  69. dockerfile: Dockerfile
  70. path: "{{ matrix_registration_docker_src_files_path }}"
  71. pull: true
  72. when: "matrix_registration_container_image_self_build|bool"
  73. - name: Ensure matrix-registration config installed
  74. copy:
  75. content: "{{ matrix_registration_configuration|to_nice_yaml(indent=2, width=999999) }}"
  76. dest: "{{ matrix_registration_config_path }}/config.yaml"
  77. mode: 0644
  78. owner: "{{ matrix_user_username }}"
  79. group: "{{ matrix_user_groupname }}"
  80. - name: Ensure matrix-registration.service installed
  81. template:
  82. src: "{{ role_path }}/templates/systemd/matrix-registration.service.j2"
  83. dest: "{{ matrix_systemd_path }}/matrix-registration.service"
  84. mode: 0644
  85. register: matrix_registration_systemd_service_result
  86. - name: Ensure systemd reloaded after matrix-registration.service installation
  87. service:
  88. daemon_reload: true
  89. when: "matrix_registration_systemd_service_result.changed|bool"
  90. - name: Ensure matrix-registration.service restarted, if necessary
  91. service:
  92. name: "matrix-registration.service"
  93. state: restarted
  94. when: "matrix_registration_requires_restart|bool"