This is the official demonstration of the capabilities of the language-puppet library. While it is pretty hackish, it is also quite useful, especially for people working a log with large manifests.
Installing the application
In order for the application to work, you will need a working Haskell
environment for now. As it compiles into native code, it is pretty simple to
generate a redistributable binary. As with most Haskell binaries, the only
required library is libgmp
.
The only trouble is the dependency on a Ruby script that will compute the complicated templates, as it would be way too much work to emulate fully this language. This means you will also need a ruby interpreter installed, and probably not much more.
So once you have a working cabal, and a recent GHC (all coming from your distribution or from The Haskell Platform), just type :
1
|
|
Checking the parser
You now have a puppetresources
executable. If invoked with a single argument,
it will parse a Puppet manifest file and show you how it parsed it :
1 2 3 4 5 6 |
|
This is not terribly useful, but could be used to check for syntax errors.
Computing catalogs
This is the main usage of this application : computing whole catalogs. In order
to do this you must invoke it with a path to a standard Puppet directory (such
as /etc/puppet
) and a node name :
1 2 3 4 5 6 7 8 9 10 11 |
|
This will display the whole catalog as a large, top level, Puppet manifest, after the warnings. As not everything is implemented yet, there will probably be quite a few of them for real world catalogs.
You will notice that the relationship between resources is not yet supported, and that a class resource type is used. This is a placeholder for the future relationships system.
The typical use of this feature occurs during manifests development. It serves as a high level correctness checker, as it will fail about the same as the real Puppet application, but can be run on your workstation before pushing to the puppet master. It is also significantly faster than the Ruby code.
Debugging templates
Using the previous features helps a lot, but is not very useful when debugging templates. The reason is that the content parameter is displayed as a one line string, and is hard to read in most cases :
1 2 3 4 5 6 |
|
It is then possible to add a third argument, which is the name of one of the files, to display its content on the standard output :
1 2 3 4 5 |
|
Interactive use and diffing
This is the fun part. For this a binary distribution will not work as it
requires ghci
. In order to play with this, you need to run it on the Main.hs
file, initialize the daemon and start computing catalogs :
1 2 3 4 5 6 |
|
The catalogs returned are of type FinalCatalog, which is a plain Data.Map. This means you can manipulate it as usual, checking its size or typing crazy one liners :
1 2 3 4 5 6 7 8 |
|
But the real point here is to run diffs between catalogs, to check differences between hosts that should be alike, or progress when altering a catalog :
1 2 3 4 5 6 |
|
Important note about the facts
All the facts, except those related to hostnames, are extracted from the current
host. This means that the differences will not be accurate if part of the
catalog comes from the facts, which is pretty common. Handling this properly is
left as an exercice to the reader, but should be fairly obvious (roll out your
own initializedaemon
that takes facts as parameter).