On Fri, Feb 15, 2013 at 6:52 AM, Leo Simons <[email protected]> wrote:
> Hey folks, > > On Saturday, January 26, 2013 6:06:55 PM UTC+1, Eric Sorenson wrote: > >> ### Ruby DSL Deprecated, new Puppet Ruby DSL removed >> >> We introduced deprecation warnings for the (not-well-documented, >> mostly-unused) Ruby DSL; if you are using the Ruby DSL in production >> we want to hear from you to learn what you're doing with it -- please >> reply to this message on [email protected]! >> > > Well, ok :-) > > We are currently using the ruby DSL in production and we're pretty > dependent on it. We don't like this setup very much (mostly because it's > undocumented and fragile!), but there's a few things we can't figure out > how to accomplish with the puppet DSL, yet we aren't rubyist enough to > write elaborate plugins. > > We have a custom external node classifier which is a pretty simple ruby > script that reads in a set of YAML files and merges them together. These > files include > > * config.yml with various global/default config > * systems.yml defining every system > * profiles.yml defining the classes for every profile > * environments.yml defining all environments and customized settings per > environment > * apps.yml defining all apps (java webapps, ruby webapps, ...) that are > installed into every profile > > We then have profiles for management servers (certificate authority, > syslog host, monitoring host, ...) that need to know about all the other > systems (for example to open up firewalls, open up syslog for connections > from other hosts, write per-app custom nagios classes, generate CRLs, ...). > The fiddly solution we have for that involves some custom classes written > with ruby DSL that read in one or more of the above YAML files (or in some > cases, even re-invoke the external node classifier), and then call > create_resources() to hand control back to puppet. > > For example, here's how we tell the rsyslog host about the machines it > should accept connections from: > > hosts.rb > ---- > hostclass :"rsyslog::hosts" do > management = scope.lookupvar("management") > # for example, 'local' is not to be monitored > exclude = management['exclude_environments'] > > nodes = YAML::load( File.open( '/etc/sys/puppet/systems.yml' )) > hosts = [] > nodes.each do |host, params| > env = params['env'] > # 'deleted' remembers machines that will be decomissioned soon > if env == "deleted" or exclude.include? env > next > end > > hosts.push(host) > end > > rsyslog_clients = { > "rsyslog::hosts::config" => { > "rsyslog_clients" => hosts > } > } > > create_resources(['rsyslog::config', rsyslog_clients]) > end > > init.pp > ---- > ... > define rsyslog::config($rsyslog_clients) { > file { "/etc/rsyslog.conf": > owner => root, > group => root, > mode => 644, > content => template("rsyslog/rsyslog.conf.erb"), > require => [ > Class["rsyslog::packages"], > Exec["rsyslog-ssl-cert"], > ], > notify => Service["rsyslog"], > } > } > ... > > rsyslog.conf.erb > ---- > ... > <% rsyslog_clients.each do |client| %> > $InputTCPServerStreamDriverPermittedPeer <%= client %> > <% end %> > ... > > So you can imagine my brief panic when my local test puppet VM greeted me > this morning with big fat red letters > > Warning: Use of the Ruby DSL is deprecated. > (at /usr/lib/ruby/vendor_ruby/puppet/parser/parser_support.rb:140:in > `parse') > > I counted, we have only 6 such custom hostclasses, they're all less than > 50 lines, and they all follow pretty much the same pattern. > > I would not mind at all getting rid of the ruby DSL stuff in favor of > something else, but, since I see no alternative yet, and since you asked > for it, I thought I'd write about our particular flavour of iteration use > case :) > Since you are passing data to create_resources, how about a rvalue function? module Puppet::Parser::Functions newfunction(:rsyslog_client, :type => :rvalue) # copy what you have currently before the create_resource call. end end class rsyslog::hosts { create_resources('rsyslog::config', rsyslog_client) } You might even be able to consolidate them if they use the same pattern. Nan -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/puppet-dev?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
