@@ -240,37 +240,28 @@ run_ansible_playbook() {
240240 # Extract key_vault_id from sap-parameters.yaml
241241 key_vault_id=$( grep " ^key_vault_id:" " $system_params " | awk ' {split($0,a,": "); print a[2]}' | xargs)
242242
243- if [[ -z " $key_vault_id " ]]; then
244- local ssh_key=" ${cmd_dir} /../WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME /ssh_key.ppk"
245- if [[ -f " $ssh_key " ]]; then
246- log " INFO" " key_vault_id is not provided, but local SSH key is present: $ssh_key ."
247- command=" ansible-playbook ${cmd_dir} /../src/$playbook_name .yml -i $system_hosts --private-key $ssh_key \
248- -e @$VARS_FILE -e @$system_params -e '_workspace_directory=$system_config_folder '"
249- else
250- log " ERROR" " Error: key_vault_id is not defined in $system_params , and no local SSH key is present."
251- exit 1
252- fi
253- else
243+ local ssh_key=" ${cmd_dir} /../WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME /ssh_key.ppk"
244+ if [[ -f " $ssh_key " ]]; then
245+ log " INFO" " Local SSH key is present: $ssh_key . Skipping secret_name requirement."
246+ command=" ansible-playbook ${cmd_dir} /../src/$playbook_name .yml -i $system_hosts --private-key $ssh_key \
247+ -e @$VARS_FILE -e @$system_params -e '_workspace_directory=$system_config_folder '"
248+ elif [[ -n " $key_vault_id " ]]; then
254249 log " INFO" " Extracted key_vault_id: $key_vault_id "
255250
256251 # Extract Key Vault details and retrieve secret
257252 retrieve_secret_from_key_vault " $key_vault_id "
258253 if [[ -z " $secret_value " ]]; then
259- local ssh_key=" ${cmd_dir} /../WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME /ssh_key.ppk"
260- if [[ -f " $ssh_key " ]]; then
261- log " INFO" " Secret value is not retrieved, but local SSH key is present: $ssh_key ."
262- command=" ansible-playbook ${cmd_dir} /../src/$playbook_name .yml -i $system_hosts --private-key $ssh_key \
263- -e @$VARS_FILE -e @$system_params -e '_workspace_directory=$system_config_folder '"
264- else
265- log " ERROR" " Error: Secret value is not retrieved, and no local SSH key is present."
266- exit 1
267- fi
254+ log " ERROR" " Error: Secret value is not retrieved, and no local SSH key is present."
255+ exit 1
268256 else
269257 log " INFO" " Using Key Vault for SSH key retrieval."
270258 log " INFO" " Temporary SSH key file: $temp_file "
271259 command=" ansible-playbook ${cmd_dir} /../src/$playbook_name .yml -i $system_hosts --private-key $temp_file \
272260 -e @$VARS_FILE -e @$system_params -e '_workspace_directory=$system_config_folder '"
273261 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
274265 fi
275266 elif [[ " $auth_type " == " VMPASSWORD" ]]; then
276267 if [[ -z " $secret_value " ]]; then
@@ -340,21 +331,10 @@ main() {
340331 check_file_exists " $SYSTEM_PARAMS " \
341332 " sap-parameters.yaml not found in WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME directory."
342333
343- # log "INFO" "Checking if the SSH key or password file exists..."
344- # if [[ "$AUTHENTICATION_TYPE" == "SSHKEY" ]]; then
345- # check_file_exists "${cmd_dir}/../WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME/ssh_key.ppk" \
346- # "ssh_key.ppk not found in WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME directory."
347- # elif [[ "$AUTHENTICATION_TYPE" == "VMPASSWORD" ]]; then
348- # check_file_exists "${cmd_dir}/../WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME/password" \
349- # "password file not found in WORKSPACES/SYSTEM/$SYSTEM_CONFIG_NAME directory."
350- # elif [[ "$AUTHENTICATION_TYPE" == "KEYVAULT" ]]; then
351- # log "INFO" "Key Vault authentication selected. Ensure Key Vault parameters are set."
352- # fi
353-
354334 # Extract secret_name from sap-parameters.yaml
355335 secret_name=$( grep " ^secret_name:" " $SYSTEM_PARAMS " | awk ' {split($0,a,": "); print a[2]}' | xargs)
356336
357- if [[ -z " $secret_name " ]]; then
337+ if [[ -z " $secret_name " && " $AUTHENTICATION_TYPE " != " SSHKEY " ]]; then
358338 log " ERROR" " Error: secret_name is not defined in $SYSTEM_PARAMS ."
359339 exit 1
360340 fi
0 commit comments