Matrix Docker Ansible eploy
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

197 řádky
8.1 KiB

  1. ---
  2. - import_tasks: "{{ role_path }}/../matrix-base/tasks/util/ensure_openssl_installed.yml"
  3. - name: Ensure Appservice IRC paths exist
  4. file:
  5. path: "{{ item.path }}"
  6. state: directory
  7. mode: 0750
  8. owner: "{{ matrix_user_username }}"
  9. group: "{{ matrix_user_groupname }}"
  10. with_items:
  11. - {path: "{{ matrix_appservice_irc_base_path }}", when: true}
  12. - {path: "{{ matrix_appservice_irc_config_path }}", when: true}
  13. - {path: "{{ matrix_appservice_irc_data_path }}", when: true}
  14. - {path: "{{ matrix_appservice_irc_docker_src_files_path }}", when: "{{ matrix_appservice_irc_container_image_self_build }}"}
  15. when: item.when|bool
  16. - name: Check if an old passkey file already exists
  17. stat:
  18. path: "{{ matrix_appservice_irc_base_path }}/passkey.pem"
  19. register: matrix_appservice_irc_stat_passkey
  20. - block:
  21. - name: (Data relocation) Ensure matrix-appservice-irc.service is stopped
  22. service:
  23. name: matrix-appservice-irc
  24. state: stopped
  25. daemon_reload: true
  26. failed_when: false
  27. - name: (Data relocation) Move AppService IRC passkey.pem file to ./data directory
  28. command: "mv {{ matrix_appservice_irc_base_path }}/passkey.pem {{ matrix_appservice_irc_data_path }}/passkey.pem"
  29. - name: (Data relocation) Move AppService IRC database files to ./data directory
  30. command: "mv {{ matrix_appservice_irc_base_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}"
  31. with_items:
  32. - rooms.db
  33. - users.db
  34. failed_when: false
  35. when: "matrix_appservice_irc_stat_passkey.stat.exists"
  36. - set_fact:
  37. matrix_appservice_irc_requires_restart: false
  38. - block:
  39. - name: Check if a nedb database already exists
  40. stat:
  41. path: "{{ matrix_appservice_irc_data_path }}/users.db"
  42. register: matrix_appservice_irc_nedb_database_path_local_stat_result
  43. - block:
  44. - import_tasks: "{{ role_path }}/tasks/migrate_nedb_to_postgres.yml"
  45. - set_fact:
  46. matrix_appservice_irc_requires_restart: true
  47. when: "matrix_appservice_irc_nedb_database_path_local_stat_result.stat.exists|bool"
  48. when: "matrix_appservice_irc_database_engine == 'postgres'"
  49. - name: Ensure Appservice IRC image is pulled
  50. docker_image:
  51. name: "{{ matrix_appservice_irc_docker_image }}"
  52. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  53. force_source: "{{ matrix_appservice_irc_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  54. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_irc_docker_image_force_pull }}"
  55. when: "matrix_appservice_irc_enabled|bool and not matrix_appservice_irc_container_image_self_build|bool"
  56. - name: Ensure matrix-appservice-irc repository is present when self-building
  57. git:
  58. repo: "{{ matrix_appservice_irc_docker_repo }}"
  59. dest: "{{ matrix_appservice_irc_docker_src_files_path }}"
  60. force: "yes"
  61. register: matrix_appservice_irc_git_pull_results
  62. when: "matrix_appservice_irc_enabled|bool and matrix_appservice_irc_container_image_self_build|bool"
  63. - name: Ensure matrix-appservice-irc Docker image is built
  64. docker_image:
  65. name: "{{ matrix_appservice_irc_docker_image }}"
  66. source: build
  67. force_source: "{{ matrix_appservice_irc_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  68. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_irc_git_pull_results.changed }}"
  69. build:
  70. dockerfile: Dockerfile
  71. path: "{{ matrix_appservice_irc_docker_src_files_path }}"
  72. pull: true
  73. when: "matrix_appservice_irc_enabled|bool and matrix_appservice_irc_container_image_self_build|bool and matrix_appservice_irc_git_pull_results.changed"
  74. - name: Ensure Matrix Appservice IRC config installed
  75. copy:
  76. content: "{{ matrix_appservice_irc_configuration|to_nice_yaml }}"
  77. dest: "{{ matrix_appservice_irc_config_path }}/config.yaml"
  78. mode: 0644
  79. owner: "{{ matrix_user_username }}"
  80. group: "{{ matrix_user_groupname }}"
  81. - name: Check if Appservice IRC passkey exists
  82. stat:
  83. path: "{{ matrix_appservice_irc_data_path }}/passkey.pem"
  84. register: irc_passkey_file
  85. - name: Generate Appservice IRC passkey if it doesn't exist
  86. shell: "{{ matrix_host_command_openssl }} genpkey -out {{ matrix_appservice_irc_data_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:2048"
  87. become: true
  88. become_user: "{{ matrix_user_username }}"
  89. when: "not irc_passkey_file.stat.exists"
  90. # In the past, we used to generate the passkey.pem file with root, so permissions may not be okay.
  91. # Fix it.
  92. - name: (Migration) Ensure Appservice IRC passkey permissions are okay
  93. file:
  94. path: "{{ matrix_appservice_irc_data_path }}/passkey.pem"
  95. mode: 0644
  96. owner: "{{ matrix_user_username }}"
  97. group: "{{ matrix_user_groupname }}"
  98. # Ideally, we'd like to generate the final registration.yaml file by ourselves.
  99. #
  100. # However, the IRC bridge supports multiple servers, which leads to multiple
  101. # users/aliases/rooms rules in the registration file.
  102. #
  103. # Generating a proper file by ourselves is complicated and may lead to deviation
  104. # from what the bridge is doing.
  105. #
  106. # Instead, we do another hacky thing - asking the bridge to generate a template,
  107. # and then we parse it and fix it up with our own AS/HS token.
  108. # We need to do this, because:
  109. # - we'd like to have an up-to-date registration file
  110. # - we can achieve this by asking the bridge to rebuild it each time
  111. # - however, the bridge insists on regenerating all tokens each time
  112. # - .. which is not friendly for integrating with the homeserver
  113. #
  114. # So we have a hybrid approach. We ask the bridge to always generate
  115. # an up-to-date file, and we fix it up with some static values later on,
  116. # to produce a final registration.yaml file, as we desire.
  117. - name: Generate Appservice IRC registration-template.yaml
  118. shell: >-
  119. {{ matrix_host_command_docker }} run --rm --name matrix-appservice-irc-gen
  120. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  121. --cap-drop=ALL
  122. -v {{ matrix_appservice_irc_config_path }}:/config:z
  123. -v {{ matrix_appservice_irc_data_path }}:/data:z
  124. --entrypoint=/bin/bash
  125. {{ matrix_appservice_irc_docker_image }}
  126. -c
  127. 'node app.js
  128. -r
  129. -f /config/registration-template.yaml
  130. -u "http://matrix-appservice-irc:9999"
  131. -c /config/config.yaml
  132. -l irc_bot'
  133. changed_when: false
  134. - name: Read Appservice IRC registration-template.yaml
  135. slurp:
  136. src: "{{ matrix_appservice_irc_config_path }}/registration-template.yaml"
  137. register: matrix_appservice_irc_registration_template_slurp
  138. - name: Remove unnecessary Appservice IRC registration-template.yaml
  139. file:
  140. path: "{{ matrix_appservice_irc_config_path }}/registration-template.yaml"
  141. state: absent
  142. changed_when: false
  143. - name: Parse registration-template.yaml
  144. set_fact:
  145. matrix_appservice_irc_registration_template: "{{ matrix_appservice_irc_registration_template_slurp['content'] | b64decode | from_yaml }}"
  146. - name: Combine registration-template.yaml and own registration override config
  147. set_fact:
  148. matrix_appservice_irc_registration: "{{ matrix_appservice_irc_registration_template|combine(matrix_appservice_irc_registration_override, recursive=True) }}"
  149. - name: Ensure Appservice IRC registration.yaml installed
  150. copy:
  151. content: "{{ matrix_appservice_irc_registration|to_nice_yaml }}"
  152. dest: "{{ matrix_appservice_irc_config_path }}/registration.yaml"
  153. mode: 0644
  154. owner: "{{ matrix_user_username }}"
  155. group: "{{ matrix_user_groupname }}"
  156. - name: Ensure matrix-appservice-irc.service installed
  157. template:
  158. src: "{{ role_path }}/templates/systemd/matrix-appservice-irc.service.j2"
  159. dest: "{{ matrix_systemd_path }}/matrix-appservice-irc.service"
  160. mode: 0644
  161. register: matrix_appservice_irc_systemd_service_result
  162. - name: Ensure systemd reloaded after matrix-appservice-irc.service installation
  163. service:
  164. daemon_reload: true
  165. when: "matrix_appservice_irc_systemd_service_result.changed"
  166. - name: Ensure matrix-appservice-irc.service restarted, if necessary
  167. service:
  168. name: "matrix-appservice-irc.service"
  169. state: restarted
  170. when: "matrix_appservice_irc_requires_restart|bool"