{"id":2124,"date":"2011-06-06T15:52:10","date_gmt":"2011-06-06T14:52:10","guid":{"rendered":"http:\/\/www.devco.net\/?p=2124"},"modified":"2011-10-27T23:29:17","modified_gmt":"2011-10-27T22:29:17","slug":"puppet_backend_for_hiera","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2011\/06\/06\/puppet_backend_for_hiera.php","title":{"rendered":"Puppet backend for Hiera"},"content":{"rendered":"

Note:<\/strong> This project is now being managed by Puppetlabs, its new home is http:\/\/projects.puppetlabs.com\/projects\/hiera<\/a><\/p>\n

Yesterday I released a Hierarchical datastore called Hiera<\/a>, today as promised I’ll show how it integrates with Puppet.<\/p>\n

Extlookup has solved the basic problem of loading data into Puppet. This was done 3 years ago at a time before Puppet supported complex data in Hashes or things like Parametrized classes. Now as Puppet has improved a new solution is needed. I believe the combination of Hiera and the Puppet plugin goes a very long way to solving this and making parametrized classes much more bearable.<\/p>\n

I will highlight a sample use case where a module author places a module on the Puppet Forge and a module user downloads and use the module. Both actors need to create data – the author needs default data to create a just-works experience and the module user wants to configure the module behavior either in YAML, JSON, Puppet files or anything else he can code.<\/p>\n

Module Author<\/h3>\n

The most basic NTP module can be seen below. It has a ntp::config<\/em> class that uses Hiera to read default data from ntp::data<\/em>:<\/p>\n

modules\/ntp\/manifests\/config.pp<\/b>
\n<\/p>\n

\r\nclass ntp::config($ntpservers = hiera(\"ntpservers\")) {\r\n    file{\"\/tmp\/ntp.conf\":\r\n        content => template(\"ntp\/ntp.conf.erb\")\r\n    }\r\n}\r\n<\/pre>\n

<\/code><\/p>\n

modules\/ntp\/manifests\/data.pp<\/b>
\n<\/p>\n

\r\nclass ntp::data {\r\n    $ntpservers = [\"1.pool.ntp.org\", \"2.pool.ntp.org\"]\r\n}\r\n<\/pre>\n

<\/code><\/p>\n

This is your most basic NTP module. By using hiera(“ntpserver”)<\/em> you load $ntpserver<\/em> from these variables, the first one that exists gets used. In this case the last one. <\/p>\n