From 50bd121e3d38dacd3519808505bff536cfc1a4d3 Mon Sep 17 00:00:00 2001 From: Todd Malsbary Date: Fri, 4 Mar 2022 16:31:30 -0800 Subject: [PATCH] Make .ssh/config changes idempotent Signed-off-by: Todd Malsbary Change-Id: Ifb850284882e2db0be8eea7a3982744e98dc7ddc --- deploy/site/vm/vm.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deploy/site/vm/vm.sh b/deploy/site/vm/vm.sh index 51ad4c9..8d65df7 100755 --- a/deploy/site/vm/vm.sh +++ b/deploy/site/vm/vm.sh @@ -84,7 +84,7 @@ function insert_control_plane_network_identity_into_ssh_config { prefix=$(helm -n ${SITE_NAMESPACE} get values -a cluster-icn | awk '/controlPlanePrefix:/ {print $2}') host=$(ipcalc ${endpoint}/${prefix} | awk '/Network:/ {sub(/\.0.*/,".*"); print $2}') if [[ $(grep -c "Host ${host}" ${HOME}/.ssh/config) != 0 ]]; then - sed -i -e '/Host '"${host}"'/,+1 d' ${HOME}/.ssh/config + sed -i -e '/Host '"${host}"'/,+3 d' ${HOME}/.ssh/config fi cat <>${HOME}/.ssh/config Host ${host} @@ -94,6 +94,8 @@ Host ${host} EOF # Add the identity to authorized keys on this host to enable ssh # logins via its control plane address + authorized_key=$(cat ${SCRIPTDIR}/id_rsa.pub) + sed -i -e '\!'"${authorized_key}"'!d' ${HOME}/.ssh/authorized_keys cat ${SCRIPTDIR}/id_rsa.pub >> ~/.ssh/authorized_keys } -- 2.16.6