我有一個Rails應用程序,我想要改變./config/environment/production.rb文件,以根據我想要的服務器做不同的配置。這是使用puppet更改配置文件的正確方法嗎?
因此,我將從.pp文件進入.rb文件並更改一些字符串,然後重新啓動服務。這對我來說似乎非常糟糕。有一個更好的方法嗎?我一直要求提供 RPM和改變通過木偶的配置,所以......
class Cloud-widget($MServer, $GoogleEarthServer, $CSever) {
package { "Cloud-widget":
ensure => installed
}
service { "Cloud-widget":
ensure => running,
}
<%
file_names = ['./config/environment/production.rb']
file_names.each do |file_name|
puts text.gsub(/.*config.mserver(.*)/, "config.mserver_root = \"#{$Merver}\"")
puts text.gsub(/.*config.google_earth_url(.*)/, "config.google_earth_url(= \"#{$GoogleEarthServer}\"")
puts text.gsub(/.*config.cserver_base_url(.*)/, "config.cserver_base_url = \"#{$CServer}\"")
end
File.open(file_name, "w") {|file| file.puts output_of_gsub}
%>
service { Cloud-widget:
ensure => running,
subscribe => File["./config/environment/production.rb"],
}
}
使用ERB模板是(請參閱http:// docs.puppetlabs.com/guides/templating.html) –