如何用bash创建厨师食谱中的文件

时间:2015-05-14 16:27:30

标签: chef chef-recipe chef-solo

我正在为应用程序部署编写一些厨师食谱。 我提取代码然后编辑它。它看起来像:

bash 'admin-init' do
    user "root"
    code <<-EOH
        <here I extract the code>
    EOH
end

execute 'configure' do
  file = Chef::Util::FileEdit.new(node["code_dir"] + "websaas/settings.py")
  file.search_file_replace("'HOST': '*'", "'HOST': '" + node["db_host"] + "'")
  file.write_file
end

我的问题是在编译期间,settings.py还没有,所以我得到:

ArgumentError
-------------
File doesn't exist
在厨师编译期间

我该如何解决?

谢谢Arshavski Alexander

1 个答案:

答案 0 :(得分:0)

您需要使用ruby_block资源,而不是execute资源。你的执行资源甚至没有定义命令,因此没有任何效果。

ruby_block 'configure' do
  block do
    file = Chef::Util::FileEdit.new(node["code_dir"] + "websaas/settings.py")
    file.search_file_replace("'HOST': '*'", "'HOST': '" + node["db_host"] + "'")
    file.write_file
  end
end