Skip to content

Commit

Permalink
Workaround broken OS patch KB2918614
Browse files Browse the repository at this point in the history
Remove puts

Removing incorrect quote character
  • Loading branch information
adamedx committed Oct 4, 2014
1 parent 569c267 commit a1206b3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
None.

## Latest release: 0.8.0
* [knife-windows #96](https://github.com/opscode/knife-windows/issues/96) Fix break from OS patch KB2918614
* Update winrm-s dependency along with em-winrm and winrm dependencies
* Return failure codes from knife winrm even when `returns` is not set
* Support Windows negotiate authentication protocol when running knife on Windows
Expand Down
50 changes: 49 additions & 1 deletion lib/chef/knife/core/windows_bootstrap_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def win_wget_ps
end

def install_chef
install_chef = 'msiexec /qn /log "%CHEF_CLIENT_MSI_LOG_PATH%" /i "%LOCAL_DESTINATION_MSI_PATH%"'
install_chef = install_command('"') + "\n" + fallback_install_task_command
end

def bootstrap_directory
Expand All @@ -171,6 +171,54 @@ def first_boot
def escape_and_echo(file_contents)
file_contents.gsub(/^(.*)$/, 'echo.\1').gsub(/([(<|>)^])/, '^\1')
end

private

def install_command(executor_quote)
"msiexec /qn /log #{executor_quote}%CHEF_CLIENT_MSI_LOG_PATH%#{executor_quote} /i #{executor_quote}%LOCAL_DESTINATION_MSI_PATH%#{executor_quote}"
end

def fallback_install_task_command
# This command will be executed by schtasks.exe in the batch
# code below. To handle tasks that contain arguments that
# need to be double quoted, schtasks allows the use of single
# quotes that will later be converted to double quotes
command = install_command('\'')
<<-EOH
@set MSIERRORCODE=!ERRORLEVEL!
@if ERRORLEVEL 1 (
@echo WARNING: Failed to install Chef Client MSI package in remote context with status code !MSIERRORCODE!.
@echo WARNING: This may be due to a defect in operating system update KB2918614: http://support.microsoft.com/kb/2918614
@set OLDLOGLOCATION="%CHEF_CLIENT_MSI_LOG_PATH%-fail.log"
@move "%CHEF_CLIENT_MSI_LOG_PATH%" "!OLDLOGLOCATION!" > NUL
@echo WARNING: Saving installation log of failure at !OLDLOGLOCATION!
@echo WARNING: Retrying installation with local context...
@schtasks /create /f /sc once /st 00:00:00 /tn chefclientbootstraptask /ru SYSTEM /rl HIGHEST /tr \"cmd /c #{command} & sleep 2 & waitfor /s %computername% /si chefclientinstalldone\"
@if ERRORLEVEL 1 (
@echo ERROR: Failed to create Chef Client installation scheduled task with status code !ERRORLEVEL! > "&2"
) else (
@echo Successfully created scheduled task to install Chef Client.
@schtasks /run /tn chefclientbootstraptask
@if ERRORLEVEL 1 (
@echo ERROR: Failed to execut Chef Client installation scheduled task with status code !ERRORLEVEL!. > "&2"
) else (
@echo Successfully started Chef Client installation scheduled task.
@echo Waiting for installation to complete -- this may take a few minutes...
waitfor chefclientinstalldone /t 600
if ERRORLEVEL 1 (
@echo ERROR: Timed out waiting for Chef Client package to install
) else (
@echo Finished waiting for Chef Client package to install.
)
@schtasks /delete /f /tn chefclientbootstraptask > NUL
)
)
) else (
@echo Successfully installed Chef Client package.
)
EOH
end
end
end
end
Expand Down

0 comments on commit a1206b3

Please sign in to comment.