Matrix Docker Ansible eploy
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 

104 rader
4.4 KiB

  1. ---
  2. - ansible.builtin.set_fact:
  3. matrix_bot_buscarron_requires_restart: false
  4. - when: "matrix_bot_buscarron_database_engine == 'postgres'"
  5. block:
  6. - name: Check if an SQLite database already exists
  7. ansible.builtin.stat:
  8. path: "{{ matrix_bot_buscarron_sqlite_database_path_local }}"
  9. register: matrix_bot_buscarron_sqlite_database_path_local_stat_result
  10. - when: "matrix_bot_buscarron_sqlite_database_path_local_stat_result.stat.exists | bool"
  11. block:
  12. - ansible.builtin.set_fact:
  13. matrix_postgres_db_migration_request:
  14. src: "{{ matrix_bot_buscarron_sqlite_database_path_local }}"
  15. dst: "{{ matrix_bot_buscarron_database_connection_string }}"
  16. caller: "{{ role_path | basename }}"
  17. engine_variable_name: 'matrix_bot_buscarron_database_engine'
  18. engine_old: 'sqlite'
  19. systemd_services_to_stop: ['matrix-bot-buscarron.service']
  20. - ansible.builtin.import_role:
  21. name: custom/matrix-postgres
  22. tasks_from: migrate_db_to_postgres
  23. - ansible.builtin.set_fact:
  24. matrix_bot_buscarron_requires_restart: true
  25. - name: Ensure buscarron paths exist
  26. ansible.builtin.file:
  27. path: "{{ item.path }}"
  28. state: directory
  29. mode: 0750
  30. owner: "{{ matrix_user_username }}"
  31. group: "{{ matrix_user_groupname }}"
  32. with_items:
  33. - {path: "{{ matrix_bot_buscarron_config_path }}", when: true}
  34. - {path: "{{ matrix_bot_buscarron_data_path }}", when: true}
  35. - {path: "{{ matrix_bot_buscarron_data_store_path }}", when: true}
  36. - {path: "{{ matrix_bot_buscarron_docker_src_files_path }}", when: true}
  37. when: "item.when | bool"
  38. - name: Ensure buscarron environment variables file created
  39. ansible.builtin.template:
  40. src: "{{ role_path }}/templates/env.j2"
  41. dest: "{{ matrix_bot_buscarron_config_path }}/env"
  42. owner: "{{ matrix_user_username }}"
  43. group: "{{ matrix_user_groupname }}"
  44. mode: 0640
  45. - name: Ensure buscarron image is pulled
  46. community.docker.docker_image:
  47. name: "{{ matrix_bot_buscarron_docker_image }}"
  48. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  49. force_source: "{{ matrix_bot_buscarron_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  50. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_buscarron_docker_image_force_pull }}"
  51. when: "not matrix_bot_buscarron_container_image_self_build | bool"
  52. register: result
  53. retries: "{{ matrix_container_retries_count }}"
  54. delay: "{{ matrix_container_retries_delay }}"
  55. until: result is not failed
  56. - name: Ensure buscarron repository is present on self-build
  57. ansible.builtin.git:
  58. repo: "{{ matrix_bot_buscarron_docker_repo }}"
  59. version: "{{ matrix_bot_buscarron_docker_repo_version }}"
  60. dest: "{{ matrix_bot_buscarron_docker_src_files_path }}"
  61. force: "yes"
  62. become: true
  63. become_user: "{{ matrix_user_username }}"
  64. register: matrix_bot_buscarron_git_pull_results
  65. when: "matrix_bot_buscarron_container_image_self_build | bool"
  66. - name: Ensure buscarron image is built
  67. community.docker.docker_image:
  68. name: "{{ matrix_bot_buscarron_docker_image }}"
  69. source: build
  70. force_source: "{{ matrix_bot_buscarron_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  71. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mailer_git_pull_results.changed }}"
  72. build:
  73. dockerfile: Dockerfile
  74. path: "{{ matrix_bot_buscarron_docker_src_files_path }}"
  75. pull: true
  76. when: "matrix_bot_buscarron_container_image_self_build | bool"
  77. - name: Ensure matrix-bot-buscarron.service installed
  78. ansible.builtin.template:
  79. src: "{{ role_path }}/templates/systemd/matrix-bot-buscarron.service.j2"
  80. dest: "{{ matrix_systemd_path }}/matrix-bot-buscarron.service"
  81. mode: 0644
  82. register: matrix_bot_buscarron_systemd_service_result
  83. - name: Ensure systemd reloaded after matrix-bot-buscarron.service installation
  84. ansible.builtin.service:
  85. daemon_reload: true
  86. when: "matrix_bot_buscarron_systemd_service_result.changed | bool"
  87. - name: Ensure matrix-bot-buscarron.service restarted, if necessary
  88. ansible.builtin.service:
  89. name: "matrix-bot-buscarron.service"
  90. state: restarted
  91. when: "matrix_bot_buscarron_requires_restart | bool"