From 318029b9a9747a4b4528c65cbd5e07f7acf5752d Mon Sep 17 00:00:00 2001 From: "Philip (a-0)" <@ph:a-0.me> Date: Sun, 4 Sep 2022 15:12:39 +0200 Subject: [PATCH] Support both binary & source install, improved README, fixed systemd service etc. --- README.md | 26 +++++++++++++- defaults/main.yml | 3 ++ example_playbook_fromsource.yml | 9 +++++ example_playbook_prebuilt.yml | 7 ++++ tasks/main.yml | 57 +++++++++++++++++++++++++------ templates/matrixmailer.service.j2 | 2 +- vars/debian.yml | 3 +- 7 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 example_playbook_fromsource.yml create mode 100644 example_playbook_prebuilt.yml diff --git a/README.md b/README.md index 339b740..d11eebb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,26 @@ -# matrixmailer +# Ansible role for matrixmailer +This role will install [matrixmailer](https://gitea.a-0.me/philip/matrixmailer) - either with pre-built binaries, or from source code directly on your system. It also sets up a systemd service and enables it. +# Supported operating systems +This playbook currently only supports debian systems. To suggest other platforms or contribute, feel free to join [#matrixmailer:a-0.me](matrix:r/matrixmailer:a-0.me). + +Despite higher system performance requirements, I recommend self-building the binary as the cross compiling is still in an experimental stage. + +# Configuration +See example playbooks for configuration samples. + +Required variables: +- `matrixmailer_version`: Pinned version of matrixmailer to install, e.g. "0.1.0" +- `matrixmailer_build`: Either "from_source" if you want to build it yourself, or the build target for prebuilt binaries, like "x86_64-unknown-linux-musl" +- `matrixmailer_config`: Yaml content of the configuration file. You may want to consider importing it from a file rather than putting the file content directly into the playbook. + +Optional variables: +- `matrixmailer_git_repo`: Only used when self-building the binary. Allows you to specify any URL a matrixmailer git repository can be pulled from. + +# System requirements +matrixmailer itself is very lightweight. However, self-building matrixmailer is only recommended on systems with +- at least one "powerful" or two CPU cores, and +- at least 2GB memory. + +# Disclaimer +Please be aware that this ansible role, as well as matrixmailer itself, are under active development. Be careful using it on production systems. \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml index 91217dc..c476b0f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,5 @@ --- matrixmailer_os_supported: False + +matrixmailer_git_repo: https://gitea.a-0.me/philip/matrixmailer.git +matrixmailer_git_branch: "release-{{ matrixmailer_version }}" \ No newline at end of file diff --git a/example_playbook_fromsource.yml b/example_playbook_fromsource.yml new file mode 100644 index 0000000..dcf9b96 --- /dev/null +++ b/example_playbook_fromsource.yml @@ -0,0 +1,9 @@ +- hosts: host.example.com + roles: + - matrixmailer + vars: + - matrixmailer_version: "0.1.0" + - matrixmailer_build: "from_source" + - matrixmailer_config: "{{ lookup("file", "path/to/config/file/template.yaml") }}" + # The following option can be left out to use the default git repository + - matrixmailer_git_repo: "https://git.myorg.com/user/matrixmailer.git" \ No newline at end of file diff --git a/example_playbook_prebuilt.yml b/example_playbook_prebuilt.yml new file mode 100644 index 0000000..bc28fed --- /dev/null +++ b/example_playbook_prebuilt.yml @@ -0,0 +1,7 @@ +- hosts: host.example.com + roles: + - matrixmailer + vars: + - matrixmailer_version: "0.1.0" + - matrixmailer_build: "x86_64-unknown-linux-musl" + - matrixmailer_config: "{{ lookup("file", "path/to/config/file/template.yaml") }}" \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 32c782f..efc0c84 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -20,10 +20,10 @@ vars: __os_supported: "{{ lookup('vars', '{}_os_supported'.format(role_name)) | bool }}" -- name: Assert matrixmailer version and system_spec are defined +- name: Assert matrixmailer version and build are defined assert: - that: matrixmailer_version is defined and matrixmailer_system_spec is defined and matrixmailer_config is defined - fail_msg: "The ansible variables 'matrixmailer_version', 'matrixmailer_system_spec' and 'matrixmailer_config' need to be set to run this role." + that: matrixmailer_version is defined and matrixmailer_build is defined and matrixmailer_config is defined + fail_msg: "The ansible variables 'matrixmailer_version', 'matrixmailer_build' and 'matrixmailer_config' need to be set to run this role." - name: Create matrixmailer group group: @@ -40,14 +40,49 @@ password_lock: yes state: present -- name: Download matrixmailer - become: yes - get_url: - url: "https://gitea.a-0.me/philip/matrixmailer/releases/download/{{ matrixmailer_version }}/{{ matrixmailer_system_spec }}" - dest: "{{ matrixmailer_binary_location }}" - owner: "{{ matrixmailer_system_user }}" - group: "{{ matrixmailer_system_group }}" - mode: 0500 +- name: Install matrixmailer from pre-built binary + block: + - name: Download matrixmailer + become: yes + get_url: + url: "https://gitea.a-0.me/philip/matrixmailer/releases/download/{{ matrixmailer_version }}/{{ matrixmailer_build }}" + dest: "{{ matrixmailer_binary_location }}" + owner: "{{ matrixmailer_system_user }}" + group: "{{ matrixmailer_system_group }}" + mode: 0500 + when: matrixmailer_build != "from_source" + +- name: Install matrixmailer custom-built from git repository + block: + - name: Clone repository + git: + repo: "{{ matrixmailer_git_repo }}" + depth: 1 + dest: "{{ matrixmailer_build_tmp }}" + version: "{{ matrixmailer_git_branch }}" + - name: Install required packages + apt: + pkg: + - libssl-dev + - pkg-config + - curl + state: present + - name: Install Rust + command: + cmd: "curl https://sh.rustup.rs -sSf | sh" + - name: Install matrixmailer + command: + cmd: cargo build --release + chdir: "{{ matrixmailer_build_tmp }}" + - name: Copy built binary to final location + copy: + remote_src: yes + src: "{{ matrixmailer_build_tmp }}"/release/matrixmailer + dest: "{{ matrixmailer_binary_location }}" + owner: "{{ matrixmailer_system_user }}" + group: "{{ matrixmailer_system_group }}" + mode: 0500 + when: matrixmailer_build == "from_source" - name: Create config file directory file: diff --git a/templates/matrixmailer.service.j2 b/templates/matrixmailer.service.j2 index d11b7c7..5547f5a 100644 --- a/templates/matrixmailer.service.j2 +++ b/templates/matrixmailer.service.j2 @@ -5,7 +5,7 @@ After=network.target [Service] Type=simple -ExecStart={{ matirxmailer_binary_location }} {{ matrixmailer_config_dir }}/config.yaml +ExecStart={{ matrixmailer_binary_location }} {{ matrixmailer_config_dir }}/config.yaml Restart=always RestartSec=1s User={{ matrixmailer_system_user }} diff --git a/vars/debian.yml b/vars/debian.yml index 738e1ab..51fffb2 100644 --- a/vars/debian.yml +++ b/vars/debian.yml @@ -1,7 +1,8 @@ --- matrixmailer_os_supported: True -matirxmailer_binary_location: /usr/bin/matrixmailer +matrixmailer_build_tmp: /tmp/matrixmailer +matrixmailer_binary_location: /usr/bin/matrixmailer matrixmailer_config_dir: /etc/matrixmailer matrixmailer_systemd_service_file: /etc/systemd/system/matrixmailer.service matrixmailer_system_user: matrixmailer