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.2 KiB

  1. ---
  2. - name: Ensure AppService Slack paths exist
  3. file:
  4. path: "{{ item.path }}"
  5. state: directory
  6. mode: 0750
  7. owner: "{{ matrix_user_username }}"
  8. group: "{{ matrix_user_groupname }}"
  9. with_items:
  10. - {path: "{{ matrix_appservice_slack_base_path }}", when: true}
  11. - {path: "{{ matrix_appservice_slack_config_path }}", when: true}
  12. - {path: "{{ matrix_appservice_slack_data_path }}", when: true}
  13. - {path: "{{ matrix_appservice_slack_docker_src_files_path }}", when: "{{ matrix_appservice_slack_container_image_self_build }}"}
  14. when: item.when|bool
  15. - set_fact:
  16. matrix_appservice_slack_requires_restart: false
  17. - block:
  18. - name: Check if a nedb database already exists
  19. stat:
  20. path: "{{ matrix_appservice_slack_data_path }}/teams.db"
  21. register: matrix_appservice_slack_nedb_database_path_local_stat_result
  22. - block:
  23. - import_tasks: "{{ role_path }}/tasks/migrate_nedb_to_postgres.yml"
  24. - set_fact:
  25. matrix_appservice_slack_requires_restart: true
  26. when: "matrix_appservice_slack_nedb_database_path_local_stat_result.stat.exists|bool"
  27. when: "matrix_appservice_slack_database_engine == 'postgres'"
  28. - name: Ensure Appservice Slack image is pulled
  29. docker_image:
  30. name: "{{ matrix_appservice_slack_docker_image }}"
  31. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  32. force_source: "{{ matrix_appservice_slack_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  33. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_slack_docker_image_force_pull }}"
  34. when: "not matrix_appservice_slack_container_image_self_build|bool"
  35. register: result
  36. retries: "{{ matrix_container_retries_count }}"
  37. delay: "{{ matrix_container_retries_delay }}"
  38. until: result is not failed
  39. - name: Ensure matrix-appservice-slack repository is present when self-building
  40. git:
  41. repo: "{{ matrix_appservice_slack_docker_repo }}"
  42. dest: "{{ matrix_appservice_slack_docker_src_files_path }}"
  43. force: "yes"
  44. become: true
  45. become_user: "{{ matrix_user_username }}"
  46. register: matrix_appservice_slack_git_pull_results
  47. when: "matrix_appservice_slack_container_image_self_build|bool"
  48. - name: Ensure matrix-appservice-slack Docker image is built
  49. docker_image:
  50. name: "{{ matrix_appservice_slack_docker_image }}"
  51. source: build
  52. force_source: "{{ matrix_appservice_slack_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  53. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_slack_git_pull_results.changed }}"
  54. build:
  55. dockerfile: Dockerfile
  56. path: "{{ matrix_appservice_slack_docker_src_files_path }}"
  57. pull: true
  58. when: "matrix_appservice_slack_container_image_self_build|bool and matrix_appservice_slack_git_pull_results.changed"
  59. - name: Ensure Matrix Appservice Slack config installed
  60. copy:
  61. content: "{{ matrix_appservice_slack_configuration|to_nice_yaml(indent=2, width=999999) }}"
  62. dest: "{{ matrix_appservice_slack_config_path }}/config.yaml"
  63. mode: 0644
  64. owner: "{{ matrix_user_username }}"
  65. group: "{{ matrix_user_groupname }}"
  66. - name: Ensure appservice-slack registration.yaml installed
  67. copy:
  68. content: "{{ matrix_appservice_slack_registration|to_nice_yaml(indent=2, width=999999) }}"
  69. dest: "{{ matrix_appservice_slack_config_path }}/slack-registration.yaml"
  70. mode: 0644
  71. owner: "{{ matrix_user_username }}"
  72. group: "{{ matrix_user_groupname }}"
  73. - name: Ensure matrix-appservice-slack.service installed
  74. template:
  75. src: "{{ role_path }}/templates/systemd/matrix-appservice-slack.service.j2"
  76. dest: "{{ matrix_systemd_path }}/matrix-appservice-slack.service"
  77. mode: 0644
  78. register: matrix_appservice_slack_systemd_service_result
  79. - name: Ensure systemd reloaded after matrix-appservice-slack.service installation
  80. service:
  81. daemon_reload: true
  82. when: "matrix_appservice_slack_systemd_service_result.changed"
  83. - name: Ensure matrix-appservice-slack.service restarted, if necessary
  84. service:
  85. name: "matrix-appservice-slack.service"
  86. state: restarted
  87. when: "matrix_appservice_slack_requires_restart|bool"