mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2025-06-25 18:57:50 +02:00
Feat: Added element call setup and configuration.
This commit is contained in:
@ -0,0 +1,22 @@
|
||||
---
|
||||
---
|
||||
# Create the element.json file to point to Element Call
|
||||
|
||||
- name: Ensure .well-known/element directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ matrix_element_call_well_known_element_path | dirname }}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: Create or update the element.json file with Element Call config
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ matrix_element_call_well_known_element_path }}"
|
||||
content: |
|
||||
{
|
||||
"call": {
|
||||
"widget_url": "{{ matrix_element_call_base_url }}"
|
||||
}
|
||||
}
|
||||
mode: '0644'
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
17
roles/custom/matrix-element-call/tasks/install.yml
Normal file
17
roles/custom/matrix-element-call/tasks/install.yml
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
# Main install task for matrix-element-call
|
||||
|
||||
- name: Install Docker containers for Element Call
|
||||
include_tasks: install_docker_containers.yml
|
||||
|
||||
- name: Update .well-known/matrix/client
|
||||
include_tasks: update_well_known_client.yml
|
||||
|
||||
- name: Create .well-known/element/element.json
|
||||
include_tasks: create_element_json.yml
|
||||
|
||||
- name: Update homeserver.yaml for Element Call
|
||||
include_tasks: update_homeserver_config.yml
|
||||
|
||||
- name: Update Element-Web config.json for Element Call
|
||||
include_tasks: update_element_web_config.yml
|
@ -0,0 +1,158 @@
|
||||
---
|
||||
# Ensure Required Directories Exist
|
||||
- name: Ensure matrix-element-call paths exist
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
state: directory
|
||||
mode: 0750
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
loop:
|
||||
- path: "{{ matrix_element_call_base_path }}"
|
||||
- path: "{{ matrix_element_call_base_path }}/data"
|
||||
- path: "{{ matrix_element_call_base_path }}/config"
|
||||
- path: "{{ matrix_element_call_base_path }}/backend" # For LiveKit and Redis config
|
||||
|
||||
# Ensure Configuration Files are in Place
|
||||
- name: Ensure Element Call config.json is in place
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/config.json.j2"
|
||||
dest: "{{ matrix_element_call_base_path }}/config/config.json"
|
||||
mode: 0640
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
|
||||
- name: Ensure LiveKit livekit.yaml is in place
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/livekit.yaml.j2"
|
||||
dest: "{{ matrix_element_call_base_path }}/backend/livekit.yaml"
|
||||
mode: 0640
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
|
||||
- name: Ensure Redis redis.conf is in place
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/redis.conf.j2"
|
||||
dest: "{{ matrix_element_call_base_path }}/backend/redis.conf"
|
||||
mode: 0640
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
|
||||
- name: Ensure matrix-element-call environment file is in place
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/env.j2"
|
||||
dest: "{{ matrix_element_call_base_path }}/config/env"
|
||||
mode: 0640
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
|
||||
- name: Ensure matrix-element-call Docker labels file is in place
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/labels.j2"
|
||||
dest: "{{ matrix_element_call_base_path }}/config/labels"
|
||||
mode: 0640
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
|
||||
# Ensure Docker Images are Pulled
|
||||
- name: Ensure matrix-element-call Docker image is pulled
|
||||
community.docker.docker_image:
|
||||
name: "{{ matrix_element_call_image }}"
|
||||
source: pull
|
||||
force_source: "{{ matrix_element_call_container_image_force_pull }}"
|
||||
register: element_call_image_result
|
||||
retries: "{{ devture_playbook_help_container_retries_count }}"
|
||||
delay: "{{ devture_playbook_help_container_retries_delay }}"
|
||||
until: element_call_image_result is not failed
|
||||
|
||||
- name: Ensure jwt-service Docker image is pulled
|
||||
community.docker.docker_image:
|
||||
name: "ghcr.io/element-hq/lk-jwt-service:latest-ci"
|
||||
source: pull
|
||||
register: jwt_image_result
|
||||
retries: 3
|
||||
delay: 10
|
||||
until: jwt_image_result is not failed
|
||||
|
||||
- name: Ensure livekit Docker image is pulled
|
||||
community.docker.docker_image:
|
||||
name: "livekit/livekit-server:latest"
|
||||
source: pull
|
||||
register: livekit_image_result
|
||||
retries: 3
|
||||
delay: 10
|
||||
until: livekit_image_result is not failed
|
||||
|
||||
- name: Ensure redis Docker image is pulled
|
||||
community.docker.docker_image:
|
||||
name: "redis:6-alpine"
|
||||
source: pull
|
||||
register: redis_image_result
|
||||
retries: 3
|
||||
delay: 10
|
||||
until: redis_image_result is not failed
|
||||
|
||||
# Ensure Docker Containers are Running
|
||||
- name: Run matrix-element-call Docker container
|
||||
community.docker.docker_container:
|
||||
name: "matrix-element-call"
|
||||
image: "{{ matrix_element_call_image }}"
|
||||
state: started
|
||||
restart_policy: unless-stopped
|
||||
env_file: "{{ matrix_element_call_base_path }}/config/env"
|
||||
labels: "{{ lookup('file', matrix_element_call_base_path ~ '/config/labels') | from_yaml }}"
|
||||
networks:
|
||||
- name: "{{ matrix_element_call_container_network }}"
|
||||
volumes:
|
||||
- "{{ matrix_element_call_base_path }}/config/config.json:/app/config.json"
|
||||
- "{{ matrix_element_call_base_path }}/data:/data"
|
||||
|
||||
- name: Run jwt-service Docker container
|
||||
community.docker.docker_container:
|
||||
name: "matrix-jwt-service"
|
||||
image: "ghcr.io/element-hq/lk-jwt-service:latest-ci"
|
||||
state: started
|
||||
restart_policy: unless-stopped
|
||||
environment:
|
||||
LIVEKIT_SECRET: "{{ matrix_element_call_livekit_dev_key }}" # User-specified key
|
||||
LIVEKIT_URL: "{{ matrix_element_call_livekit_service_url }}"
|
||||
LIVEKIT_KEY: "devkey"
|
||||
networks:
|
||||
- name: "{{ matrix_element_call_container_network }}"
|
||||
|
||||
- name: Run livekit Docker container
|
||||
community.docker.docker_container:
|
||||
name: "matrix-livekit"
|
||||
image: "livekit/livekit-server:latest"
|
||||
state: started
|
||||
restart_policy: unless-stopped
|
||||
command: "--dev --config /etc/livekit.yaml"
|
||||
volumes:
|
||||
- "{{ matrix_element_call_base_path }}/backend/livekit.yaml:/etc/livekit.yaml"
|
||||
network_mode: "host"
|
||||
|
||||
- name: Run redis Docker container
|
||||
community.docker.docker_container:
|
||||
name: "matrix-redis"
|
||||
image: "redis:6-alpine"
|
||||
state: started
|
||||
restart_policy: unless-stopped
|
||||
command: redis-server /etc/redis.conf
|
||||
volumes:
|
||||
- "{{ matrix_element_call_base_path }}/backend/redis.conf:/etc/redis.conf"
|
||||
networks:
|
||||
- name: "{{ matrix_element_call_container_network }}"
|
||||
|
||||
# Ensure Systemd Services are Set Up
|
||||
- name: Ensure matrix-element-call systemd service is installed
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/element-call.service.j2"
|
||||
dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-element-call.service"
|
||||
mode: 0644
|
||||
|
||||
- name: Ensure matrix-element-call systemd service is enabled and started
|
||||
ansible.builtin.systemd:
|
||||
name: matrix-element-call
|
||||
enabled: true
|
||||
state: started
|
||||
daemon_reload: true
|
14
roles/custom/matrix-element-call/tasks/main.yml
Normal file
14
roles/custom/matrix-element-call/tasks/main.yml
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
# roles/custom/matrix-element-call/tasks/main.yml
|
||||
|
||||
- name: Ensure Element Call dependencies are valid and present
|
||||
when: matrix_element_call_enabled | bool
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/validate_config.yml"
|
||||
|
||||
- name: Install Element Call and its related services
|
||||
when: matrix_element_call_enabled | bool
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/install.yml"
|
||||
|
||||
- name: Uninstall Element Call and clean up resources
|
||||
when: not matrix_element_call_enabled | bool
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/uninstall.yml"
|
51
roles/custom/matrix-element-call/tasks/uninstall.yml
Normal file
51
roles/custom/matrix-element-call/tasks/uninstall.yml
Normal file
@ -0,0 +1,51 @@
|
||||
---
|
||||
---
|
||||
# roles/custom/matrix-element-call/tasks/uninstall.yml
|
||||
|
||||
# Stop and remove Docker containers
|
||||
- name: Stop and remove matrix-element-call Docker container
|
||||
community.docker.docker_container:
|
||||
name: "matrix-element-call"
|
||||
state: absent
|
||||
when: matrix_element_call_enabled | bool == false
|
||||
|
||||
- name: Stop and remove jwt-service Docker container
|
||||
community.docker.docker_container:
|
||||
name: "matrix-jwt-service"
|
||||
state: absent
|
||||
when: matrix_element_call_enabled | bool == false
|
||||
|
||||
- name: Stop and remove livekit Docker container
|
||||
community.docker.docker_container:
|
||||
name: "matrix-livekit"
|
||||
state: absent
|
||||
when: matrix_element_call_enabled | bool == false
|
||||
|
||||
- name: Stop and remove redis Docker container
|
||||
community.docker.docker_container:
|
||||
name: "matrix-redis"
|
||||
state: absent
|
||||
when: matrix_element_call_enabled | bool == false
|
||||
|
||||
# Remove matrix-element-call directories
|
||||
- name: Remove matrix-element-call directories
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- "{{ matrix_element_call_base_path }}"
|
||||
when: matrix_element_call_enabled | bool == false
|
||||
|
||||
# Disable and remove systemd service for matrix-element-call
|
||||
- name: Stop and disable matrix-element-call systemd service
|
||||
ansible.builtin.systemd:
|
||||
name: matrix-element-call
|
||||
state: stopped
|
||||
enabled: false
|
||||
when: matrix_element_call_enabled | bool == false
|
||||
|
||||
- name: Remove matrix-element-call systemd service file
|
||||
ansible.builtin.file:
|
||||
path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-element-call.service"
|
||||
state: absent
|
||||
when: matrix_element_call_enabled | bool == false
|
@ -0,0 +1,29 @@
|
||||
---
|
||||
# Update Element-Web config.json with Element Call features
|
||||
|
||||
- name: Ensure Element-Web config.json exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ matrix_element_web_config_path }}"
|
||||
state: file
|
||||
mode: 0644
|
||||
|
||||
- name: Update Element-Web config.json with Element Call features
|
||||
ansible.builtin.blockinfile:
|
||||
path: "{{ matrix_element_web_config_path }}"
|
||||
block: |
|
||||
"features": {
|
||||
"feature_video_rooms": true,
|
||||
"feature_new_room_decoration_ui": true,
|
||||
"feature_group_calls": true,
|
||||
"feature_element_call_video_rooms": true
|
||||
},
|
||||
"element_call": {
|
||||
"url": "{{ matrix_element_call_base_url }}",
|
||||
"participant_limit": 8,
|
||||
"brand": "Element Call",
|
||||
"use_exclusively": true
|
||||
}
|
||||
marker: "# ANSIBLE MANAGED BLOCK - Element Call features"
|
||||
mode: '0644'
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
@ -0,0 +1,36 @@
|
||||
---
|
||||
# Update the homeserver.yaml file with Element Call config
|
||||
|
||||
- name: Ensure homeserver.yaml exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ matrix_homeserver_config_path }}"
|
||||
state: file
|
||||
mode: 0644
|
||||
|
||||
- name: Add listeners section for Element Call to homeserver.yaml
|
||||
ansible.builtin.blockinfile:
|
||||
path: "{{ matrix_homeserver_config_path }}"
|
||||
block: |
|
||||
listeners:
|
||||
- port: 8008
|
||||
tls: false
|
||||
type: http
|
||||
x_forwarded: true
|
||||
|
||||
resources:
|
||||
- names: [client, federation, openid]
|
||||
compress: false
|
||||
marker: "# ANSIBLE MANAGED BLOCK - Element Call listeners"
|
||||
mode: '0644'
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
||||
|
||||
- name: Ensure serve_server_wellknown is enabled in homeserver.yaml
|
||||
ansible.builtin.lineinfile:
|
||||
path: "{{ matrix_homeserver_config_path }}"
|
||||
line: "serve_server_wellknown: true"
|
||||
insertafter: EOF
|
||||
state: present
|
||||
mode: '0644'
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
@ -0,0 +1,24 @@
|
||||
---
|
||||
---
|
||||
# Update the .well-known/matrix/client file with Element Call config
|
||||
|
||||
- name: Ensure .well-known directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ matrix_element_call_well_known_client_path | dirname }}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
|
||||
- name: Update .well-known/matrix/client file with Element Call config
|
||||
ansible.builtin.blockinfile:
|
||||
path: "{{ matrix_element_call_well_known_client_path }}"
|
||||
block: |
|
||||
"org.matrix.msc4143.rtc_foci": [
|
||||
{
|
||||
"type": "livekit",
|
||||
"livekit_service_url": "{{ matrix_element_call_jwt_service_url }}"
|
||||
}
|
||||
]
|
||||
create: yes
|
||||
mode: '0644'
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_groupname }}"
|
79
roles/custom/matrix-element-call/tasks/validate_config.yml
Normal file
79
roles/custom/matrix-element-call/tasks/validate_config.yml
Normal file
@ -0,0 +1,79 @@
|
||||
---
|
||||
# roles/custom/matrix-element-call/tasks/validate_config.yml
|
||||
|
||||
- name: Ensure required variables for Element Call are defined
|
||||
ansible.builtin.fail:
|
||||
msg: "The variable '{{ item }}' is required and must be set."
|
||||
when: vars[item] is not defined or vars[item] == ''
|
||||
loop:
|
||||
- matrix_element_call_enabled
|
||||
- matrix_element_call_version
|
||||
- matrix_element_call_hostname
|
||||
- matrix_element_call_path_prefix
|
||||
- matrix_element_call_base_path
|
||||
- matrix_element_call_container_image
|
||||
- matrix_element_call_container_network
|
||||
- matrix_element_call_container_labels_traefik_hostname
|
||||
- matrix_element_call_jwt_service_url
|
||||
- matrix_element_call_livekit_service_url
|
||||
- matrix_element_call_livekit_dev_key
|
||||
|
||||
- name: Validate that the Element Call hostname is properly formatted
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'{{ matrix_element_call_hostname }}' is match('^([a-zA-Z0-9][-a-zA-Z0-9]*[a-zA-Z0-9])$')"
|
||||
fail_msg: "The hostname '{{ matrix_element_call_hostname }}' is not valid. It should be a valid domain or subdomain."
|
||||
success_msg: "The hostname '{{ matrix_element_call_hostname }}' is valid."
|
||||
|
||||
- name: Validate that the Element Call version is specified correctly
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_call_version is string
|
||||
- matrix_element_call_version != ''
|
||||
fail_msg: "The Element Call version must be a non-empty string."
|
||||
success_msg: "The Element Call version is set correctly."
|
||||
|
||||
- name: Ensure LiveKit dev key is set
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_call_livekit_dev_key is string
|
||||
- matrix_element_call_livekit_dev_key != ''
|
||||
fail_msg: "The LiveKit dev key (matrix_element_call_livekit_dev_key) must be a non-empty string."
|
||||
success_msg: "The LiveKit dev key is set correctly."
|
||||
|
||||
- name: Ensure JWT service URL is valid
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_call_jwt_service_url is match('^https?://[a-zA-Z0-9.-]+$')
|
||||
fail_msg: "The JWT service URL '{{ matrix_element_call_jwt_service_url }}' is not valid."
|
||||
success_msg: "The JWT service URL is valid."
|
||||
|
||||
- name: Ensure LiveKit service URL is valid
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_call_livekit_service_url is match('^https?://[a-zA-Z0-9.-]+$')
|
||||
fail_msg: "The LiveKit service URL '{{ matrix_element_call_livekit_service_url }}' is not valid."
|
||||
success_msg: "The LiveKit service URL is valid."
|
||||
|
||||
- name: Ensure matrix-element-call base path is set and exists
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- matrix_element_call_base_path is string
|
||||
- matrix_element_call_base_path != ''
|
||||
fail_msg: "The base path for Element Call (matrix_element_call_base_path) must be a non-empty string."
|
||||
success_msg: "The base path for Element Call is set correctly."
|
||||
|
||||
- name: Ensure required paths for configurations are accessible
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
with_items:
|
||||
- "{{ matrix_element_call_base_path }}/config"
|
||||
- "{{ matrix_element_call_base_path }}/backend"
|
||||
register: config_paths_check
|
||||
|
||||
- name: Fail if any required paths for configurations are not accessible
|
||||
ansible.builtin.fail:
|
||||
msg: "The required configuration path '{{ item.path }}' does not exist or is not accessible."
|
||||
when: config_paths_check.results is defined and config_paths_check.results | selectattr('failed', 'eq', True) | list | length > 0
|
||||
loop: "{{ config_paths_check.results | selectattr('failed', 'eq', True) | list }}"
|
Reference in New Issue
Block a user