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.
 
 

91 lines
3.5 KiB

  1. ---
  2. # If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist.
  3. # We don't want to fail in such cases.
  4. - name: Fail if matrix-synapse role already executed
  5. fail:
  6. msg: >-
  7. The matrix-bridge-appservice-discord role needs to execute before the matrix-synapse role.
  8. when: "matrix_synapse_role_executed|default(False)"
  9. - name: Ensure Appservice Discord image is pulled
  10. docker_image:
  11. name: "{{ matrix_appservice_discord_docker_image }}"
  12. source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
  13. - name: Ensure Appservice Discord base directory exists
  14. file:
  15. path: "{{ matrix_appservice_discord_base_path }}"
  16. state: directory
  17. mode: 0750
  18. owner: "{{ matrix_user_username }}"
  19. group: "{{ matrix_user_username }}"
  20. - name: Ensure Matrix Appservice Discord config installed
  21. copy:
  22. content: "{{ matrix_appservice_discord_configuration|to_nice_yaml }}"
  23. dest: "{{ matrix_appservice_discord_base_path }}/config.yaml"
  24. mode: 0644
  25. owner: "{{ matrix_user_username }}"
  26. group: "{{ matrix_user_username }}"
  27. - name: Ensure matrix-appservice-discord.service installed
  28. template:
  29. src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2"
  30. dest: "/etc/systemd/system/matrix-appservice-discord.service"
  31. mode: 0644
  32. register: matrix_appservice_discord_systemd_service_result
  33. - name: Ensure systemd reloaded after matrix-appservice-discord.service installation
  34. service:
  35. daemon_reload: yes
  36. when: "matrix_appservice_discord_systemd_service_result.changed"
  37. - name: Check if a matrix-appservice-discord registration file exists
  38. stat:
  39. path: "{{ matrix_appservice_discord_base_path }}/discord-registration.yaml"
  40. register: appservice_discord_registration_file
  41. - name: Generate matrix-appservice-discord discord-registration.yaml if it doesn't exist
  42. shell: >-
  43. /usr/bin/docker run --rm --name matrix-appservice-discord-gen
  44. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  45. --cap-drop=ALL
  46. -v {{ matrix_appservice_discord_base_path }}:/data:z
  47. {{ matrix_appservice_discord_docker_image }}
  48. node build/src/discordas.js
  49. -r
  50. -u "http://matrix-appservice-discord:9005"
  51. -c /data/config.yaml
  52. -f /data/discord-registration.yaml
  53. -l discord_bot
  54. when: "not appservice_discord_registration_file.stat.exists"
  55. - name: Check if a matrix-appservice-discord invite_link file exists
  56. stat:
  57. path: "{{ matrix_appservice_discord_base_path }}/invite_link"
  58. register: appservice_discord_link_generated
  59. - name: Generate your discord invite link
  60. shell: >-
  61. /usr/bin/docker run --rm --name matrix-appservice-discord-link-gen
  62. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  63. --cap-drop=ALL
  64. -v {{ matrix_appservice_discord_base_path }}:/data
  65. -w /data
  66. {{ matrix_appservice_discord_docker_image }}
  67. /bin/sh -c "node .././build/tools/addbot.js > invite_link"
  68. when: "not appservice_discord_link_generated.stat.exists"
  69. # If the matrix-synapse role is not used, these variables may not exist.
  70. - set_fact:
  71. matrix_synapse_container_extra_arguments: >
  72. {{ matrix_synapse_container_extra_arguments|default([]) }}
  73. +
  74. {{ ["--mount type=bind,src={{ matrix_appservice_discord_base_path }}/discord-registration.yaml,dst=/matrix-appservice-discord-registration.yaml,ro"] }}
  75. matrix_synapse_app_service_config_files: >
  76. {{ matrix_synapse_app_service_config_files|default([]) }}
  77. +
  78. {{ ["/matrix-appservice-discord-registration.yaml"] }}