2017-09-01 25 views
0

当前厨师配方代码谁能告诉更好的方式在厨师更换线

ruby_block 'replace_line' do 
    block do 
    file = Chef::Util::FileEdit.new(common_conf) 
    file.search_file_replace_line(/fs.type.*/, 'fs.type='+fs_type) 
    file.write_file 
    end 
    only_if { File.exist?(common_conf) } 
end 

我得到以下警告:

Running handlers complete 
[0m[2017-09-01T03:22:36-05:00] INFO: Report handlers complete 

Deprecated features used! 
Cloning resource attributes for ruby_block[replace_line] from prior resource 
[0mPrevious ruby_block[replace_line]: /var/chef/cache/cookbooks/spark_deployer/recipes/execution_component.rb:61:in `from_file' 
[0mCurrent ruby_block[replace_line]: /var/chef/cache/cookbooks/spark_deployer/recipes/execution_component.rb:70:in `from_file' at 1 location:[0m 
    - /var/chef/cache/cookbooks/spark_deployer/recipes/execution_component.rb:70:in `from_file'[0m 
    See https://docs.chef.io/deprecations_resource_cloning.html for further details 

谁能帮我写上面的代码中更好的办法?

回答

1

您是否尝试过

进一步的细节

https://docs.chef.io/deprecations_resource_cloning.html因为你清楚该错误消息告诉?如果你有,你可能会看到在这个配方之前你有另一个命名完全一样的:'replace_line'。为了解决这个问题,你要重命名这个配方(也可能给它的所有引用),以独特的东西,比如,说:

ruby_block 'replace_line_fs_type' do 
1

既然你问一个“更好的方式”,你可能会检查出line cookbook。它提供了编辑线的几个原语,如:

append_if_no_line "make sure a line is in some file" do 
    path "/some/file" 
    line "HI THERE I AM STRING" 
end 

最好的解决办法是管理主厨这整个文件,并且在嵌入一个模板在你的食谱,文件拷贝出来你的菜谱或者将整个文件写入您的ruby_block的一部分。部分管理的文件可能充满了危险。

此外,就像the other answer所说的那样,您依赖于资源克隆,因为您拥有多个同名的资源。即使切换到行菜谱,也应确保所有资源名称都是唯一的(或将所有编辑组合到一个资源中)。

+0

只是对未来的一个说明,因为厨师13资源克隆不再是一件事情,所以警告消失了。 – coderanger