Alex Vinyar, from then Opscode, now Chef, provided me with a custom library file that I have used since up until it was added to chef on, I believe, in version 11.12 of the Chef Client.
All I had to do was make sure you include windows::reboot_handler first in the nodes run list or role.
Then include a not_if {reboot_pending?} on your recipes and on the windows_reboot section add a only_if {reboot_pending?}.
Here are couple of examples
Both of these are for deploying RDSH for some Citrix XenApp servers. These are different recipes from the same cookbook.
I do have the custom library file in this cookbook
library/reboot_pending.rb
class Chef
class Resource
# include Chef::Mixin::ShellOut
def reboot_pending?
# Any files listed here means reboot needed
(Registry.key_exists?('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations') &&
Registry.get_value('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager','PendingFileRenameOperations').any?) ||
# 1 for any value means reboot pending
# "9306cdfc-c4a1-4a22-9996-848cb67eddc3"=1
(Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') &&
Registry.get_values('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired').select{|v| v[2] == 1 }.any?) ||
# 1 or 2 for 'Flags' value means reboot pending
(Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile') &&
[1,2].include?(Registry::get_value('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile','Flags'))) ||
# added by Alex
Registry.key_exists?('HKLM\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending')
end
end
end
w2k8r2.rb - Using powershell code I have found its easier to split them up.
# install RDS
powershell node['w2k8']['rds'] do
code <<-eoh p=""> Import-Module ServerManager
Add-WindowsFeature RDS-RD-Server
EOH
not_if {reboot_pending?}
end
# Install desktop experience
powershell node['w2k8']['deskexp'] do
code <<-eoh p=""> Import-Module ServerManager
Add-WindowsFeature Desktop-Experience
EOH
not_if {reboot_pending?}
end
powershell node['w2k8']['xps'] do
code <<-eoh p=""> Import-Module ServerManager
Add-WindowsFeature XPS-Viewer
EOH
not_if {reboot_pending?}
end
windows_reboot 30 do
reason 'Chef said to'
only_if {reboot_pending?}
end
w2012r2.rb
%w{ Xps-Foundation-Xps-Viewer Remote-Desktop-Services ServerMediaFoundation AppServer DesktopExperience }.each do |feature|
windows_feature feature do
action :install
not_if {reboot_pending?}
end
end
windows_reboot 30 do
reason 'Chef said to'
only_if {reboot_pending?}
end
Per the latest windows cookbook :
-eoh>-eoh>-eoh>
Attributes
node['windows']['allow_pending_reboots']
- used to configure theWindowsRebootHandler
(via thewindows::reboot_handler
recipe) to act on pending reboots. default is true (ie act on pending reboots). The value of this attribute only has an effect if thewindows::reboot_handler
is in a node's run list.
No comments:
Post a Comment