2012-06-11 26 views
0

我有一個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"], 
    } 
} 
+0

使用ERB模板是(請參閱http:// docs.puppetlabs.com/guides/templating.html) –

回答

2

不,那是不是達到你所需要的一個好辦法。

你可以看看模板並以這種方式生成配置文件。這樣,你可以在配置文件中使用變量。

0

如果需要從模式創建的conf你應該使用INI文件模塊從Puppetlabs

ini_setting { "sample setting": 
    path => '/tmp/foo.ini', 
    section => 'foo', 
    setting => 'foosetting', 
    value => 'FOO!', 
    ensure => present, 
} 

從木偶安裝該模塊:

puppet module install cprice404-inifile 
相關問題