Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

137 строки
5.5 KiB

  1. ---
  2. - name: Ensure Appservice IRC image is pulled
  3. docker_image:
  4. name: "{{ matrix_appservice_irc_docker_image }}"
  5. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  6. force_source: "{{ matrix_appservice_irc_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
  7. force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_irc_docker_image_force_pull }}"
  8. - name: Ensure Appservice IRC paths exist
  9. file:
  10. path: "{{ item }}"
  11. state: directory
  12. mode: 0750
  13. owner: "{{ matrix_user_username }}"
  14. group: "{{ matrix_user_username }}"
  15. with_items:
  16. - "{{ matrix_appservice_irc_base_path }}"
  17. - "{{ matrix_appservice_irc_config_path }}"
  18. - "{{ matrix_appservice_irc_data_path }}"
  19. - name: Check if an old passkey file already exists
  20. stat:
  21. path: "{{ matrix_appservice_irc_base_path }}/passkey.pem"
  22. register: matrix_appservice_irc_stat_passkey
  23. - name: (Data relocation) Ensure matrix-appservice-irc.service is stopped
  24. service:
  25. name: matrix-appservice-irc
  26. state: stopped
  27. daemon_reload: yes
  28. failed_when: false
  29. when: "matrix_appservice_irc_stat_passkey.stat.exists"
  30. - name: (Data relocation) Move AppService IRC passkey.pem file to ./data directory
  31. command: "mv {{ matrix_appservice_irc_base_path }}/passkey.pem {{ matrix_appservice_irc_data_path }}/passkey.pem"
  32. when: "matrix_appservice_irc_stat_passkey.stat.exists"
  33. - name: (Data relocation) Move AppService IRC database files to ./data directory
  34. command: "mv {{ matrix_appservice_irc_base_path }}/{{ item }} {{ matrix_appservice_irc_data_path }}/{{ item }}"
  35. with_items:
  36. - rooms.db
  37. - users.db
  38. failed_when: false
  39. when: "matrix_appservice_irc_stat_passkey.stat.exists"
  40. - name: Ensure Matrix Appservice IRC config installed
  41. copy:
  42. content: "{{ matrix_appservice_irc_configuration|to_nice_yaml }}"
  43. dest: "{{ matrix_appservice_irc_config_path }}/config.yaml"
  44. mode: 0644
  45. owner: "{{ matrix_user_username }}"
  46. group: "{{ matrix_user_username }}"
  47. - name: Check if Appservice IRC passkey exists
  48. stat:
  49. path: "{{ matrix_appservice_irc_data_path }}/passkey.pem"
  50. register: irc_passkey_file
  51. - name: Generate Appservice IRC passkey if it doesn't exist
  52. shell: /usr/bin/openssl genpkey -out {{ matrix_appservice_irc_data_path }}/passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:2048
  53. when: "not irc_passkey_file.stat.exists"
  54. # Ideally, we'd like to generate the final registration.yaml file by ourselves.
  55. #
  56. # However, the IRC bridge supports multiple servers, which leads to multiple
  57. # users/aliases/rooms rules in the registration file.
  58. #
  59. # Generating a proper file by ourselves is complicated and may lead to deviation
  60. # from what the bridge is doing.
  61. #
  62. # Instead, we do another hacky thing - asking the bridge to generate a template,
  63. # and then we parse it and fix it up with our own AS/HS token.
  64. # We need to do this, because:
  65. # - we'd like to have an up-to-date registration file
  66. # - we can achieve this by asking the bridge to rebuild it each time
  67. # - however, the bridge insists on regenerating all tokens each time
  68. # - .. which is not friendly for integrating with the homeserver
  69. #
  70. # So we have a hybrid approach. We ask the bridge to always generate
  71. # an up-to-date file, and we fix it up with some static values later on,
  72. # to produce a final registration.yaml file, as we desire.
  73. - name: Generate Appservice IRC registration-template.yaml
  74. shell: >-
  75. /usr/bin/docker run --rm --name matrix-appservice-irc-gen
  76. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  77. --cap-drop=ALL
  78. -v {{ matrix_appservice_irc_config_path }}:/config:z
  79. -v {{ matrix_appservice_irc_data_path }}:/data:z
  80. {{ matrix_appservice_irc_docker_image }}
  81. node app.js
  82. -r
  83. -f /config/registration-template.yaml
  84. -u "http://matrix-appservice-irc:9999"
  85. -c /config/config.yaml
  86. -l irc_bot
  87. changed_when: false
  88. - name: Read Appservice IRC registration-template.yaml
  89. slurp:
  90. src: "{{ matrix_appservice_irc_config_path }}/registration-template.yaml"
  91. register: matrix_appservice_irc_registration_template_slurp
  92. - name: Remove unnecessary Appservice IRC registration-template.yaml
  93. file:
  94. path: "{{ matrix_appservice_irc_config_path }}/registration-template.yaml"
  95. state: absent
  96. changed_when: false
  97. - name: Parse registration-template.yaml
  98. set_fact:
  99. matrix_appservice_irc_registration_template: "{{ matrix_appservice_irc_registration_template_slurp['content'] | b64decode | from_yaml }}"
  100. - name: Combine registration-template.yaml and own registration override config
  101. set_fact:
  102. matrix_appservice_irc_registration: "{{ matrix_appservice_irc_registration_template|combine(matrix_appservice_irc_registration_override, recursive=True) }}"
  103. - name: Ensure Appservice IRC registration.yaml installed
  104. copy:
  105. content: "{{ matrix_appservice_irc_registration|to_nice_yaml }}"
  106. dest: "{{ matrix_appservice_irc_config_path }}/registration.yaml"
  107. mode: 0644
  108. owner: "{{ matrix_user_username }}"
  109. group: "{{ matrix_user_username }}"
  110. - name: Ensure matrix-appservice-irc.service installed
  111. template:
  112. src: "{{ role_path }}/templates/systemd/matrix-appservice-irc.service.j2"
  113. dest: "/etc/systemd/system/matrix-appservice-irc.service"
  114. mode: 0644
  115. register: matrix_appservice_irc_systemd_service_result
  116. - name: Ensure systemd reloaded after matrix-appservice-irc.service installation
  117. service:
  118. daemon_reload: yes
  119. when: "matrix_appservice_irc_systemd_service_result.changed"