Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vagrant ssh key to Windows #338

Merged
merged 1 commit into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions ansible/win-simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
- name: Enable Firewall for OpenSSH
win_shell: New-NetFirewallRule -DisplayName "ssh" -Direction Inbound -Action Allow -Protocol "TCP" -LocalPort "22"

- name: Add Vagrant key
win_get_url:
url: https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub
dest: "%PROGRAMDATA%\\ssh\\administrators_authorized_keys"

- name: Unzip downloaded BleachBit
win_unzip:
src: "%HOMEDRIVE%\\BleachBit-portable.zip"
Expand Down
4 changes: 2 additions & 2 deletions my_windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"vm_name": "{{ user `name` }}",
"winrm_insecure": "true",
"winrm_password": "{{ user `winrm_password` }}",
"winrm_timeout": "30m",
"winrm_timeout": "40m",
"winrm_use_ssl": "true",
"winrm_username": "{{ user `winrm_username` }}"
},
Expand Down Expand Up @@ -74,7 +74,7 @@
"vm_name": "{{ user `name` }}",
"winrm_insecure": "true",
"winrm_password": "{{ user `winrm_password` }}",
"winrm_timeout": "30m",
"winrm_timeout": "40m",
"winrm_use_ssl": "true",
"winrm_username": "{{ user `winrm_username` }}"
}
Expand Down
26 changes: 10 additions & 16 deletions vagrant_init_destroy_boxes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ check_vagrant_vm() {
*windows* )
sleep 100

echo '*** Running: Certificate "Red Hat" or "Oracle" driver check'
TRUSTED_CERTIFICATES=$(vagrant winrm --shell powershell --command "Get-ChildItem -Path Cert:\LocalMachine\TrustedPublisher" | uniq)
if [[ ! ${TRUSTED_CERTIFICATES} =~ (Red Hat|Oracle) ]]; then
echo "${TRUSTED_CERTIFICATES}"
Expand All @@ -38,13 +39,7 @@ 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

echo '*** Running: "QEMU" or "Virtualbox" driver check'
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 All @@ -53,6 +48,7 @@ check_vagrant_vm() {
exit 2
fi

echo '*** Running: "Red Hat" and "VirtIO" driver check'
if [[ ${VAGRANT_BOX_FILE} =~ "libvirt" ]]; then
VIRT_DEVICES=$(vagrant winrm --shell powershell --command "Get-WmiObject Win32_PnPSignedDriver | where {\$_.devicename -match \".*Red Hat.*|.*VirtIO.*\"} | select devicename, driverversion" | uniq)
if [[ ! ${VIRT_DEVICES} =~ (Red Hat|VirtIO) ]]; then
Expand All @@ -63,6 +59,7 @@ check_vagrant_vm() {
fi
fi

echo '*** Running: Windows version check'
WIN_VERSION=$(vagrant winrm --shell cmd --command 'systeminfo | findstr /B /C:"OS Name" /C:"OS Version"')
if [[ ! ${VAGRANT_BOX_FILE} =~ $(echo "${WIN_VERSION}" | awk '/^OS Name/ { print tolower($4 "-" $5 "-" $6) }') ]]; then
echo "${WIN_VERSION}"
Expand All @@ -71,6 +68,7 @@ check_vagrant_vm() {
exit 4
fi

echo '*** Running: Windows license check'
LICENSE_STATUS=$(vagrant winrm --shell cmd --command "cscript C:\Windows\System32\slmgr.vbs /dli" | uniq)
if [[ ! ${LICENSE_STATUS} =~ (10|90|180)\ day ]]; then
echo "${LICENSE_STATUS}"
Expand All @@ -80,22 +78,18 @@ check_vagrant_vm() {
fi
;;
*centos* | *ubuntu* )
echo "*** Checking if there are some packages to upgrade (there should be none)"
echo '*** Checking if there are some packages to upgrade (there should be none)'
vagrant ssh --command '
grep PRETTY_NAME /etc/os-release;
sudo sh -c "test -x /usr/bin/apt && apt-get update 2>&1 > /dev/null && echo \"apt list -qq --upgradable\" && apt list -qq --upgradable";
sudo sh -c "test -x /usr/bin/yum && yum list -q updates";
id;
id; sudo id
'
echo "*** vagrant ssh test completed..."
if [[ "${VAGRANT_BOX_PROVIDER}" != "virtualbox" ]]; then
echo "*** Running: sshpass"
set -x
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
;;
esac

echo '*** Running: sshpass'
sshpass -pvagrant ssh -q -F "${VAGRANT_CWD}/ssh-config" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ControlMaster=no -o PreferredAuthentications=password -o PubkeyAuthentication=no default 'cd'
}

vagrant_cleanup() {
Expand Down
4 changes: 2 additions & 2 deletions windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"vm_name": "{{ user `name` }}",
"winrm_insecure": "true",
"winrm_password": "{{ user `winrm_password` }}",
"winrm_timeout": "30m",
"winrm_timeout": "40m",
"winrm_use_ssl": "true",
"winrm_username": "{{ user `winrm_username` }}"
},
Expand Down Expand Up @@ -78,7 +78,7 @@
"vm_name": "{{ user `name` }}",
"winrm_insecure": "true",
"winrm_password": "{{ user `winrm_password` }}",
"winrm_timeout": "30m",
"winrm_timeout": "40m",
"winrm_use_ssl": "true",
"winrm_username": "{{ user `winrm_username` }}"
}
Expand Down