Reputation: 659
I want to execute a command only if the given directory "/local/update/" doesn't exist
My recipe code is below
execute 'test' do
command "some command here"
not_if { ::File.directory?("/local/update/") }
end
also tried
not_if { ::File.exist?("/local/update/") }
Even when the directory is present it still runs the command. I have checked in client.log and this step is not skipped
Upvotes: 0
Views: 47
Reputation: 7340
Adding an answer as there is a better (in-built) way to make the execute
resource idempotent. Instead of skipping it using not_if
, we can use the creates
property. From the documentation:
creates
Ruby Type: String
Prevent a command from creating a file when that file already exists.
Example:
execute 'test' do
command "some command here"
creates '/local/update/'
end
With this implementation, the command
will run if the /local/update/
path does not exist. Otherwise it will report as "up to date":
* execute[test] action run (up to date)
Upvotes: 1