Chef infra 如何在使用bash创建chef cookbook后编辑该文件

Chef infra 如何在使用bash创建chef cookbook后编辑该文件,chef-infra,chef-recipe,chef-solo,Chef Infra,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"

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

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
在编辑过程中。 我怎样才能解决它

谢谢,Arshavski Alexander

您需要使用ruby_块资源,而不是执行资源。您的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

根据我的经验,这对厨师来说是一个特别困难的问题。您希望配置文件与项目代码一起在源代码管理下管理,但希望Chef管理其中的硬件和机密配置。我尝试过/看到过但不满意的解决方案:将配置文件完全移动到Chef repo,将配置选项拆分为两个文件—一个在Chef中,另一个在源代码中,构建选项覆盖机制,使Chef配置文件中的选项优先+希望其他人有更好的想法。
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