Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

101 regels
4.2 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. - name: Ensure matrix-registration repository is present when self-building
  49. git:
  50. repo: "{{ matrix_registration_container_image_self_build_repo }}"
  51. dest: "{{ matrix_registration_docker_src_files_path }}"
  52. version: "{{ matrix_registration_container_image_self_build_branch }}"
  53. force: "yes"
  54. register: matrix_registration_git_pull_results
  55. when: "matrix_registration_container_image_self_build|bool"
  56. - name: Ensure matrix-registration Docker image is built
  57. docker_image:
  58. name: "{{ matrix_registration_docker_image }}"
  59. source: build
  60. force_source: "{{ matrix_registration_git_pull_results.changed }}"
  61. build:
  62. dockerfile: Dockerfile
  63. path: "{{ matrix_registration_docker_src_files_path }}"
  64. pull: yes
  65. when: "matrix_registration_container_image_self_build|bool"
  66. - name: Ensure matrix-registration config installed
  67. copy:
  68. content: "{{ matrix_registration_configuration|to_nice_yaml }}"
  69. dest: "{{ matrix_registration_config_path }}/config.yaml"
  70. mode: 0644
  71. owner: "{{ matrix_user_username }}"
  72. group: "{{ matrix_user_groupname }}"
  73. - name: Ensure matrix-registration.service installed
  74. template:
  75. src: "{{ role_path }}/templates/systemd/matrix-registration.service.j2"
  76. dest: "{{ matrix_systemd_path }}/matrix-registration.service"
  77. mode: 0644
  78. register: matrix_registration_systemd_service_result
  79. - name: Ensure systemd reloaded after matrix-registration.service installation
  80. service:
  81. daemon_reload: yes
  82. when: "matrix_registration_systemd_service_result.changed|bool"
  83. - name: Ensure matrix-registration.service restarted, if necessary
  84. service:
  85. name: "matrix-registration.service"
  86. state: restarted
  87. when: "matrix_registration_requires_restart|bool"