【问题标题】:Is this the correct way to change a config file using puppet?这是使用 puppet 更改配置文件的正确方法吗?
【发布时间】:2012-06-11 16:32:39
【问题描述】:

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

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

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

【问题讨论】:

标签: puppet


【解决方案1】:

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

您可以查看模板并以这种方式生成配置文件。这样,您就可以在配置文件中使用变量。

【讨论】:

    【解决方案2】:

    如果您需要从模式创建 conf,您应该使用 Puppetlabs 的 INI 文件模块

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

    从 puppet 安装这个模块:

    puppet module install cprice404-inifile
    

    【讨论】:

      猜你喜欢
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 2012-05-11
      • 2018-12-31
      • 2021-04-29
      • 1970-01-01
      相关资源
      最近更新 更多