From c484c6294d35ec36000a3a2936e758f1b15bc56b Mon Sep 17 00:00:00 2001 From: Charles Wright Date: Thu, 4 Aug 2022 12:37:08 -0500 Subject: [PATCH] First pass at creating defaults and tasks for Conduit --- roles/matrix-conduit/defaults/main.yml | 49 +++++++++++++++++++ roles/matrix-conduit/tasks/conduit/setup.yml | 7 +++ .../tasks/conduit/setup_install.yml | 31 ++++++++++++ .../tasks/conduit/setup_uninstall.yml | 30 ++++++++++++ roles/matrix-conduit/tasks/init.yml | 5 ++ roles/matrix-conduit/tasks/main.yml | 17 +++++++ roles/matrix-conduit/tasks/setup_conduit.yml | 14 ++++++ 7 files changed, 153 insertions(+) create mode 100644 roles/matrix-conduit/defaults/main.yml create mode 100644 roles/matrix-conduit/tasks/conduit/setup.yml create mode 100644 roles/matrix-conduit/tasks/conduit/setup_install.yml create mode 100644 roles/matrix-conduit/tasks/conduit/setup_uninstall.yml create mode 100644 roles/matrix-conduit/tasks/init.yml create mode 100644 roles/matrix-conduit/tasks/main.yml create mode 100644 roles/matrix-conduit/tasks/setup_conduit.yml diff --git a/roles/matrix-conduit/defaults/main.yml b/roles/matrix-conduit/defaults/main.yml new file mode 100644 index 00000000..a4a9289d --- /dev/null +++ b/roles/matrix-conduit/defaults/main.yml @@ -0,0 +1,49 @@ +--- +# Conduit is a simple, fast and reliable chat server powered by Matrix +# See: https://conduit.rs + +matrix_conduit_enabled: true + +matrix_conduit_docker_image: "{{ matrix_conduit_docker_image_name_prefix}}matrixconduit/matrix-conduit:{{ matrix_conduit_docker_image_tag }}" +matrix_conduit_docker_image_name_prefix: "docker.io/" +matrix_conduit_docker_image_tag: "v0.4.0" +matrix_conduit_docker_image_force_pull: "{{ matrix_conduit_docker_image.endswith(':latest') }}" + +matrix_conduit_base_path: "{{ matrix_base_data_path }}/conduit" +matrix_conduit_config_dir_path: "{{ matrix_conduit_base_path }}/config" +matrix_conduit_storage_path: "{{ matrix_conduit_base_path }}/storage" + +matrix_conduit_port_number: 6167 + +# List of systemd services that matrix-conduit.service depends on +matrix_conduit_systemd_required_services_list: ["docker.service"] + +# List of systemd services that matrix-conduit.service wants +matrix_conduit_systemd_wanted_services_list: [] + +# Extra arguments for the Docker container +matrix_conduit_container_extra_arguments: [] + +# Specifies which template files to use when configuring Conduit. +# If you'd like to have your own different configuration, feel free to copy and paste +# the original files into your inventory (e.g. in `inventory/host_vars//`) +# and then change the specific host's `vars.yaml` file like this: +# matrix_conduit_template_conduit_config: "{{ playbook_dir }}/inventory/host_vars//conduit.yaml.j2" +matrix_conduit_template_conduit_config: "{{ role_path }}/templates/conduit/conduit.toml.j2" + +# Max size for uploads, in bytes +matrix_conduit_max_request_size: "20_000_000" + +# Enables registration. If set to false, no users can register on this server. +matrix_conduit_allow_registration: true + +matrix_conduit_allow_federation: true + +# Enable the display name lightning bolt on registration. +matrix_conduit_enable_lightning_bolt: true + +matrix_conduit_trusted_servers: + - "matrix.org" + +# How many requests Conduit sends to other servers at the same time +matrix_conduit_max_concurrent_requests: 100 diff --git a/roles/matrix-conduit/tasks/conduit/setup.yml b/roles/matrix-conduit/tasks/conduit/setup.yml new file mode 100644 index 00000000..57aaafdf --- /dev/null +++ b/roles/matrix-conduit/tasks/conduit/setup.yml @@ -0,0 +1,7 @@ +--- + +- import_tasks: "{{ role_path }}/tasks/conduit/setup_install.yml" + when: matrix_conduit_enabled|bool + +- import_tasks: "{{ role_path }}/tasks/conduit/setup_uninstall.yml" + when: "not matrix_conduit_enabled|bool" diff --git a/roles/matrix-conduit/tasks/conduit/setup_install.yml b/roles/matrix-conduit/tasks/conduit/setup_install.yml new file mode 100644 index 00000000..9fd933c7 --- /dev/null +++ b/roles/matrix-conduit/tasks/conduit/setup_install.yml @@ -0,0 +1,31 @@ +--- +- name: Ensure Conduit Docker image is pulled + docker_image: + name: "{{ matrix_conduit_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_conduit_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}" + force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_conduit_docker_image_force_pull }}" + register: result + retries: "{{ matrix_container_retries_count }}" + delay: "{{ matrix_container_retries_delay }}" + until: result is not failed + +- name: Ensure Conduit configuration installed + template: + src: "{{ role_path }}/templates/conduit/conduit.toml.j2" + dest: "{{ matrix_conduit_config_dir_path }}/conduit.toml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure matrix-conduit.service installed + template: + src: "{{ role_path }}/templates/conduit/systemd/matrix-conduit.service.j2" + dest: "{{ matrix_systemd_path }}/matrix-conduit.service" + mode: 0644 + register: matrix_conduit_systemd_service_result + +- name: Ensure systemd reloaded after matrix-conduit.service installation + service: + daemon_reload: true + when: "matrix_conduit_systemd_service_result.changed|bool" diff --git a/roles/matrix-conduit/tasks/conduit/setup_uninstall.yml b/roles/matrix-conduit/tasks/conduit/setup_uninstall.yml new file mode 100644 index 00000000..73722287 --- /dev/null +++ b/roles/matrix-conduit/tasks/conduit/setup_uninstall.yml @@ -0,0 +1,30 @@ +--- + +- name: Check existence of matrix-conduit service + stat: + path: "{{ matrix_systemd_path }}/matrix-conduit.service" + register: matrix_conduit_service_stat + +- name: Ensure matrix-conduit is stopped + service: + name: matrix-conduit + state: stopped + daemon_reload: true + register: stopping_result + when: "matrix_conduit_service_stat.stat.exists" + +- name: Ensure matrix-conduit.service doesn't exist + file: + path: "{{ matrix_systemd_path }}/matrix-conduit.service" + state: absent + when: "matrix_conduit_service_stat.stat.exists" + +- name: Ensure systemd reloaded after matrix-conduit.service removal + service: + daemon_reload: true + when: "matrix_conduit_service_stat.stat.exists" + +- name: Ensure Conduit Docker image doesn't exist + docker_image: + name: "{{ matrix_conduit_docker_image }}" + state: absent diff --git a/roles/matrix-conduit/tasks/init.yml b/roles/matrix-conduit/tasks/init.yml new file mode 100644 index 00000000..464278b7 --- /dev/null +++ b/roles/matrix-conduit/tasks/init.yml @@ -0,0 +1,5 @@ +--- + +- set_fact: + matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-conduit.service'] }}" + when: matrix_conduit_enabled|bool diff --git a/roles/matrix-conduit/tasks/main.yml b/roles/matrix-conduit/tasks/main.yml new file mode 100644 index 00000000..8ace5f48 --- /dev/null +++ b/roles/matrix-conduit/tasks/main.yml @@ -0,0 +1,17 @@ +--- + +- import_tasks: "{{ role_path }}/tasks/init.yml" + tags: + - always + +- import_tasks: "{{ role_path }}/tasks/setup_conduit.yml" + when: run_setup|bool + tags: + - setup-all + - setup-conduit + +- name: Mark matrix-conduit role as executed + set_fact: + matrix_conduit_role_executed: true + tags: + - always diff --git a/roles/matrix-conduit/tasks/setup_conduit.yml b/roles/matrix-conduit/tasks/setup_conduit.yml new file mode 100644 index 00000000..7979aee4 --- /dev/null +++ b/roles/matrix-conduit/tasks/setup_conduit.yml @@ -0,0 +1,14 @@ +--- +- name: Ensure Conduit paths exist + file: + path: "{{ item.path }}" + state: directory + mode: 0750 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - {path: "{{ matrix_conduit_config_dir_path }}", when: true} + - {path: "{{ matrix_conduit_data_dir_path }}", when: true} + when: "matrix_conduit_enabled|bool and item.when" + +- import_tasks: "{{ role_path }}/tasks/conduit/setup.yml"