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.
 
 

128 lines
5.2 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.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_bot_buscarron_sqlite_database_path_local }}"
  18. dst: "{{ matrix_bot_buscarron_database_connection_string }}"
  19. caller: "{{ role_path | basename }}"
  20. engine_variable_name: 'matrix_bot_buscarron_database_engine'
  21. engine_old: 'sqlite'
  22. systemd_services_to_stop: ['matrix-bot-buscarron.service']
  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: Determine basicauth filename
  39. set_fact:
  40. matrix_bot_buscarron_basicauth_file_tmp: "{{ matrix_bot_buscarron_basicauth_file }}_{{ inventory_hostname }}"
  41. when: matrix_bot_buscarron_basicauth_enabled | bool
  42. - name: Generate basic auth file
  43. community.general.htpasswd:
  44. path: "{{ matrix_bot_buscarron_basicauth_file }}"
  45. name: "{{ matrix_bot_buscarron_basicauth_user }}"
  46. password: "{{ matrix_bot_buscarron_basicauth_password }}"
  47. become: false
  48. delegate_to: 127.0.0.1
  49. when: matrix_bot_buscarron_basicauth_enabled | bool
  50. - name: Ensure buscarron support files installed
  51. ansible.builtin.template:
  52. src: "{{ role_path }}/templates/{{ item }}.j2"
  53. dest: "{{ matrix_bot_buscarron_config_path }}/{{ item }}"
  54. owner: "{{ matrix_user_username }}"
  55. group: "{{ matrix_user_groupname }}"
  56. mode: 0640
  57. with_items:
  58. - env
  59. - labels
  60. - name: Ensure temporary basic auth file is removed
  61. ansible.builtin.file:
  62. path: "{{ matrix_bot_buscarron_basicauth_file }}"
  63. state: absent
  64. become: false
  65. delegate_to: 127.0.0.1
  66. when: matrix_bot_buscarron_basicauth_enabled | bool
  67. - name: Ensure buscarron image is pulled
  68. community.docker.docker_image:
  69. name: "{{ matrix_bot_buscarron_docker_image }}"
  70. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  71. force_source: "{{ matrix_bot_buscarron_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  72. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_buscarron_docker_image_force_pull }}"
  73. when: "not matrix_bot_buscarron_container_image_self_build | bool"
  74. register: result
  75. retries: "{{ devture_playbook_help_container_retries_count }}"
  76. delay: "{{ devture_playbook_help_container_retries_delay }}"
  77. until: result is not failed
  78. - name: Ensure buscarron repository is present on self-build
  79. ansible.builtin.git:
  80. repo: "{{ matrix_bot_buscarron_docker_repo }}"
  81. version: "{{ matrix_bot_buscarron_docker_repo_version }}"
  82. dest: "{{ matrix_bot_buscarron_docker_src_files_path }}"
  83. force: "yes"
  84. become: true
  85. become_user: "{{ matrix_user_username }}"
  86. register: matrix_bot_buscarron_git_pull_results
  87. when: "matrix_bot_buscarron_container_image_self_build | bool"
  88. - name: Ensure buscarron image is built
  89. community.docker.docker_image:
  90. name: "{{ matrix_bot_buscarron_docker_image }}"
  91. source: build
  92. force_source: "{{ matrix_bot_buscarron_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  93. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mailer_git_pull_results.changed }}"
  94. build:
  95. dockerfile: Dockerfile
  96. path: "{{ matrix_bot_buscarron_docker_src_files_path }}"
  97. pull: true
  98. when: "matrix_bot_buscarron_container_image_self_build | bool"
  99. - name: Ensure matrix-bot-buscarron.service installed
  100. ansible.builtin.template:
  101. src: "{{ role_path }}/templates/systemd/matrix-bot-buscarron.service.j2"
  102. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-buscarron.service"
  103. mode: 0644
  104. - name: Ensure buscarron container network is created
  105. community.general.docker_network:
  106. name: "{{ matrix_bot_buscarron_container_network }}"
  107. driver: bridge
  108. - name: Ensure matrix-bot-buscarron.service restarted, if necessary
  109. ansible.builtin.service:
  110. name: "matrix-bot-buscarron.service"
  111. state: restarted
  112. daemon_reload: true
  113. when: "matrix_bot_buscarron_requires_restart | bool"