Only_if not working


#1

If have a file with either 0 or 1

I need to execute something only_if file content is 0

Currently file has 0
However my

only_if (0 == cat /pathtofile/file} always return blocked due to only_if

note cat is in backtick

Appreciate any help.

M


#2

Hi,

For better readability please use the code blocks available in this forum in the future. Regarding your problem there are many many solutions and here are two of them:

only_if "grep 0 /path/to/file"
only_if { File.read('/path/to/file').chomp == 0 }

Mind that simple strings indicate that shell code is executed on the server and the return value is taken as condition. Curly braces indicate that Ruby code is executed and depending on wether it evaluates to TrueClass or FalseClass your resource will be executed or not.


#3

Thanks

This helps!