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.

99 lines
4.0 KiB

  1. ---
  2. - set_fact:
  3. matrix_bot_honoroit_requires_restart: false
  4. - block:
  5. - name: Check if an SQLite database already exists
  6. stat:
  7. path: "{{ matrix_bot_honoroit_sqlite_database_path_local }}"
  8. register: matrix_bot_honoroit_sqlite_database_path_local_stat_result
  9. - block:
  10. - set_fact:
  11. matrix_postgres_db_migration_request:
  12. src: "{{ matrix_bot_honoroit_sqlite_database_path_local }}"
  13. dst: "{{ matrix_bot_honoroit_database_connection_string }}"
  14. caller: "{{ role_path|basename }}"
  15. engine_variable_name: 'matrix_bot_honoroit_database_engine'
  16. engine_old: 'sqlite'
  17. systemd_services_to_stop: ['matrix-bot-honoroit.service']
  18. - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml"
  19. - set_fact:
  20. matrix_bot_honoroit_requires_restart: true
  21. when: "matrix_bot_honoroit_sqlite_database_path_local_stat_result.stat.exists|bool"
  22. when: "matrix_bot_honoroit_database_engine == 'postgres'"
  23. - name: Ensure honoroit paths exist
  24. file:
  25. path: "{{ item.path }}"
  26. state: directory
  27. mode: 0750
  28. owner: "{{ matrix_user_username }}"
  29. group: "{{ matrix_user_groupname }}"
  30. with_items:
  31. - {path: "{{ matrix_bot_honoroit_config_path }}", when: true}
  32. - {path: "{{ matrix_bot_honoroit_data_path }}", when: true}
  33. - {path: "{{ matrix_bot_honoroit_data_store_path }}", when: true}
  34. - {path: "{{ matrix_bot_honoroit_docker_src_files_path }}", when: true}
  35. when: "item.when|bool"
  36. - name: Ensure honoroit environment variables file created
  37. template:
  38. src: "{{ role_path }}/templates/env.j2"
  39. dest: "{{ matrix_bot_honoroit_config_path }}/env"
  40. owner: "{{ matrix_user_username }}"
  41. group: "{{ matrix_user_groupname }}"
  42. mode: 0640
  43. - name: Ensure honoroit image is pulled
  44. docker_image:
  45. name: "{{ matrix_bot_honoroit_docker_image }}"
  46. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  47. force_source: "{{ matrix_bot_honoroit_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  48. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_honoroit_docker_image_force_pull }}"
  49. when: "not matrix_bot_honoroit_container_image_self_build|bool"
  50. register: result
  51. retries: "{{ matrix_container_retries_count }}"
  52. delay: "{{ matrix_container_retries_delay }}"
  53. until: result is not failed
  54. - name: Ensure honoroit repository is present on self-build
  55. git:
  56. repo: "{{ matrix_bot_honoroit_docker_repo }}"
  57. dest: "{{ matrix_bot_honoroit_docker_src_files_path }}"
  58. force: "yes"
  59. register: matrix_bot_honoroit_git_pull_results
  60. when: "matrix_bot_honoroit_container_image_self_build|bool"
  61. - name: Ensure honoroit image is built
  62. docker_image:
  63. name: "{{ matrix_bot_honoroit_docker_image }}"
  64. source: build
  65. force_source: "{{ matrix_bot_honoroit_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  66. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mailer_git_pull_results.changed }}"
  67. build:
  68. dockerfile: Dockerfile
  69. path: "{{ matrix_bot_honoroit_docker_src_files_path }}"
  70. pull: true
  71. when: "matrix_bot_honoroit_container_image_self_build|bool"
  72. - name: Ensure matrix-bot-honoroit.service installed
  73. template:
  74. src: "{{ role_path }}/templates/systemd/matrix-bot-honoroit.service.j2"
  75. dest: "{{ matrix_systemd_path }}/matrix-bot-honoroit.service"
  76. mode: 0644
  77. register: matrix_bot_honoroit_systemd_service_result
  78. - name: Ensure systemd reloaded after matrix-bot-honoroit.service installation
  79. service:
  80. daemon_reload: true
  81. when: "matrix_bot_honoroit_systemd_service_result.changed|bool"
  82. - name: Ensure matrix-bot-honoroit.service restarted, if necessary
  83. service:
  84. name: "matrix-bot-honoroit.service"
  85. state: restarted
  86. when: "matrix_bot_honoroit_requires_restart|bool"