Method: Chef::Resource#only_if
- Defined in:
- lib/chef/resource.rb
#only_if(command = nil, opts = {}, &block) ⇒ Object
A command or block that indicates whether to actually run this resource. The command or block is run just before the action actually executes, and the action will be skipped if the block returns false.
If a block is specified, it must return true in order for the Resource to be executed.
If a command is specified, the resource’s #guard_interpreter will run the command and interpret the results according to opts. For example, the default execute resource will be treated as false if the command returns a non-zero exit code, and true if it returns 0. Thus, in the default case:
-
‘only_if “your command”` will perform the action only if `your command`
returns 0.
-
‘only_if “your command”, valid_exit_codes: [ 1, 2, 3 ]` will perform the action only if `your command` returns 1, 2, or 3.
379 380 381 382 383 384 |
# File 'lib/chef/resource.rb', line 379 def only_if(command = nil, opts = {}, &block) if command || block_given? @only_if << Conditional.only_if(self, command, opts, &block) end @only_if end |