Matrix Docker Ansible eploy
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 

134 行
6.6 KiB

  1. ---
  2. - set_fact:
  3. matrix_dimension_requires_restart: false
  4. - block:
  5. - name: Check if an SQLite database already exists
  6. stat:
  7. path: "{{ matrix_dimension_sqlite_database_path_local }}"
  8. register: matrix_dimension_sqlite_database_path_local_stat_result
  9. - block:
  10. # pgloader makes a few columns `smallint`, instead of `boolean`.
  11. # We need to fix them up.
  12. - set_fact:
  13. matrix_dimension_pgloader_additional_psql_statements_list: []
  14. - set_fact:
  15. matrix_dimension_pgloader_additional_psql_statements_list: |
  16. {{
  17. matrix_dimension_pgloader_additional_psql_statements_list
  18. +
  19. ([] if item.default == '' else ['ALTER TABLE ' + item.table + ' ALTER COLUMN "' + item.column + '" DROP default;'])
  20. +
  21. (['ALTER TABLE ' + item.table + ' ALTER COLUMN "' + item.column + '" TYPE BOOLEAN USING("' + item.column + '"::text::boolean);'])
  22. +
  23. ([] if item.default == '' else ['ALTER TABLE ' + item.table + ' ALTER COLUMN "' + item.column + '" SET default ' + item.default + ';'])
  24. }}
  25. with_items:
  26. - {'table': 'dimension_widgets', 'column': 'isEnabled', 'default': ''}
  27. - {'table': 'dimension_widgets', 'column': 'isPublic', 'default': ''}
  28. - {'table': 'dimension_webhook_bridges', 'column': 'isEnabled', 'default': ''}
  29. - {'table': 'dimension_user_sticker_packs', 'column': 'isSelected', 'default': ''}
  30. - {'table': 'dimension_scalar_tokens', 'column': 'isDimensionToken', 'default': ''}
  31. - {'table': 'dimension_users', 'column': 'isSelfBot', 'default': 'false'}
  32. - {'table': 'dimension_telegram_bridges', 'column': 'allowTgPuppets', 'default': ''}
  33. - {'table': 'dimension_telegram_bridges', 'column': 'allowMxPuppets', 'default': ''}
  34. - {'table': 'dimension_telegram_bridges', 'column': 'isEnabled', 'default': ''}
  35. - {'table': 'dimension_sticker_packs', 'column': 'isEnabled', 'default': ''}
  36. - {'table': 'dimension_sticker_packs', 'column': 'isPublic', 'default': ''}
  37. - {'table': 'dimension_slack_bridges', 'column': 'isEnabled', 'default': ''}
  38. - {'table': 'dimension_neb_integrations', 'column': 'isPublic', 'default': ''}
  39. - {'table': 'dimension_neb_integrations', 'column': 'isEnabled', 'default': ''}
  40. - {'table': 'dimension_irc_bridges', 'column': 'isEnabled', 'default': ''}
  41. - {'table': 'dimension_irc_bridge_networks', 'column': 'isEnabled', 'default': ''}
  42. - {'table': 'dimension_gitter_bridges', 'column': 'isEnabled', 'default': ''}
  43. - {'table': 'dimension_custom_simple_bots', 'column': 'isEnabled', 'default': ''}
  44. - {'table': 'dimension_custom_simple_bots', 'column': 'isPublic', 'default': ''}
  45. - {'table': 'dimension_bridges', 'column': 'isEnabled', 'default': ''}
  46. - {'table': 'dimension_bridges', 'column': 'isPublic', 'default': ''}
  47. - set_fact:
  48. matrix_postgres_db_migration_request:
  49. src: "{{ matrix_dimension_sqlite_database_path_local }}"
  50. dst: "{{ matrix_dimension_database_connection_string }}"
  51. caller: "{{ role_path|basename }}"
  52. engine_variable_name: 'matrix_dimension_database_engine'
  53. engine_old: 'sqlite'
  54. systemd_services_to_stop: ['matrix-dimension.service']
  55. pgloader_options: ['--with "quote identifiers"']
  56. additional_psql_statements_list: "{{ matrix_dimension_pgloader_additional_psql_statements_list }}"
  57. additional_psql_statements_db_name: "{{ matrix_dimension_database_name }}"
  58. - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
  59. - set_fact:
  60. matrix_dimension_requires_restart: true
  61. when: "matrix_dimension_sqlite_database_path_local_stat_result.stat.exists|bool"
  62. when: "matrix_dimension_database_engine == 'postgres'"
  63. - name: Ensure Dimension base path exists
  64. file:
  65. path: "{{ matrix_dimension_base_path }}"
  66. state: directory
  67. mode: 0770
  68. owner: "{{ matrix_user_username }}"
  69. group: "{{ matrix_dimension_user_gid }}"
  70. - name: Ensure Dimension config installed
  71. copy:
  72. content: "{{ matrix_dimension_configuration|to_nice_yaml }}"
  73. dest: "{{ matrix_dimension_base_path }}/config.yaml"
  74. mode: 0640
  75. owner: "{{ matrix_user_username }}"
  76. group: "{{ matrix_dimension_user_gid }}"
  77. - name: Ensure Dimension image is pulled
  78. docker_image:
  79. name: "{{ matrix_dimension_docker_image }}"
  80. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  81. force_source: "{{ matrix_dimension_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  82. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_dimension_docker_image_force_pull }}"
  83. when: "not matrix_dimension_container_image_self_build|bool"
  84. register: matrix_dimension_pull_results
  85. - name: Ensure dimension repository is present on self-build
  86. git:
  87. repo: "{{ matrix_dimension_container_image_self_build_repo }}"
  88. dest: "{{ matrix_dimension_docker_src_files_path }}"
  89. version: "{{ matrix_dimension_container_image_self_build_branch }}"
  90. force: "yes"
  91. when: "matrix_dimension_container_image_self_build|bool"
  92. register: matrix_dimension_git_pull_results
  93. - name: Ensure Dimension Docker image is built
  94. docker_image:
  95. name: "{{ matrix_dimension_docker_image }}"
  96. source: build
  97. force_source: "{{ matrix_dimension_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  98. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_dimension_git_pull_results.changed }}"
  99. build:
  100. dockerfile: Dockerfile
  101. path: "{{ matrix_dimension_docker_src_files_path }}"
  102. pull: yes
  103. when: "matrix_dimension_container_image_self_build|bool"
  104. - name: Ensure matrix-dimension.service installed
  105. template:
  106. src: "{{ role_path }}/templates/systemd/matrix-dimension.service.j2"
  107. dest: "{{ matrix_systemd_path }}/matrix-dimension.service"
  108. mode: 0644
  109. register: matrix_dimension_systemd_service_result
  110. - name: Ensure systemd reloaded after matrix-dimension.service installation
  111. service:
  112. daemon_reload: yes
  113. when: "matrix_dimension_systemd_service_result.changed|bool"
  114. - name: Ensure matrix-dimension.service restarted, if necessary
  115. service:
  116. name: "matrix-dimension.service"
  117. state: restarted
  118. when: "matrix_dimension_requires_restart|bool"