Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm passing a hash to a define like so:


    net::addr { 'routes':
    ipr => {
        ipr1 => {
            address => '',
            netmask => '',
            gateway => '',
            dev     => 'eth3',
        ipr22 => {
            address => '',
            netmask => '',
            gateway => '',
            dev     => 'eth2',


define net::addr (
    if ($num != "") {

What I want to do is define a variable called iname and set it to the dev under each hash element, so on iteration 1 I want dev to be set to eth3, which corresponds to the "ipr1" element, on the next iteration I was iname set to eth2 and so on.

I'm struggling to do this as everytime my num variable keeps getting undefined and then ends up being set to 0, can someone please suggest a way round this or a more intelligent solution?

Thanks Dan

share|improve this question

2 Answers 2

As of Puppet version 3.3, the Puppet DSL language does not do (or need) iteration.

You should check out the create_resources() function from Puppet Labs:


# A hash of user resources:
$myusers = {
  'nick' => { uid    => '1330',
              group  => allstaff,
              groups => ['developers', 'operations', 'release'], }
  'dan'  => { uid    => '1308',
              group  => allstaff,
              groups => ['developers', 'prosvc', 'release'], }

create_resources(user, $myusers)
share|improve this answer
create_resources is what you are looking for.Puppet version 3.3 doesnt need iteration.

create_resources converts a hash into a set of resources and adds them to the catalog.

Check documentation

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.