Method: Chef::Resource#not_if
- Defined in:
- lib/chef/resource.rb
#not_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 true.
If a block is specified, it must return false 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:
-
‘not_if “your command”` will perform the action only if `your command`
returns a non-zero code.
-
‘only_if “your command”, valid_exit_codes: [ 1, 2, 3 ]` will perform the action only if `your command` returns something other than 1, 2, or 3.
409 410 411 412 413 414 |
# File 'lib/chef/resource.rb', line 409 def not_if(command = nil, opts = {}, &block) if command || block_given? @not_if << Conditional.not_if(self, command, opts, &block) end @not_if end |