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

125 строки
5.7 KiB

  1. ---
  2. - ansible.builtin.set_fact:
  3. matrix_mautrix_googlechat_requires_restart: false
  4. - when: "matrix_mautrix_googlechat_database_engine == 'postgres'"
  5. block:
  6. - name: Check if an SQLite database already exists
  7. ansible.builtin.stat:
  8. path: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}"
  9. register: matrix_mautrix_googlechat_sqlite_database_path_local_stat_result
  10. - when: "matrix_mautrix_googlechat_sqlite_database_path_local_stat_result.stat.exists | bool"
  11. block:
  12. - ansible.builtin.include_role:
  13. name: galaxy/com.devture.ansible.role.postgres
  14. tasks_from: migrate_db_to_postgres
  15. vars:
  16. devture_postgres_db_migration_request:
  17. src: "{{ matrix_mautrix_googlechat_sqlite_database_path_local }}"
  18. dst: "{{ matrix_mautrix_googlechat_database_connection_string }}"
  19. caller: "{{ role_path | basename }}"
  20. engine_variable_name: 'matrix_mautrix_googlechat_database_engine'
  21. engine_old: 'sqlite'
  22. systemd_services_to_stop: ['matrix-mautrix-googlechat.service']
  23. - ansible.builtin.set_fact:
  24. matrix_mautrix_googlechat_requires_restart: true
  25. - name: Ensure Mautrix googlechat image is pulled
  26. community.docker.docker_image:
  27. name: "{{ matrix_mautrix_googlechat_docker_image }}"
  28. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  29. force_source: "{{ matrix_mautrix_googlechat_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  30. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_googlechat_docker_image_force_pull }}"
  31. when: not matrix_mautrix_googlechat_container_image_self_build
  32. register: result
  33. retries: "{{ devture_playbook_help_container_retries_count }}"
  34. delay: "{{ devture_playbook_help_container_retries_delay }}"
  35. until: result is not failed
  36. - name: Ensure Mautrix googlechat paths exist
  37. ansible.builtin.file:
  38. path: "{{ item.path }}"
  39. state: directory
  40. mode: 0750
  41. owner: "{{ matrix_user_username }}"
  42. group: "{{ matrix_user_groupname }}"
  43. with_items:
  44. - {path: "{{ matrix_mautrix_googlechat_base_path }}", when: true}
  45. - {path: "{{ matrix_mautrix_googlechat_config_path }}", when: true}
  46. - {path: "{{ matrix_mautrix_googlechat_data_path }}", when: true}
  47. - {path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}", when: "{{ matrix_mautrix_googlechat_container_image_self_build }}"}
  48. when: "item.when | bool"
  49. - name: Ensure Mautrix Hangots repository is present on self build
  50. ansible.builtin.git:
  51. repo: "{{ matrix_mautrix_googlechat_container_image_self_build_repo }}"
  52. version: "{{ matrix_mautrix_googlechat_container_image_self_build_repo_version }}"
  53. dest: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  54. force: "yes"
  55. become: true
  56. become_user: "{{ matrix_user_username }}"
  57. register: matrix_mautrix_googlechat_git_pull_results
  58. when: "matrix_mautrix_googlechat_container_image_self_build | bool"
  59. - name: Ensure Mautrix googlechat Docker image is built
  60. community.docker.docker_image:
  61. name: "{{ matrix_mautrix_googlechat_docker_image }}"
  62. source: build
  63. force_source: "{{ matrix_mautrix_googlechat_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  64. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_googlechat_git_pull_results.changed }}"
  65. build:
  66. dockerfile: Dockerfile
  67. path: "{{ matrix_mautrix_googlechat_docker_src_files_path }}"
  68. pull: true
  69. when: "matrix_mautrix_googlechat_container_image_self_build | bool"
  70. - name: Check if an old database file already exists
  71. ansible.builtin.stat:
  72. path: "{{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db"
  73. register: matrix_mautrix_googlechat_stat_database
  74. - name: (Data relocation) Ensure matrix-mautrix-googlechat.service is stopped
  75. ansible.builtin.service:
  76. name: matrix-mautrix-googlechat
  77. state: stopped
  78. enabled: false
  79. daemon_reload: true
  80. failed_when: false
  81. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  82. - name: (Data relocation) Move mautrix-googlechat database file to ./data directory
  83. ansible.builtin.command: "mv {{ matrix_mautrix_googlechat_base_path }}/mautrix-googlechat.db {{ matrix_mautrix_googlechat_data_path }}/mautrix-googlechat.db"
  84. when: "matrix_mautrix_googlechat_stat_database.stat.exists"
  85. - name: Ensure mautrix-googlechat config.yaml installed
  86. ansible.builtin.copy:
  87. content: "{{ matrix_mautrix_googlechat_configuration | to_nice_yaml(indent=2, width=999999) }}"
  88. dest: "{{ matrix_mautrix_googlechat_config_path }}/config.yaml"
  89. mode: 0644
  90. owner: "{{ matrix_user_username }}"
  91. group: "{{ matrix_user_groupname }}"
  92. - name: Ensure mautrix-googlechat registration.yaml installed
  93. ansible.builtin.copy:
  94. content: "{{ matrix_mautrix_googlechat_registration | to_nice_yaml(indent=2, width=999999) }}"
  95. dest: "{{ matrix_mautrix_googlechat_config_path }}/registration.yaml"
  96. mode: 0644
  97. owner: "{{ matrix_user_username }}"
  98. group: "{{ matrix_user_groupname }}"
  99. - name: Ensure matrix-mautrix-googlechat.service installed
  100. ansible.builtin.template:
  101. src: "{{ role_path }}/templates/systemd/matrix-mautrix-googlechat.service.j2"
  102. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-mautrix-googlechat.service"
  103. mode: 0644
  104. - name: Ensure matrix-mautrix-googlechat.service restarted, if necessary
  105. ansible.builtin.service:
  106. name: "matrix-mautrix-googlechat.service"
  107. state: restarted
  108. daemon_reload: true
  109. when: "matrix_mautrix_googlechat_requires_restart | bool"