I just released the latest language-puppet version. For the full list of changes, please take a look at the changelog. Here are the highlights.
PuppetDB code reworked
The PuppetDB code and API has been completely overhauled. It is now more generic : the resource collection and puppet query functions now work the same. Additionally, a PuppetDB stub has been created for testing use.
Better diagnostic facilities
As the main use of this library is to test stuff, the following features were added:
- Several error messages have been reworked so that they are more informative.
- A
dumpvariables
built-in function has been added. It just prints all known variables (and facts) to stdout, and can be quite handy. - The “scope stack” description is stored with the resources. This turned out to be extremely useful when debugging resource names colisions or to find out where some resource is defined.
Here is an example, let’s say you do not remember which package installs the collectd
package. Just run this :
1 2 3 4 5 6 7 |
|
You now know exactly where the package
resource is declared, and the list of “scopes” that have been traversed in
order to do so. Note that this information is displayed when resources names collide.
Easier to setup
This library doesn’t depend from a newish bytestring
anymore, and should build with the package provided with a GHC
compiler of the 7.6.x serie.
This is not yet done, but I will certainly soon publish a debian-style repository of the compiled puppetresources
binary. I am interested in suggestions for an automated building system.
Better testing
The testing API seems sufficient to write pretty strong tests, but would still benefit from a few more helper functions. The testing “daemon” has been reworked to use the new PuppetDB stub. It makes it possible to test complex interactions between hosts using the exported resource or PuppetDB query features.
Work in progress
I will probably lensify the code until I get a descent understanding of it.
I do not intend to work on Hiera emulation just yet, as I am probably the only user of this library for now and I do not use this feature.
One area of improvement would be to embed the ruby interpreter in the library. I am not sure how to do this, but as there are quite a few projects of lightweight interpreters sprouting from the earth, it might be possible in the near future. The only problem would be figuring out how to build a large C project with cabal.
Some other considerations
I recently ported the code from random.c
to Haskell
(here). This has been
quite tedious, and is quite hard to read. This is an almost naive port of the code found in the Ruby interpreter,
without the useless loop variables. For some reason, there are many loops like this :
1 2 3 4 5 6 7 8 9 10 |
|
As you can see, the value of k is never used in the loop. I am not sure why the author didn’t go for something like :
1
|
|
Anyway, the Haskell code is pretty bad, and will certainly only work for 64-bit builds. I am not sure how I should have written it. I suppose staying in the ST monad would have lead to nicer code, and I am open to suggestions.