Skip to content

Commit 3ad3440

Browse files
committed
Preload known_hosts in the jumpbox
1 parent b1cf7f4 commit 3ad3440

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ansible/deploy-api-from-local.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ echo "[3/4] Uploading systemd template..."
3434
ssh -i "${SSH_KEY_LOCAL}" "${JUMP_USER}@${JUMP_HOST}" "mkdir -p ${REMOTE_DIR}/templates"
3535
scp -i "${SSH_KEY_LOCAL}" "${TEMPLATE_LOCAL}" "${JUMP_USER}@${JUMP_HOST}:${TEMPLATE_REMOTE}"
3636

37+
# === STEP 3.5: Preload known_hosts in the jumpbox to avoid host key verification ===
38+
echo "[3.5/4] Adding backend VM keys to known_hosts on the jumpbox..."
39+
ssh -i "${SSH_KEY_LOCAL}" "${JUMP_USER}@${JUMP_HOST}" bash <<'EOF'
40+
set -e
41+
# Parse inventory to get IPs and add them to known_hosts
42+
for ip in $(grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' inventory.ini); do
43+
ssh-keyscan -H "$ip" >> ~/.ssh/known_hosts 2>/dev/null || true
44+
done
45+
EOF
46+
3747
# === STEP 4: Execute playbook remotely ===
3848
echo "[4/4] Executing playbook from the jump host..."
3949
ssh -i "${SSH_KEY_LOCAL}" "${JUMP_USER}@${JUMP_HOST}" << EOF

0 commit comments

Comments
 (0)