Matrix Docker Ansible eploy
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

106 linhas
4.6 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. register: matrix_registration_git_pull_results
  59. when: "matrix_registration_container_image_self_build|bool"
  60. - name: Ensure matrix-registration Docker image is built
  61. docker_image:
  62. name: "{{ matrix_registration_docker_image }}"
  63. source: build
  64. force_source: "{{ matrix_registration_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  65. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_registration_git_pull_results.changed }}"
  66. build:
  67. dockerfile: Dockerfile
  68. path: "{{ matrix_registration_docker_src_files_path }}"
  69. pull: true
  70. when: "matrix_registration_container_image_self_build|bool"
  71. - name: Ensure matrix-registration config installed
  72. copy:
  73. content: "{{ matrix_registration_configuration|to_nice_yaml(indent=2, width=999999) }}"
  74. dest: "{{ matrix_registration_config_path }}/config.yaml"
  75. mode: 0644
  76. owner: "{{ matrix_user_username }}"
  77. group: "{{ matrix_user_groupname }}"
  78. - name: Ensure matrix-registration.service installed
  79. template:
  80. src: "{{ role_path }}/templates/systemd/matrix-registration.service.j2"
  81. dest: "{{ matrix_systemd_path }}/matrix-registration.service"
  82. mode: 0644
  83. register: matrix_registration_systemd_service_result
  84. - name: Ensure systemd reloaded after matrix-registration.service installation
  85. service:
  86. daemon_reload: true
  87. when: "matrix_registration_systemd_service_result.changed|bool"
  88. - name: Ensure matrix-registration.service restarted, if necessary
  89. service:
  90. name: "matrix-registration.service"
  91. state: restarted
  92. when: "matrix_registration_requires_restart|bool"