# Any of these next three examples will create /tmp/somefile, but not if /etc/passwd exists.
not_if Do not apply this resource if the given string (shell command) or block (ruby code) results in return code 0 or is true.
only_if Only apply this resource if the given string (shell command) or block (ruby code) results in return code 0 or is true.
not_if and only_if attributes can be passed as strings or blocks.
Strings are executed as a shell command. The attribute is true if the command returns 0.
Blocks are Ruby code. The attribute is true if the result is true.
The behavior of the resource depends on whether the attribute was true.
not_if {true} - indicates the action should never be performed.
not_if {false} - indicates the action should always be performed.
only_if {true} - indicates the action should always be performed.
only_if {false} - indicates the action should never be performed.
# A block using curly braces
template "/tmp/somefile" do
mode "0644"
source "somefile.erb"
not_if {File.exists?("/etc/passwd")}
end