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.
 
 

102 lines
4.3 KiB

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