Summary: In this article you will learn how to debug hiera lookups using the traditional methods and more importantly with the puppet-debugger which can cover a multitude of use cases.
Previously, debugging hiera lookups has been limited to the command line and debug logs. If you wanted to debug hiera lookups you had to use the hiera command and pass in the config file along with the scope (variables, facts) you wanted to use.
Puppet introduced Bolt at Puppetconf 2017 this year and so far I like what I see. Simple, easy to use remote task execution without a huge requirement of any one language. Best of all puppet modules can start adding one off bolt tasks to help with the administrative duties of various applications. Bolt makes it really easy to get started but adds some required scaffolding to create a properly defined task, namely the metadata file.
Puppet 4.9 cemented the final touches to putting data in puppet modules with the release of hiera 5. Which by the way hiera is now part of Puppet project instead of a separate gem as with previous versions.
So now that that whole params.pp mess is over we can finally move forward and create modules with rich sets of data without resorting to the params.pp hack.
So lets get started. In order to put data in your module you need to have a few things.
The puppet 4 language introduced a slew of new features that gives us enormous amounts of power and flexibility. So much so that puppet code can become complex and often hard to understand at a glance.
A way to combat this complexity is to write unit tests to validate the end state. However, one of the shortcomings of unit testing with rspec-puppet is that you can only test against the end state.
Did you know the puppet debugger can measure how fast your puppet code runs? Starting with release 0.6.1 of the puppet-debugger you can now perform simple benchmarks against your puppet code. So if you ever wondered how fast your puppet code is or that custom puppet function you wrote now there is a way to benchmark those things.
All you need to do is enable benchmark mode, and then use the debugger as you normally do.
The puppet language comes with a lot of extremely useful syntax and concepts. However, sometimes it is difficult to understand how these work or how to use them. Datatypes are found in almost every programming language so it is no surprise that puppet 4 has a similar feature for validating parameter data. If you have never used a puppet datatype before have a look here first.
The other day I was showing my client the awesome power of puppet datatypes and I was using the puppet-debugger to illustrate how datatypes work.