From f588a80ec71d0b38f74858360714668fd7c29a6b Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Tue, 16 Sep 2025 10:37:26 -0500 Subject: [PATCH] fix jq error when indices don't exist (seen on fresh installs when fleet hasn't ever been installed) --- .../tools/sbin_jinja/so-elastic-fleet-setup | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-setup b/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-setup index deb16dadf..1ceec9c95 100755 --- a/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-setup +++ b/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-setup @@ -23,18 +23,17 @@ if [[ "$RETURN_CODE" != "0" ]]; then exit 1 fi -ALIASES=".fleet-servers .fleet-policies-leader .fleet-policies .fleet-agents .fleet-artifacts .fleet-enrollment-api-keys .kibana_ingest" -for ALIAS in ${ALIASES} -do +ALIASES=(.fleet-servers .fleet-policies-leader .fleet-policies .fleet-agents .fleet-artifacts .fleet-enrollment-api-keys .kibana_ingest) +for ALIAS in "${ALIASES[@]}"; do # Get all concrete indices from alias - INDXS=$(curl -K /opt/so/conf/kibana/curl.config -s -k -L -H "Content-Type: application/json" "https://localhost:9200/_resolve/index/${ALIAS}" | jq -r '.aliases[].indices[]') - - # Delete all resolved indices - for INDX in ${INDXS} - do + if INDXS_RAW=$(curl -sK /opt/so/conf/kibana/curl.config -s -k -L -H "Content-Type: application/json" "https://localhost:9200/_resolve/index/${ALIAS}" --fail 2>/dev/null); then + INDXS=$(echo "$INDXS_RAW" | jq -r '.aliases[].indices[]') + # Delete all resolved indices + for INDX in ${INDXS}; do status "Deleting $INDX" curl -K /opt/so/conf/kibana/curl.config -s -k -L -H "Content-Type: application/json" "https://localhost:9200/${INDX}" -XDELETE - done + done + fi done # Restarting Kibana...