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.
 
 

101 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. become: true
  60. become_user: "{{ matrix_user_username }}"
  61. register: matrix_bot_honoroit_git_pull_results
  62. when: "matrix_bot_honoroit_container_image_self_build|bool"
  63. - name: Ensure honoroit image is built
  64. docker_image:
  65. name: "{{ matrix_bot_honoroit_docker_image }}"
  66. source: build
  67. force_source: "{{ matrix_bot_honoroit_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  68. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mailer_git_pull_results.changed }}"
  69. build:
  70. dockerfile: Dockerfile
  71. path: "{{ matrix_bot_honoroit_docker_src_files_path }}"
  72. pull: true
  73. when: "matrix_bot_honoroit_container_image_self_build|bool"
  74. - name: Ensure matrix-bot-honoroit.service installed
  75. template:
  76. src: "{{ role_path }}/templates/systemd/matrix-bot-honoroit.service.j2"
  77. dest: "{{ matrix_systemd_path }}/matrix-bot-honoroit.service"
  78. mode: 0644
  79. register: matrix_bot_honoroit_systemd_service_result
  80. - name: Ensure systemd reloaded after matrix-bot-honoroit.service installation
  81. service:
  82. daemon_reload: true
  83. when: "matrix_bot_honoroit_systemd_service_result.changed|bool"
  84. - name: Ensure matrix-bot-honoroit.service restarted, if necessary
  85. service:
  86. name: "matrix-bot-honoroit.service"
  87. state: restarted
  88. when: "matrix_bot_honoroit_requires_restart|bool"