chef / knife-windows

Plugin for Chef's knife tool for working with Windows nodes
Apache License 2.0
152 stars 110 forks source link

bootstrap fails on windows 2012 #293

Closed mikkoc closed 7 years ago

mikkoc commented 9 years ago

Hello, using knife-windows 1.0.0.rc2 with validatorless setup.

Running into this issue:

DEBUG: 10.214.126.175[C6479B91-7BE0-42AB-84B4-08B361C90B2A] => :run_command[cmd.exe /C "%TEMP%\bootstrap-4542-1443710985.bat"]
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.Set objFSO = Nothing 
10.214.126.175 Set objFSO = Nothing
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.
10.214.126.175 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.Else
10.214.126.175 Else
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP") 
10.214.126.175 Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.Set wshShell = CreateObject( "WScript.Shell" ) 
10.214.126.175 Set wshShell = CreateObject( "WScript.Shell" )
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.Set objUserVariables = wshShell.Environment("USER") 
10.214.126.175 Set objUserVariables = wshShell.Environment("USER")
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.
10.214.126.175 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.rem http proxy is optional 
10.214.126.175 rem http proxy is optional
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.rem attempt to read from HTTP_PROXY env var first 
10.214.126.175 rem attempt to read from HTTP_PROXY env var first
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.On Error Resume Next 
10.214.126.175 On Error Resume Next
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.
10.214.126.175 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.If NOT (objUserVariables("HTTP_PROXY") = "") Then 
10.214.126.175 If NOT (objUserVariables("HTTP_PROXY") = "") Then
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.proxy = objUserVariables("HTTP_PROXY") 
10.214.126.175 proxy = objUserVariables("HTTP_PROXY")
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.
10.214.126.175 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.rem fall back to named arg 
10.214.126.175 rem fall back to named arg
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.ElseIf NOT (WScript.Arguments.Named("proxy") = "") Then 
10.214.126.175 ElseIf NOT (WScript.Arguments.Named("proxy") = "") Then
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.proxy = WScript.Arguments.Named("proxy") 
10.214.126.175 proxy = WScript.Arguments.Named("proxy")
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.End If 
10.214.126.175 End If
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.
10.214.126.175 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.If NOT isNull(proxy) Then 
10.214.126.175 If NOT isNull(proxy) Then
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.rem setProxy method is only available on ServerXMLHTTP 6.0+ 
10.214.126.175 rem setProxy method is only available on ServerXMLHTTP 6.0+
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0") 
10.214.126.175 Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.objXMLHTTP.setProxy 2, proxy 
10.214.126.175 objXMLHTTP.setProxy 2, proxy
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.End If 
10.214.126.175 End If
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.
10.214.126.175 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.On Error Goto 0 
10.214.126.175 On Error Goto 0
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.
10.214.126.175 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.objXMLHTTP.open "GET", url, false 
10.214.126.175 objXMLHTTP.open "GET", url, false
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.objXMLHTTP.send()
10.214.126.175 objXMLHTTP.send()
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.If objXMLHTTP.Status = 200 Then 
10.214.126.175 If objXMLHTTP.Status = 200 Then
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.Set objADOStream = CreateObject("ADODB.Stream") 
10.214.126.175 Set objADOStream = CreateObject("ADODB.Stream")
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.objADOStream.Open
10.214.126.175 objADOStream.Open
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.objADOStream.Type = 1 
10.214.126.175 objADOStream.Type = 1
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.objADOStream.Write objXMLHTTP.ResponseBody 
10.214.126.175 objADOStream.Write objXMLHTTP.ResponseBody
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.objADOStream.Position = 0 
10.214.126.175 objADOStream.Position = 0
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.Set objFSO = Createobject("Scripting.FileSystemObject") 
10.214.126.175 Set objFSO = Createobject("Scripting.FileSystemObject")
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.If objFSO.Fileexists(path) Then objFSO.DeleteFile path 
10.214.126.175 If objFSO.Fileexists(path) Then objFSO.DeleteFile path
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.Set objFSO = Nothing 
10.214.126.175 Set objFSO = Nothing
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.objADOStream.SaveToFile path 
10.214.126.175 objADOStream.SaveToFile path
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.objADOStream.Close
10.214.126.175 objADOStream.Close
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.Set objADOStream = Nothing 
10.214.126.175 Set objADOStream = Nothing
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.End If 
10.214.126.175 End If
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.Set objXMLHTTP = Nothing 
10.214.126.175 Set objXMLHTTP = Nothing
10.214.126.175 
10.214.126.175 C:\Users\Administrator>echo.End If 
10.214.126.175 End If
10.214.126.175 
10.214.126.175 C:\Users\Administrator>(
10.214.126.175 echo.param( 
10.214.126.175  echo.   [String] $remoteUrl,  
10.214.126.175  echo.   [String] $localPath  
10.214.126.175  echo.) 
10.214.126.175  echo. 
10.214.126.175  echo.$webClient = new-object System.Net.WebClient;  
10.214.126.175  echo. 
10.214.126.175  echo.$webClient.DownloadFile($remoteUrl, $localPath); 
10.214.126.175 ) 1>C:\chef\wget.ps1 
10.214.126.175 '!powershell_download!' is not recognized as an internal or external command,
10.214.126.175 operable program or batch file.
10.214.126.175 Failed PowerShell download with status code !DOWNLOAD_ERROR_STATUS! 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>(
10.214.126.175  
10.214.126.175   
10.214.126.175  
10.214.126.175 ) 
10.214.126.175 Detected Windows Version 6.3 Build 9600
10.214.126.175 
10.214.126.175 C:\Users\Administrator>goto Version6.3 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>goto Version6.2 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>goto architecture_select 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>goto Architecture 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>goto ArchitectureAMD64 
10.214.126.175 
10.214.126.175 C:\Users\Administrator>goto install 
10.214.126.175 Checking for existing downloaded package at "C:\Users\ADMINI~1\AppData\Local\Temp\chef-client-latest.msi"
10.214.126.175 No existing downloaded packages to delete.
10.214.126.175 Attempting to download client package using PowerShell if available...
10.214.126.175 !powershell_download!
10.214.126.175 Warning: Failed to download "https://www.chef.io/chef/download?p=windows&pv=2012&m=x86_64&DownloadContext=PowerShell&v=12" to "C:\Users\ADMINI~1\AppData\Local\Temp\chef-client-latest.msi"
10.214.126.175 Warning: Retrying download with cscript ...
10.214.126.175 Failed to download "https://www.chef.io/chef/download?p=windows&pv=2012&m=x86_64&DownloadContext=PowerShell&v=12" with status code !ERRORLEVEL!. 
10.214.126.175 Exiting without bootstrapping due to download failure. 
10.214.126.175 Input Error: Can not find script file "C:\chef\wget.vbs".
DEBUG: 10.214.126.175[C6479B91-7BE0-42AB-84B4-08B361C90B2A] => :command_cleanup[cmd.exe /C "%TEMP%\bootstrap-4542-1443710985.bat"]
DEBUG: 10.214.126.175[C6479B91-7BE0-42AB-84B4-08B361C90B2A] => :shell_close
ERROR: Bootstrap command returned 1

