Skip to content

Commit 3bb1a0c

Browse files
testing
1 parent 018f8ff commit 3bb1a0c

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

scripts/sap_automation_qa.sh

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -237,31 +237,33 @@ run_ansible_playbook() {
237237
if [[ "$auth_type" == "SSHKEY" ]]; then
238238
log "INFO" "Authentication type is SSHKEY."
239239

240-
# Extract key_vault_id from sap-parameters.yaml
241-
key_vault_id=$(grep "^key_vault_id:" "$system_params" | awk '{split($0,a,": "); print a[2]}' | xargs)
242-
243240
local ssh_key="${cmd_dir}/../WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME/ssh_key.ppk"
244241
if [[ -f "$ssh_key" ]]; then
245242
log "INFO" "Local SSH key is present: $ssh_key. Skipping secret_name requirement."
246243
command="ansible-playbook ${cmd_dir}/../src/$playbook_name.yml -i $system_hosts --private-key $ssh_key \
247244
-e @$VARS_FILE -e @$system_params -e '_workspace_directory=$system_config_folder'"
248-
elif [[ -n "$key_vault_id" ]]; then
245+
else
246+
log "INFO" "Local SSH key not found. Retrieving SSH key from Key Vault."
247+
248+
# Extract key_vault_id only if needed
249+
key_vault_id=$(grep "^key_vault_id:" "$system_params" | awk '{split($0,a,": "); print a[2]}' | xargs)
249250
log "INFO" "Extracted key_vault_id: $key_vault_id"
250251

251-
# Extract Key Vault details and retrieve secret
252+
if [[ -z "$key_vault_id" ]]; then
253+
log "ERROR" "Error: key_vault_id is not defined in $system_params, and no local SSH key is present."
254+
exit 1
255+
fi
256+
252257
retrieve_secret_from_key_vault "$key_vault_id"
253258
if [[ -z "$secret_value" ]]; then
254259
log "ERROR" "Error: Secret value is not retrieved, and no local SSH key is present."
255260
exit 1
256-
else
257-
log "INFO" "Using Key Vault for SSH key retrieval."
258-
log "INFO" "Temporary SSH key file: $temp_file"
259-
command="ansible-playbook ${cmd_dir}/../src/$playbook_name.yml -i $system_hosts --private-key $temp_file \
260-
-e @$VARS_FILE -e @$system_params -e '_workspace_directory=$system_config_folder'"
261261
fi
262-
else
263-
log "ERROR" "Error: key_vault_id is not defined in $system_params, and no local SSH key is present."
264-
exit 1
262+
temp_file=$(mktemp --suffix=.ppk)
263+
echo "$secret_value" > "$temp_file"
264+
log "INFO" "Temporary SSH key file created: $temp_file"
265+
command="ansible-playbook ${cmd_dir}/../src/$playbook_name.yml -i $system_hosts --private-key $temp_file \
266+
-e @$VARS_FILE -e @$system_params -e '_workspace_directory=$system_config_folder'"
265267
fi
266268
elif [[ "$auth_type" == "VMPASSWORD" ]]; then
267269
local password_file="${cmd_dir}/../WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME/password"
@@ -272,6 +274,16 @@ run_ansible_playbook() {
272274
-e '_workspace_directory=$system_config_folder'"
273275
else
274276
log "INFO" "Local password file not found. Retrieving password from Key Vault."
277+
278+
# Extract key_vault_id only if needed
279+
key_vault_id=$(grep "^key_vault_id:" "$system_params" | awk '{split($0,a,": "); print a[2]}' | xargs)
280+
log "INFO" "Extracted key_vault_id: $key_vault_id"
281+
282+
if [[ -z "$key_vault_id" ]]; then
283+
log "ERROR" "Error: key_vault_id is not defined in $system_params, and no local password file is present."
284+
exit 1
285+
fi
286+
275287
temp_file=$(mktemp --suffix=.password)
276288
retrieve_secret_from_key_vault "$key_vault_id"
277289
echo "$secret_value" > "$temp_file"

0 commit comments

Comments
 (0)