Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Add ssh to vagrant_init_destroy_boxes #335

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions vagrant_init_destroy_boxes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ vagrant_init_up() {
}

check_vagrant_vm() {
VAGRANT_VM_IP=$(vagrant ssh-config | awk '/HostName/ { print $2 }')
vagrant ssh-config | head -5 > "${VAGRANT_CWD}/ssh-config"

case ${VAGRANT_BOX_FILE} in
*windows* )
Expand All @@ -38,6 +38,13 @@ check_vagrant_vm() {
exit 1
fi

SSH_TEST=$(sshpass -pvagrant ssh -q -F "${VAGRANT_CWD}/ssh-config" -o StrictHostKeyChecking=no -o ControlMaster=no -o PreferredAuthentications=password -o PubkeyAuthentication=no default 'dir .vbox_version')
if [[ ! ${SSH_TEST} =~ "vbox_version" ]]; then
echo "*** There is some SSH error when accessing the box using login/password !"
vagrant_cleanup
exit 1
fi

VIRT_SERVICES=$(vagrant winrm --shell powershell --command "Get-Service | where {\$_.Name -match \".*QEMU.*|.*Spice.*|.*vdservice.*|.*VBoxService.*\"}" | uniq)
if [[ ! ${VIRT_SERVICES} =~ (QEMU|Spice|vdservice|VBoxService) ]]; then
echo "${VIRT_SERVICES}"
Expand Down Expand Up @@ -84,7 +91,7 @@ check_vagrant_vm() {
if [[ "${VAGRANT_BOX_PROVIDER}" != "virtualbox" ]]; then
echo "*** Running: sshpass"
set -x
sshpass -pvagrant ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ControlMaster=no -o PreferredAuthentications=password -o PubkeyAuthentication=no "vagrant@${VAGRANT_VM_IP}" 'id; sudo id'
sshpass -pvagrant ssh -F "${VAGRANT_CWD}/ssh-config" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ControlMaster=no -o PreferredAuthentications=password -o PubkeyAuthentication=no default 'id; sudo id'
echo "*** sshpass test completed..."
fi
;;
Expand All @@ -99,7 +106,7 @@ vagrant_cleanup() {
virsh --quiet --connect=qemu:///system vol-delete --pool default --vol "${VAGRANT_BOX_NAME}_vagrant_box_image_0.img"
fi

rm -rf "${VAGRANT_CWD}"/{Vagrantfile,.vagrant}
rm -rf "${VAGRANT_CWD}"/{Vagrantfile,.vagrant,ssh-config}
rmdir "${VAGRANT_CWD}"
}

Expand Down