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

150 строки
7.5 KiB

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