I nailed it down to this snippet of code:

@echo Attempting to download client package using PowerShell if available...
@set "REMOTE_SOURCE_MSI_URL=https://www.chef.io/chef/download?p=windows&pv=%MACHINE_OS%&m=%MACHINE_ARCH%&DownloadContext=PowerShell&v=12"
@set powershell_download=powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File  C:\chef\wget.ps1 "%REMOTE_SOURCE_MSI_URL%" "%LOCAL_DESTINATION_MSI_PATH%"
@echo !powershell_download!
@call !powershell_download!

In particular the last line fails to execute with:

'!powershell_download!' is not recognized as an internal or external command,

Executing the command directly works:

powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -File  C:\chef\wget.ps1 "%REMOTE_SOURCE_MSI_URL%" "%LOCAL_DESTINATION_MSI_PATH%"

Using Powershell 4.0:

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1
adamedx commented 9 years ago

@mikkoc I'm not able to repro. Is this a stock image, or has it been customized before running this command? One possibility is that cmd.exe command extensions to support "!" syntax aren't enabled for some reason. Do you have any configuration of that nature in place?

adamedx commented 9 years ago

Also, @mikkoc, does this reproduce for you using release 0.8.6?

adamedx commented 9 years ago

This does not seem to be a regression, I can repro a very similar failure with 0.8.6 if I set the following in the user profile of the user under which the bootstrap is running on the Windows node:

`HKCU\Software\Microsoft\Command Processor' 'EnableExtensions' to "0"

If I then set this value to 1, everything is fine. To work around the issue you're hitting, set this to back to "1" and see if it fixes things.

I've also validated that we can fix this if it is indeed your issue by forcing cmd.exe to run with cmd extensions enabled at the command line, so that's a fix we'll deliver soon.

mikkoc commented 9 years ago

@adamedx I switched back to 0.8.6 with validator key and the problem is fixed so I'm not sure what caused the issue in the first place. We are using custom Windows images, yes.

adamedx commented 9 years ago

@mikkoc, I would say the custom image at least explains why we're not seeing it elsewhere. What if you use 1.0 with a validator -- does it still happen then?

We'd like to get this working for you, but since we can't repro here, it would help if you can try a few things out:

mikkoc commented 9 years ago

I'm happy to say that I cannot reproduce it anymore, even with 1.0.0 and validator/validatorless setup! I checked those registry entries and they're all set to '1'. Feel free to close this issue. I think it got messed up when I copied the knife-windows-1.0.0.rc2 directory into the chefDK embedded gems directory, replacing the one that came with chefDK.

adamedx commented 9 years ago

Thank you for the response @mikkoc. Now that is very mysterious. :) Yes, copying the gem over could have caused some strange issues actually. I'm going to keep this open a little while longer because you did actually expose an issue where we can't bootstrap systems with command extensions disabled. That's unlikely to ever be set of course, but we might as well protect against it. So we'll close once we merge that fix.

@mikkoc, thank you for testing out the RC for 1.0 -- glad you're getting some use out of the new features!

cpkatragadda commented 8 years ago

Hello, I am also getting same issue on 2008R2 can you help me to resolve issue?

Thanks capture capture1

cheeseplus commented 7 years ago

@cpkatragadda that issue is actually a different one entirely - as the node doesn't seem to have powershell.exe in the path or installed which will present a huge problem if trying to use knife-winrm. Given the age and the fact the originally reported issue was resolved I'm closing this one out but feel free to open a new one if still having trouble