这是使用 puppet 更改配置文件的正确方法吗? [英] Is this the correct way to change a config file using puppet?

查看:53
本文介绍了这是使用 puppet 更改配置文件的正确方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 rails 应用程序,我想根据我希望该服务器执行的操作更改 ./config/environment/production.rb 文件以使用不同的配置.

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.

所以,我将从 .pp 文件进入 .rb 文件并更改一些字符串,然后重新启动服务.这对我来说似乎非常糟糕.有一个更好的方法吗?我被要求提供 1 RPM 并通过 puppet 更改配置,所以...

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

推荐答案

不,这不是实现您需要的好方法.

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.

这篇关于这是使用 puppet 更改配置文件的正确方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