The library comes with a nice building block in the Puppet.Daemon module. Here is a minimalistic application of this library (note that I have tried to keep this readable by non Haskellers).
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Here is a detailed explanation of what is happening:
- Lines 1 to 4 import all the required libraries that we will use in this example.
- Line 6 declares the main function, nothing interesting here.
- Line 7 computes the preferences from the base puppet directory. As explained in the haddocks, this structure holds the directory for manifests, modules and templates. This helper function just fills the fields with their default values. The astute reader will notice that this structure could holds pool sizes, for compilation and parsing. This is mainly used if your application needs to scale, and will be covered in a later post.
- Line 8 initializes the daemon, and returns a function that takes a node name and a set of facts, and should return a catalog object.
- Line 9 gathers facts from the local computer, using the hsfacter module. This is pretty experimental, but works for the current use cases.
- Line 10 computes the catalog for node
node.test
. - Lines 11 to 13 display an error if something failed or the actual catalog.
This covers a very basic usage of the tool. In the next post, a simple yet useful application will be described.