【发布时间】:2017-12-06 04:31:53
【问题描述】:
我知道有很多答案和已解决的答案,但似乎没有什么对我有用,我想做的是在 tomcat 安装完成后添加几行代码,并在 /var/ 中安装lib/tomcat8/conf/catalina.properties 文件。
这是我迄今为止尝试过的简单的 ruby 方法以及 Chef utils 的方法。
File.open("/var/lib/tomcat8/conf/catalina.properties", "a+") do |f|
f << "\n"
f << "javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"
end
ruby_block "insert_line" do
block do
file = Chef::Util::FileEdit.new("/var/lib/tomcat8/conf/catalina.properties")
file.insert_line_if_no_match("/javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl/", "javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl")
file.write_file
end
end
file '/var/lib/tomcat8/conf/catalina.properties' do
action :create
owner 'root'
group 'root'
content File.open("/var/lib/tomcat8/conf/catalina.properties", "a+") do |f|
f << "\n"
f << "javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"
end
end
file '/var/lib/tomcat8/conf/catalina.properties' do
action :create
owner 'root'
group 'root'
content File.open("/var/lib/tomcat8/conf/catalina.properties", "a+") do |f|
f << "\n"
f << "javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"
end
end
我尝试将 puts “测试”,但似乎厨师甚至没有进入代码。
【问题讨论】:
标签: ruby chef-infra chef-recipe chef-solo cookbook