I am attempting to use the following chef recipe to download and install windows updates on a windows 2008 R2 machine in the Amazon cloud: https://github.com/dougm/site-cookbooks/blob/master/windows/recipes/update.rb.
I am using Chef 11.8.0 but the chef run fails with the following error:
Recipe Compile Error in c:/chef/cache/cookbooks/test/recipes/updates.rb
WIN32OLERuntimeError
(in OLE method `CreateUpdateDownloader': ) OLE error code:80070005 in HRESULT error code:0x80020009 Exception occurred.
Cookbook Trace:
c:/chef/cache/cookbooks/test/recipes/updates.rb:54:in method_missing'
c:/chef/cache/cookbooks/test/recipes/updates.rb:54:in
from_file'
Line 54: downloader = session.CreateUpdateDownloader.
Any ideas?
The error is coming from this line of code. The error is not related to Chef, but rather WIN32OLE
is raising that exception.
I would try running the code in an interactive Ruby (irb
) and see if you get a more helpful error.
Like sethvargo said, this is not directly a chef code issue. Both "code:80070005" and "error code 0x80020009" are permissions issues. Try confirming the user context that Chef is running on your Windows server. Is Chef installed and running as a service or are you triggering a chef-client execution?
#
# Cookbook Name:: InstallWindowsUpdates
# Recipe:: default
# Author(s):: A M
#
# Configures Windows Update automatic updates
powershell_script "install-windows-updates" do
guard_interpreter :powershell_script
# Set a 2 hour timeout
timeout 7200
code <<-EOH
Write-Host -ForegroundColor Green "Searching for updates (this may take up to 30 minutes or more)..."
$updateSession = New-Object -com Microsoft.Update.Session
$updateSearcher = $updateSession.CreateupdateSearcher()
try
{
$searchResult = $updateSearcher.Search("Type='Software' and IsHidden=0 and IsInstalled=0").Updates
}
catch
{
eventcreate /t ERROR /ID 1 /L APPLICATION /SO "Chef-Cookbook" /D "InstallWindowsUpdates: Update attempt failed."
$updateFailed = $true
}
if(!($updateFailed)) {
foreach ($updateItem in $searchResult) {
$UpdatesToDownload = New-Object -com Microsoft.Update.UpdateColl
if (!($updateItem.EulaAccepted)) {
$updateItem.AcceptEula()
}
$UpdatesToDownload.Add($updateItem)
$Downloader = $UpdateSession.CreateUpdateDownloader()
$Downloader.Updates = $UpdatesToDownload
$Downloader.Download()
$UpdatesToInstall = New-Object -com Microsoft.Update.UpdateColl
$UpdatesToInstall.Add($updateItem)
$Title = $updateItem.Title
Write-host -ForegroundColor Green " Installing Update: $Title"
$Installer = $UpdateSession.CreateUpdateInstaller()
$Installer.Updates = $UpdatesToInstall
$InstallationResult = $Installer.Install()
eventcreate /t INFORMATION /ID 1 /L APPLICATION /SO "Chef-Cookbook" /D "InstallWindowsUpdates: Installed update $Title."
}
if (!($searchResult.Count)) {
eventcreate /t INFORMATION /ID 999 /L APPLICATION /SO "Chef-Cookbook" /D "InstallWindowsUpdates: No updates available."
}
eventcreate /t INFORMATION /ID 1 /L APPLICATION /SO "Chef-Cookbook" /D "InstallWindowsUpdates: Done Installing Updates."
}
EOH
action :run
end
User contributions licensed under CC BY-SA 3.0