Use the reboot resource to reboot a node, a necessary step with some installations on certain platforms. This resource is supported for use on the Microsoft Windows, Mac OS X, and Linux platforms.
A reboot resource block reboots a node:
reboot 'app_requires_reboot' do action :request_reboot reason 'Need to reboot when the run completes successfully.' delay_mins 5 end
The full syntax for all of the properties that are available to the reboot resource is:
reboot 'name' do delay_mins Fixnum notifies # see description reason String subscribes # see description action Symbol end
where
reboot
is the resourcename
is the name of the resource block:action
identifies the steps the chef-client will take to bring the node into the desired statedelay_mins
and reason
are properties of this resource, with the Ruby type shown. See “Properties” section below for more information about all of the properties that may be used with this resource.This resource has the following actions:
:cancel
:nothing
:reboot_now
:request_reboot
This resource has the following properties:
delay_mins
Ruby Type: Fixnum
The amount of time (in minutes) to delay a reboot request.
ignore_failure
Ruby Types: TrueClass, FalseClass
Continue running a recipe if a resource fails for any reason. Default value: false
.
notifies
Ruby Type: Symbol, ‘Chef::Resource[String]’
A resource may notify another resource to take action when its state changes. Specify a 'resource[name]'
, the :action
that resource should take, and then the :timer
for that action. A resource may notifiy more than one resource; use a notifies
statement for each resource to be notified.
A timer specifies the point during the chef-client run at which a notification is run. The following timer is available:
:immediate
, :immediately
reason
Ruby Type: String
A string that describes the reboot action.
retries
Ruby Type: Integer
The number of times to catch exceptions and retry the resource. Default value: 0
.
retry_delay
Ruby Type: Integer
The retry delay (in seconds). Default value: 2
.
subscribes
Ruby Type: Symbol, ‘Chef::Resource[String]’
A resource may listen to another resource, and then take action if the state of the resource being listened to changes. Specify a 'resource[name]'
, the :action
to be taken, and then the :timer
for that action.
A timer specifies the point during the chef-client run at which a notification is run. The following timer is available:
:immediate
, :immediately
The following examples demonstrate various approaches for using resources in recipes. If you want to see examples of how Chef uses resources in recipes, take a closer look at the cookbooks that Chef authors and maintains: https://github.com/chef-cookbooks.
Reboot a node immediately
reboot 'now' do action :nothing reason 'Cannot continue Chef run without a reboot.' delay_mins 2 end execute 'foo' do command '...' notifies :reboot_now, 'reboot[now]', :immediately end
Reboot a node at the end of a chef-client run
reboot 'app_requires_reboot' do action :request_reboot reason 'Need to reboot when the run completes successfully.' delay_mins 5 end
Cancel a reboot
reboot 'cancel_reboot_request' do action :cancel reason 'Cancel a previous end-of-run reboot request.' end
Rename computer, join domain, reboot
The following example shows how to rename a computer, join a domain, and then reboot the computer:
reboot 'Restart Computer' do action :nothing end powershell_script 'Rename and Join Domain' do code <<-EOH ...your rename and domain join logic here... EOH not_if <<-EOH $ComputerSystem = gwmi win32_computersystem ($ComputerSystem.Name -like '#{node['some_attribute_that_has_the_new_name']}') -and $ComputerSystem.partofdomain) EOH notifies :reboot_now, 'reboot[Restart Computer]', :immediately end
where:
not_if
guard prevents the Windows PowerShell script from running when the settings in the not_if
guard match the desired statenotifies
statement tells the reboot resource block to run if the powershell_script block was executed during the chef-client run
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs-archive.chef.io/release/12-13/resource_reboot.html