[Puppet-users] Pupppet Ruby DSL

Luke Kanies
Wed, 26 Jul 2006 14:13:52 -0000

I constantly get told I should just create a DSL in Ruby, instead of
having a separate, custom language.  This has, unsurprisingly, come
up multiple times here at OSCON.

So, I decided I''d see if I could hack something up and see how it
looked.  This is the first thing I could come up with in terms of the
basic functionality:

#!/usr/bin/ruby

class Base
     file "/etc/passwd",
         :owner => "root",
         :group => "root",
         :mode => 0644,
         :source => "puppet://puppet/..."



end

class BSD < Base
     file "/etc/passwd",
         :group => "wheel"
end

include :bsd

The implementation I have (which is about 105 lines of code) supports
the same kind of overriding that Puppet''s language supports, but it
doesn''t do anything else.  I haven''t tried to model define
statements, since I figure people would just use the normal Ruby
methods.  I also haven''t bothered to set up any of the Facts in the
script or anything like that, and currently my code just dumps the
created configuration, rather than applying it.

I have been thinking that maybe Puppet could support loading
''.rb''
files written in this kind of code, or ''.pp'' files written in
current
Puppet code, and it should be possible to otherwise treat them the
same -- puppetmasterd would parse everything and wait for
connections, while puppet would immediately apply the configuration.
I wouldn''t expect you to be able to mix files -- all of them would
be .pp, or all of them would be .rb.

I haven''t thought much about how this would look in real life, but I
figured I''d at least look at what a DSL in Ruby would look like and
see if it was an incredibly bad idea.

I still don''t know.  It feels like it''s basically as
restricted as
the language, but certainly it''s a heckuva lot less code than
Puppet''s parser is.

Any comments?  Should I commit this to subversion, just to keep it
around in case people want to mess with it?

--
Luke Kanies
http://madstop.com
615-594-8199