How to define nodes from a Hiera file in Puppet?

Posted by Pigueiras on Server Fault See other posts from Server Fault or by Pigueiras
Published on 2013-11-12T08:41:39Z Indexed on 2013/11/12 9:58 UTC
Read the original article Hit count: 181

Filed under:

I am using puppet and the puppet network device management module and I am trying to build my custom type.

In the built-in type for the routers configuration, you can specify a list of nodes and then the configuration inside that node:

node "c2950.domain.com" { 
  Interface { duplex => auto, speed => auto } 
  interface { "FastEthernet 0/1": 
    description => "--> to end-user workstation", 
    mode => access, native_vlan => 1000 
  # [...] More configuration 
}

What I am trying to do, is to move the manifest declaration of the nodes and the configuration of my custom type to a Hiera file like this one:

nodes:
  - node1
  - node2

config_device:
  node1:
    custom_parameter: "whatever1"
  node2:
    custom_parameter: "whatever2" 

And then in the manifest iterate over the hiera file creating the nodes with the configuration of each node with something like (I am taking as reference this question in serverfault):

class my_class {
  $nodes = hiera_array('nodes')

  define hash_extract() {
    $conf_hash = hiera_hash("config_device")
    $custom_paramter = $conf_hash[$name]     ## TRICK lies in $name variable

    node $name {
      my_custom_device { $name:
        custom_parameter   => $device_conf['custom_parameter']
      }
    }
  }
  hash_extract{$pdu_names: }
  }
}

But for this solution I have two problems, I can not define a node inside a define and I can not parameterize a node name. So, is there any way to declare nodes from a Hiera file with their configuration inside?

© Server Fault or respective owner

Related posts about puppet