Attributes passed to a defined resource or hostclass will be available as instance variables within the block.

define :foo, :bar do
notify @name, :message => @bar
end

Examples

One of the oldest open tickets in Puppet requests mkdir_p functionality (It's #86 :) ). We can easily code this with the Ruby DSL since Ruby can iterate over all directory subpaths to create File resources.

define :mkdir_p do
name = @name
until name == '/'
file name, :ensure => 'directory'
name = File.dirname(name)
end
end
node 'default' do
mkdir_p '/tmp/foo/bar/baz'
end

henrik lindberg

First a small note. The manifests are not fully declarative but they produce a catalog that is. We decided that it was more valuable to add iteration to the Puppet Language as this was the main reason for using the Ruby DSL.

The Ruby DSL was also very limited in what could be expressed.
There was an attempt of reaching the same level of functionality in the Ruby DSL as in the Puppet manifests. It did not quite succeed, and the result was far more unsafe (small mistakes could have grave consequences like stopping, hanging or crashing the puppet master). This attempt was reverted and never released and the remaining very limited (earlier released) Ruby DSL was deprecated, and subsequently removed.

"As for just using Ruby as the input format, Puppet 2.6.0 actually added this functionality, and manifests can now be written in pure Ruby. However, this capability should be used carefully and avoided where possible: the full grammar of Ruby is often too much functionality, and we believe systems administrators should be able to model their datacenters in a higher-level system"