Skip to content

Commit

Permalink
Add ssh to vagrant_init_destroy_boxes (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruzickap authored Oct 14, 2021
1 parent fc4cfc0 commit 98a6aee
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit 98a6aee

Please sign in to comment.