Matrix Docker Ansible eploy
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

130 lines
5.2 KiB

  1. ---
  2. - ansible.builtin.set_fact:
  3. matrix_bot_honoroit_requires_restart: false
  4. - when: "matrix_bot_honoroit_database_engine == 'postgres'"
  5. block:
  6. - name: Check if an SQLite database already exists
  7. ansible.builtin.stat:
  8. path: "{{ matrix_bot_honoroit_sqlite_database_path_local }}"
  9. register: matrix_bot_honoroit_sqlite_database_path_local_stat_result
  10. - when: "matrix_bot_honoroit_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_honoroit_sqlite_database_path_local }}"
  18. dst: "{{ matrix_bot_honoroit_database_connection_string }}"
  19. caller: "{{ role_path | basename }}"
  20. engine_variable_name: 'matrix_bot_honoroit_database_engine'
  21. engine_old: 'sqlite'
  22. systemd_services_to_stop: ['matrix-bot-honoroit.service']
  23. - ansible.builtin.set_fact:
  24. matrix_bot_honoroit_requires_restart: true
  25. - name: Ensure honoroit 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_honoroit_config_path }}", when: true}
  34. - {path: "{{ matrix_bot_honoroit_data_path }}", when: true}
  35. - {path: "{{ matrix_bot_honoroit_data_store_path }}", when: true}
  36. - {path: "{{ matrix_bot_honoroit_docker_src_files_path }}", when: true}
  37. when: "item.when | bool"
  38. - name: Determine basicauth filename
  39. ansible.builtin.set_fact:
  40. matrix_bot_honoroit_basicauth_file_tmp: "{{ matrix_bot_honoroit_basicauth_file }}_{{ inventory_hostname }}"
  41. when: matrix_bot_honoroit_basicauth_enabled | bool
  42. - name: Generate basic auth file
  43. community.general.htpasswd:
  44. path: "{{ matrix_bot_honoroit_basicauth_file }}"
  45. name: "{{ matrix_bot_honoroit_basicauth_user }}"
  46. password: "{{ matrix_bot_honoroit_basicauth_password }}"
  47. mode: 0640
  48. become: false
  49. delegate_to: 127.0.0.1
  50. when: matrix_bot_honoroit_basicauth_enabled | bool
  51. - name: Ensure honoroit support files installed
  52. ansible.builtin.template:
  53. src: "{{ role_path }}/templates/{{ item }}.j2"
  54. dest: "{{ matrix_bot_honoroit_config_path }}/{{ item }}"
  55. owner: "{{ matrix_user_username }}"
  56. group: "{{ matrix_user_groupname }}"
  57. mode: 0640
  58. with_items:
  59. - env
  60. - labels
  61. - name: Ensure temporary basic auth file is removed
  62. ansible.builtin.file:
  63. path: "{{ matrix_bot_honoroit_basicauth_file }}"
  64. state: absent
  65. become: false
  66. delegate_to: 127.0.0.1
  67. when: matrix_bot_honoroit_basicauth_enabled | bool
  68. - name: Ensure honoroit image is pulled
  69. community.docker.docker_image:
  70. name: "{{ matrix_bot_honoroit_docker_image }}"
  71. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  72. force_source: "{{ matrix_bot_honoroit_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  73. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_honoroit_docker_image_force_pull }}"
  74. when: "not matrix_bot_honoroit_container_image_self_build | bool"
  75. register: result
  76. retries: "{{ devture_playbook_help_container_retries_count }}"
  77. delay: "{{ devture_playbook_help_container_retries_delay }}"
  78. until: result is not failed
  79. - name: Ensure honoroit repository is present on self-build
  80. ansible.builtin.git:
  81. repo: "{{ matrix_bot_honoroit_docker_repo }}"
  82. version: "{{ matrix_bot_honoroit_docker_repo_version }}"
  83. dest: "{{ matrix_bot_honoroit_docker_src_files_path }}"
  84. force: "yes"
  85. become: true
  86. become_user: "{{ matrix_user_username }}"
  87. register: matrix_bot_honoroit_git_pull_results
  88. when: "matrix_bot_honoroit_container_image_self_build | bool"
  89. - name: Ensure honoroit image is built
  90. community.docker.docker_image:
  91. name: "{{ matrix_bot_honoroit_docker_image }}"
  92. source: build
  93. force_source: "{{ matrix_bot_honoroit_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  94. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_bot_honoroit_container_image_self_build.changed }}"
  95. build:
  96. dockerfile: Dockerfile
  97. path: "{{ matrix_bot_honoroit_docker_src_files_path }}"
  98. pull: true
  99. when: "matrix_bot_honoroit_container_image_self_build | bool"
  100. - name: Ensure honoroit container network is created
  101. community.general.docker_network:
  102. name: "{{ matrix_bot_honoroit_container_network }}"
  103. driver: bridge
  104. - name: Ensure matrix-bot-honoroit.service installed
  105. ansible.builtin.template:
  106. src: "{{ role_path }}/templates/systemd/matrix-bot-honoroit.service.j2"
  107. dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-bot-honoroit.service"
  108. mode: 0644
  109. register: matrix_bot_honoroit_systemd_service_result
  110. - name: Ensure matrix-bot-honoroit.service restarted, if necessary
  111. ansible.builtin.service:
  112. name: "matrix-bot-honoroit.service"
  113. state: restarted
  114. daemon_reload: true
  115. when: "matrix_bot_honoroit_requires_restart | bool"