I’m an idiot! Now that that’s out of the way I wanted to share my bone-headed mistake with all of you so you don’t waste a couple hours like I did today.
I created a new cookbook today (tests first of course!) and wanted to run kitchen to spin up a VM and run my Pester tests but immediately received the following error:
> kitchen create
—–> Starting Kitchen (v1.15.0)
—–> Creating <default-w2008r2>…
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>> Failed to complete #create action: [Failed to find a default VM Switch.] on default-w2008r2
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose –all` for configuration
First, I deleted and recreated my HyperV virtual switch. No change.
Next I updated kitchen-hyperv from 0.3.0 to 0.4.1. No change
Then I updated to ChefDK to 1.4.3. No change.
Finally, I found the source for kitchen-hyperv and after some research realized I didn’t have access to get the VM switches because I was running the command in a non-Admin console window. IDIOT!
What did I learn?
Mistakes are only a waste if you don’t learn from them and improve!
First, I should always blog about errors/fixes, no matter how trivial, so I can google them later and find them. I’m pretty sure I’ve seen this one before and just forgot.
Second, all the Chef/Kitchen source is on Github and searchable. “Most” code isn’t magic. Dig in and find the underlying calls. In this case, the Get-VMSwitch PowerShell cmdlet is being called to get the list of virtual switches from HyperV and requires admin rights.
Third, running as Admin should always be the second default fix after rebooting!
Hopefully others will search for this error, find this page and save some time. If so, PLEASE write a comment below to help me save some dignity in knowing I’m not the only one who struggles with the simple stuff. Thanks!