Created
August 28, 2019 20:59
-
-
Save paul1994/c16c41e8303bb4e8db94543e5f6d8119 to your computer and use it in GitHub Desktop.
kitchen Stuff Hyperv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KITCHEN SETUP: | |
https://learn.chef.io/modules/local-development/windows/hyper-v/get-set-up#/ | |
1. Enabled Hyper-V (requires reboot) | |
a. Control Panel --> Programs and Features --> Turn Windows Features on or off | |
b. Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All | |
2. Downloaded and installed Git (already installed with ChefDK?) | |
*Not required for Kitchen | |
3. Downloaded and installed Vagrant (requires reboot) | |
4. Installed Vagrant winRm Plugin | |
vagrant plugin install vagrant-winrm | |
5. Install HyperV Plugin | |
chef gem install kitchen-hyperv | |
6. Create base HyperV VM | |
#Download the evaluation version of Windows Server 2012 R2 as an ISO http://download.microsoft.com/download/6/2/A/62A76ABB-9990-4EFC-A4FE-C7D698DAEB96/9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO | |
7. Create a Hyper-V virtual switch to provide your virtual machine with Internet access. | |
#Find the "Name of the Ethernet" adapter (usually Ethernet0 or Ethernet) | |
Get-NetAdapter | |
8. Create a variable for the Ethernet adapter | |
$net_adapter = Get-NetAdapter -Name Ethernet | |
9. Now run New-VMSwitch to create the virtual switch. You'll use the name of the switch, ExternalSwitch, in a later step when you create the base virtual machine. | |
New-VMSwitch -Name ExternalSwitch -NetAdapterName $net_adapter.Name -AllowManagementOS $True -Notes "Provide public network access to VMs" | |
*Should See Something Like..... | |
Name: SwitchType: NetAdapterInterfaceDescription: | |
ExternalSwitch External Intel(R) Ethernet Connection I219-LM | |
*Should also be able to see the switch in Hyper-V Manager | |
10. Create a location to store virtual machines. | |
mkdir C:\HyperV | |
11. Create an empty base virtual machine. This will setup both a 2012r2 and 2019 VM.....if you only want/need one or the other only run the $vm or $vm2 lines. | |
$vm = New-VM -Name WindowsServer2012R2 -MemoryStartupBytes 1GB -NewVHDPath "C:\HyperV\WindowsServer2012R2.vhdx" -NewVHDSizeBytes 30GB -Path "C:\HyperV" -SwitchName ExternalSwitch | |
$vm2 = New-VM -Name WindowsServer2019 -MemoryStartupBytes 1GB -NewVHDPath "C:\HyperV\WindowsServer2019.vhdx" -NewVHDSizeBytes 30GB -Path "C:\HyperV" -SwitchName ExternalSwitch | |
$vm | Add-VMDvdDrive -Path "C:\iso\9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO" | |
$vm2 | Add-VMDvdDrive -Path "C:\iso\SW_DVD9_Win_Server_STD_CORE_2019_64Bit_English_DC_STD_MLF_X21-96581.iso" | |
$vm | Set-VM -AutomaticStartAction StartIfRunning -AutomaticStopAction ShutDown | |
$vm2 | Set-VM -AutomaticStartAction StartIfRunning -AutomaticStopAction ShutDown | |
$vm | Start-VM | |
$vm2 | Start-VM | |
12. Connect to your virtual machine through Hyper-V Manager. | |
C:\Windows\System32\mmc.exe C:\Windows\System32\virtmgmt.msc | |
OR | |
Open Hyper-V as an admin | |
13. Install Windows Server 2012 R2 on your virtual machine. | |
Install the Standard Edition with GUI | |
Choose --> Custom: Install Windows only (advanced) | |
Login: Administrator/$erver@dmin1 | |
14. Configure the base VM | |
(i) Accept remote WinRM connections. | |
Get-NetFirewallPortFilter | ?{$_.LocalPort -eq 5985 } | Get-NetFirewallRule | ?{ $_.Direction -eq "Inbound" -and $_.Profile -eq "Public" -and $_.Action -eq "Allow"} | Set-NetFirewallRule -RemoteAddress "Any" | |
(ii) Make sure the time and time zone are correct --> will cause Certificate and connection errors if not. | |
15. Shut down your virtual machine. | |
16. Setup the .kitchen.yml file in the cookbook to test. | |
17. kitchen list | |
*Should show "not created" --> basically we just want to verify it doesn't throw any errors | |
18. kitchen create | |
*This will take a while to create. | |
19. kitchen converge | |
*This will apply the cookbook to the VM. It takes a while the first time because it needs to install the Chef client. | |
20. kitchen list | |
*Should now see "Last Action=Converged" and hopefully "Last error=<None>" | |
21. kitchen converge | |
*Should run test | |
22. kitchen verify <Instance_name> | |
*Runs any integration tests on the specified host | |
23. kitchen destroy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment