1

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"],
    }
}
user1357182
  • 59
  • 1
  • 2
  • 7

2 Answers2

2

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.

xelco52
  • 5,257
  • 4
  • 40
  • 56
Ger Apeldoorn
  • 1,232
  • 8
  • 13
0

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
Zipfer
  • 174
  • 1
  • 6