Is this the correct way to change a config file using puppet?

送分小仙女□ 提交于 2019-12-25 08:49:59

问题


I have a rails app and I'd like to change the ./config/environment/production.rb file to have a different config based on what I want that server to do.

So, I'm going into the .rb file from the .pp file and changing some strings then restarting the service. This just seems really poor form to me. Is there a better way to do this? I've been asked to deliver 1 RPM and change the config via puppet, so...

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"],
    }
}

回答1:


No, that is not a good way to achieve what you need.

You could look at templates and generate the config files that way. That way, you can use variables in the config file.




回答2:


If you need create conf from pattern you should use INI-file module from Puppetlabs

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

install this module from puppet:

puppet module install cprice404-inifile


来源:https://stackoverflow.com/questions/10984084/is-this-the-correct-way-to-change-a-config-file-using-puppet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!