Im not sure I understand Chef conditional execution.
I'd like to do some conditional execution based on whether or not a database exists in Postgresql
So here's my example
execute "add_db" do
cwd "/tmp"
user "dbuser"
command "createdb -T template_postgis mydb"
not_if 'psql --list|grep mydb'
end
Running psql --list|grep mydb
return what you would expect if the db exists (the line with the dbname entry) and nothing at all if it doesnt.
So how does not_if only evaluate that? True or false? 1 or 0? Dont all processes return 0 if they are successful?
Anywho any advice would be greatly appreciated!
I just ran into this issue. My problem was that the not_if command was being run as 'root', not 'dbuser'. If you change it to
not_if 'psql --list|grep mydb', :user => 'dbuser'
then you may get the results you were looking for.