了解厨师only_if not_if [英] Understanding Chef only_if not_if
问题描述
我不确定我是否了解Chef的条件执行。
Im not sure I understand Chef conditional execution.
我想根据Postgresql中是否存在数据库进行一些条件执行
I'd like to do some conditional execution based on whether or not a database exists in Postgresql
所以这是我的示例
execute "add_db" do
cwd "/tmp"
user "dbuser"
command "createdb -T template_postgis mydb"
not_if 'psql --list|grep mydb'
end
运行 psql --list | grep mydb
返回数据库的期望值存在(带有dbname条目的行),如果不存在则什么也不存在。
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.
那么,不_if怎么评价呢?对或错? 1还是0?如果所有进程都成功,是否不返回0?
So how does not_if only evaluate that? True or false? 1 or 0? Dont all processes return 0 if they are successful?
任何建议将不胜感激!
推荐答案
我只是遇到了这个问题。我的问题是not_if命令是以 root而不是 dbuser的身份运行的。如果将其更改为
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.
http://tickets.opscode.com/browse/CHEF-438
这篇关于了解厨师only_if not_if的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!