Published on 29 July 2013 by

Hiera, a key/value data lookup tool for Puppet and Puppet Enterprise, defaults to storing data in YAML and JSON files. This is fine for many uses, but often someone will want to use a different storage format or import a bunch of data from an existing tool of some kind. To do this, you need to write a custom Hiera backend in Ruby.

Some users have already written and released custom Hiera backends, such as Craig Dunn's MySQL and http backends, and several more have probably written some but decided they were too special-purpose to publish. We think there are even more people who have some data source they'd love to integrate with, and would write a Hiera backend if they found the process easy enough.

Unfortunately, we haven't had any good documentation about writing custom backends. We've remedied that today and posted a writing custom backends chapter to the Hiera user's guide.

If you've got a data source you want to integrate with Puppet or Puppet Enterprise (maybe a CMDB hooked up to the barcode scanners your technicians use when racking hardware, maybe just a big Google spreadsheet or something), you should really take a look at this, because Hiera backends are a lot easier than they look at first. In the simplest form, you're basically just writing a lookup method that accepts four arguments, does whatever it takes to access a data source, and returns a single value. In the more flexible form, you'll also be writing a block that takes one argument and gets called for every hierarchy level. Neither approach is all that complex — the hardest part is writing the code that interfaces with your data source, and you probably have a simple API to leverage or an existing Ruby library that can do the heavy lifting.

The custom backends guide is available here, and includes a step-by-step progress walkthrough on a simple file-based backend.

Learn More

Share via:
Posted in:
The content of this field is kept private and will not be shown publicly.

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.