From 982522ca8eea2a669c69711c473d2504d3168d5d Mon Sep 17 00:00:00 2001 From: phil Date: Tue, 4 Jul 2023 22:20:14 +0200 Subject: [PATCH] Define plugin list --- defaults/main.yml | 3 +++ tasks/main.yml | 5 +++-- templates/update-opensearch-plugins.j2 | 21 ++++++++++++--------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index f4c8f67..1161e6b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -5,3 +5,6 @@ opensearch_network_host: 127.0.0.1 opensearch_http_port: 9200 opensearch_plugin_update_script: update-opensearch-plugins opensearch_monit_service: opensearch + +opensearch_plugins: + - ingest-attachment diff --git a/tasks/main.yml b/tasks/main.yml index 4f5d48c..486c333 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,11 +14,12 @@ - name: "Opensearch | Install plugins" ansible.builtin.command: - cmd: ./opensearch-plugin install ingest-attachment --batch + cmd: "./opensearch-plugin install {{ item }} --batch" chdir: /usr/share/opensearch/bin/ - creates: /usr/share/opensearch/plugins/ingest-attachment + creates: "/usr/share/opensearch/plugins/{{ item }}" become: true become_user: opensearch + loop: "{{ opensearch_plugins }}" - name: "Opensearch | Copy opensearch configuration" ansible.builtin.template: diff --git a/templates/update-opensearch-plugins.j2 b/templates/update-opensearch-plugins.j2 index b39f16d..3a0b7ac 100644 --- a/templates/update-opensearch-plugins.j2 +++ b/templates/update-opensearch-plugins.j2 @@ -5,20 +5,23 @@ set -eu OPENSEARCH_BIN_PATH=/usr/share/opensearch/bin OPENSEARCH_SERVICE=opensearch.service +PLUGINS=( +{% for plugin in opensearch_plugins %} +{% if not loop.last %} + {{ plugin }} +{% else %} + {{ plugin }}) +{% endif %} +{% endfor %} ACTION="${1:-help}" case "$ACTION" in purge) - PLUGINS=$($OPENSEARCH_BIN_PATH/opensearch-plugin list | grep -v opensearch- || true) - if [[ -z "$PLUGINS" ]]; then - exit 0 - else - for plugin in "${PLUGINS[@]}"; do - $OPENSEARCH_BIN_PATH/opensearch-plugin remove $plugin - done - systemctl restart $OPENSEARCH_SERVICE - fi + for plugin in "${PLUGINS[@]}"; do + $OPENSEARCH_BIN_PATH/opensearch-plugin remove $plugin + done + systemctl restart $OPENSEARCH_SERVICE ;; install) for plugin in "${PLUGINS[@]}"; do