【发布时间】:2015-06-02 21:19:39
【问题描述】:
我正在使用我自己创建的 Opscode Tomcat 食谱。我需要在 /etc/default/tomcat{version} 文件的末尾附加一个循环,并且我已经研究过使用部分,但我不确定如何通过我自己的食谱应用它(我们公司的政策是创建我们自己的食谱,将外部食谱作为参考)。
我认为模板资源可能会做到这一点,但我也被告知提供者可能是解决方案。
【问题讨论】:
标签: tomcat chef-infra
我正在使用我自己创建的 Opscode Tomcat 食谱。我需要在 /etc/default/tomcat{version} 文件的末尾附加一个循环,并且我已经研究过使用部分,但我不确定如何通过我自己的食谱应用它(我们公司的政策是创建我们自己的食谱,将外部食谱作为参考)。
我认为模板资源可能会做到这一点,但我也被告知提供者可能是解决方案。
【问题讨论】:
标签: tomcat chef-infra
您可以使用 Chef, Inc. 员工创建的 line 食谱来处理较小的文件更改:
https://github.com/someara/line-cookbook
例子:
append_if_no_line "make sure a line is in dangerfile" do
path "/tmp/dangerfile"
line "HI THERE I AM STRING"
end
replace_or_add "spread the love" do
path "/some/file"
pattern "Why hello there.*"
line "Why hello there, you beautiful person, you."
end
delete_lines "remove hash-comments from /some/file" do
path "/some/file"
pattern "^#.*"
end
add_to_list "add entry to a list"
path "/some/file"
pattern "People to call: "
delim [","]
entry "Bobby"
end
【讨论】:
我选择了这个不太优雅的解决方案;
ruby_block "insert_line" do
block do
file = Chef::Util::FileEdit.new("/etc/hosts")
file.insert_line_if_no_match("/www.example.com/", "www.example.com")
file.write_file
end
end
【讨论】: