Sachin,
make sure that the 'windows::reboot_handler 'is at the top of your run list as well as putting ('depends 'windows') in your metadata.rb.
The install what you want and Chef will reboot and continue.
here is an example of installing RDSH for preparation for Citrix XenApp install. It will starts the RDSH, reboot and then come back and do the desktop experience, and so on.... As long as you installed the chef service during client install or created a scheduled task.
# install RDS
powershell node['w2k8']['rds'] do
code <<-EOH
Import-Module ServerManager
Add-WindowsFeature RDS-RD-Server
EOH
not_if {reboot_pending?}
end
# Install desktop experience
powershell node['w2k8']['deskexp'] do
code <<-EOH
Import-Module ServerManager
Add-WindowsFeature Desktop-Experience
EOH
not_if {reboot_pending?}
end
powershell node['w2k8']['xps'] do
code <<-EOH
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
if you still have issues, create a library file called reboot_pending.rb in you cookbook - I was given this by Alex Vinyar from Chef. This was added to Chef Client back in version 11.12...But I still use it
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