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.
 
 

94 lines
3.6 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. - name: Ensure Appservice Discord base directory exists
  13. file:
  14. path: "{{ matrix_appservice_discord_base_path }}"
  15. state: directory
  16. mode: 0750
  17. owner: "{{ matrix_user_username }}"
  18. group: "{{ matrix_user_username }}"
  19. - name: Ensure Matrix Appservice Discord config installed
  20. copy:
  21. content: "{{ matrix_appservice_discord_configuration|to_nice_yaml }}"
  22. dest: "{{ matrix_appservice_discord_base_path }}/config.yaml"
  23. mode: 0644
  24. owner: "{{ matrix_user_username }}"
  25. group: "{{ matrix_user_username }}"
  26. - name: Ensure matrix-appservice-discord.service installed
  27. template:
  28. src: "{{ role_path }}/templates/systemd/matrix-appservice-discord.service.j2"
  29. dest: "/etc/systemd/system/matrix-appservice-discord.service"
  30. mode: 0644
  31. register: matrix_appservice_discord_systemd_service_result
  32. - name: Ensure systemd reloaded after matrix-appservice-discord.service installation
  33. service:
  34. daemon_reload: yes
  35. when: "matrix_appservice_discord_systemd_service_result.changed"
  36. - name: Check if a matrix-appservice-discord registration file exists
  37. stat:
  38. path: "{{ matrix_appservice_discord_base_path }}/discord-registration.yaml"
  39. register: appservice_discord_registration_file
  40. - name: Generate matrix-appservice-discord discord-registration.yaml if it doesn't exist
  41. shell: >-
  42. /usr/bin/docker run --rm --name matrix-appservice-discord-gen
  43. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  44. --cap-drop=ALL
  45. -v {{ matrix_appservice_discord_base_path }}:/data:z
  46. {{ matrix_appservice_discord_docker_image }}
  47. node build/src/discordas.js
  48. -r
  49. -u "http://matrix-appservice-discord:9005"
  50. -c /data/config.yaml
  51. -f /data/discord-registration.yaml
  52. -l discord_bot
  53. when: "not appservice_discord_registration_file.stat.exists"
  54. - set_fact:
  55. matrix_synapse_app_service_config_file_appservice_discord: '{{ matrix_appservice_discord_base_path }}/discord-registration.yml'
  56. - name: Check if a matrix-appservice-discord invite_link file exists
  57. stat:
  58. path: "{{ matrix_appservice_discord_base_path }}/invite_link"
  59. register: appservice_discord_link_generated
  60. - name: Generate your discord invite link
  61. shell: >-
  62. /usr/bin/docker run --rm --name matrix-appservice-discord-link-gen
  63. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  64. --cap-drop=ALL
  65. -v {{ matrix_appservice_discord_base_path }}:/data
  66. -w /data
  67. {{ matrix_appservice_discord_docker_image }}
  68. /bin/sh -c "node .././build/tools/addbot.js > invite_link"
  69. when: "not appservice_discord_link_generated.stat.exists"
  70. # If the matrix-synapse role is not used, these variables may not exist.
  71. - set_fact:
  72. matrix_synapse_container_additional_volumes: >
  73. {{ matrix_synapse_container_additional_volumes|default([]) }}
  74. +
  75. {{ [{'src': '{{ matrix_appservice_discord_base_path }}/discord-registration.yaml', 'dst': '{{ matrix_synapse_app_service_config_file_appservice_discord }}', 'options': 'ro'}] }}
  76. matrix_synapse_app_service_config_files: >
  77. {{ matrix_synapse_app_service_config_files|default([]) }}
  78. +
  79. {{ ["{{ matrix_synapse_app_service_config_file_appservice_discord }}"] | to_nice_json }}