From e60d20dc6a6ca11efb58ba8993e307e0912a164e Mon Sep 17 00:00:00 2001 From: Julian Foad Date: Mon, 4 Jul 2022 21:30:29 +0100 Subject: [PATCH] matrix-ntfy: store settings in a config file --- docs/configuring-playbook-ntfy.md | 5 ++-- roles/matrix-ntfy/defaults/main.yml | 23 +++++++++++++++++++ roles/matrix-ntfy/tasks/setup_install.yml | 9 ++++++++ .../matrix-ntfy/templates/ntfy/server.yml.j2 | 3 +++ .../templates/systemd/matrix-ntfy.service.j2 | 5 ++-- 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 roles/matrix-ntfy/templates/ntfy/server.yml.j2 diff --git a/docs/configuring-playbook-ntfy.md b/docs/configuring-playbook-ntfy.md index 03684b9c..56c859f3 100644 --- a/docs/configuring-playbook-ntfy.md +++ b/docs/configuring-playbook-ntfy.md @@ -19,12 +19,13 @@ matrix_ntfy_enabled: true # Some other options matrix_server_fqn_ntfy: "ntfy.{{ matrix_domain }}" -matrix_ntfy_container_extra_arguments: [ '--env=NTFY_LOG_LEVEL=DEBUG' ] +matrix_ntfy_configuration_extension_yaml: | + log_level: DEBUG ``` For a more complete list of variables that you could override, see `roles/matrix-ntfy/defaults/main.yml`. -For a complete list of ntfy config options that you could put in `matrix_ntfy_container_extra_arguments`, see the [ntfy config documentation](https://ntfy.sh/docs/config/#config-options). +For a complete list of ntfy config options that you could put in `matrix_ntfy_configuration_extension_yaml`, see the [ntfy config documentation](https://ntfy.sh/docs/config/#config-options). ## Installing diff --git a/roles/matrix-ntfy/defaults/main.yml b/roles/matrix-ntfy/defaults/main.yml index 6c540beb..4f0e2e55 100644 --- a/roles/matrix-ntfy/defaults/main.yml +++ b/roles/matrix-ntfy/defaults/main.yml @@ -2,6 +2,7 @@ matrix_ntfy_enabled: true matrix_ntfy_base_path: "{{ matrix_base_data_path }}/ntfy" +matrix_ntfy_config_dir_path: "{{ matrix_ntfy_base_path }}/config" matrix_ntfy_data_path: "{{ matrix_ntfy_base_path }}/data" matrix_ntfy_version: v1.27.2 @@ -21,3 +22,25 @@ matrix_ntfy_container_extra_arguments: [] # Controls whether the self-check feature should validate SSL certificates. matrix_ntfy_self_check_validate_certificates: true + +# Default ntfy configuration template which covers the generic use case. +# You can customize it by controlling the various variables inside it. +# +# For a more advanced customization, you can extend the default (see `matrix_ntfy_configuration_extension_yaml`) +# or completely replace this variable with your own template. +matrix_ntfy_configuration_yaml: "{{ lookup('template', 'templates/ntfy/server.yml.j2') }}" + +matrix_ntfy_configuration_extension_yaml: | + # Your custom YAML configuration for ntfy goes here. + # This configuration extends the default starting configuration (`matrix_ntfy_configuration_yaml`). + # + # You can override individual variables from the default configuration, or introduce new ones. + # + # If you need something more special, you can take full control by + # completely redefining `matrix_ntfy_configuration_yaml`. + +matrix_ntfy_configuration_extension: "{{ matrix_ntfy_configuration_extension_yaml|from_yaml if matrix_ntfy_configuration_extension_yaml|from_yaml is mapping else {} }}" + +# Holds the final ntfy configuration (a combination of the default and its extension). +# You most likely don't need to touch this variable. Instead, see `matrix_ntfy_configuration_yaml`. +matrix_ntfy_configuration: "{{ matrix_ntfy_configuration_yaml|from_yaml|combine(matrix_ntfy_configuration_extension, recursive=True) }}" diff --git a/roles/matrix-ntfy/tasks/setup_install.yml b/roles/matrix-ntfy/tasks/setup_install.yml index b674d320..461d3176 100644 --- a/roles/matrix-ntfy/tasks/setup_install.yml +++ b/roles/matrix-ntfy/tasks/setup_install.yml @@ -20,8 +20,17 @@ group: "{{ matrix_user_groupname }}" with_items: - "{{ matrix_ntfy_base_path }}" + - "{{ matrix_ntfy_config_dir_path }}" - "{{ matrix_ntfy_data_path }}" +- name: Ensure matrix-ntfy config installed + copy: + content: "{{ matrix_ntfy_configuration|to_nice_yaml(indent=2, width=999999) }}" + dest: "{{ matrix_ntfy_config_dir_path }}/server.yml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + - name: Ensure matrix-ntfy.service installed template: src: "{{ role_path }}/templates/systemd/matrix-ntfy.service.j2" diff --git a/roles/matrix-ntfy/templates/ntfy/server.yml.j2 b/roles/matrix-ntfy/templates/ntfy/server.yml.j2 new file mode 100644 index 00000000..4cafcd62 --- /dev/null +++ b/roles/matrix-ntfy/templates/ntfy/server.yml.j2 @@ -0,0 +1,3 @@ +base_url: {{ matrix_ntfy_base_url }} +behind_proxy: true +cache_file: /data/cache.db diff --git a/roles/matrix-ntfy/templates/systemd/matrix-ntfy.service.j2 b/roles/matrix-ntfy/templates/systemd/matrix-ntfy.service.j2 index 5bb28470..da292e5c 100644 --- a/roles/matrix-ntfy/templates/systemd/matrix-ntfy.service.j2 +++ b/roles/matrix-ntfy/templates/systemd/matrix-ntfy.service.j2 @@ -23,11 +23,10 @@ ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-ntfy \ {% if matrix_ntfy_container_http_host_bind_port %} -p {{ matrix_ntfy_container_http_host_bind_port }}:80 \ {% endif %} + --mount type=bind,src={{ matrix_ntfy_config_dir_path }},dst=/etc/ntfy,ro \ --mount type=bind,src={{ matrix_ntfy_data_path }},dst=/data \ - --env NTFY_CACHE_FILE=/data/cache.db \ - --env NTFY_BASE_URL={{ matrix_ntfy_base_url }} \ {{ matrix_ntfy_docker_image }} \ - serve --behind-proxy + serve ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-ntfy 2>/dev/null || true' ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-ntfy 2>/dev/null || true'