minimalistic configuration templating


minimalistic config templating

npm install -g core-cfg

core-cfg installs two programms: cfg and facts.

Usage: cfg [template-dir]

    -d, --destination <path>  Write processed templates relative to <path> [/]
    -t, --template <file>     Process only <file> and write output to stdout

cfg creates configuration files from templates which are filled with data from a json object. This json object is read from stdin as context. The context is applied to all template configuration files in template-dir (or a single template file if the -t option is used). As a template language Handlebars ( is used. The complete file tree (including permissions) is reproduced into the destination directory (which by default is /).

Usage: facts <keys...>

    -i, --stdin    Read JSON from stdin

facts is a small utility to create a cfg context from a SmartOS Zone configuration.

It takes any number of keys as arguments, reads them via mdata-get and produces a JSON object which can be processed by cfg. When the -i option is used it merges the context with a JSON object read from stdin.

# echo '{"foo": "yes"}' | facts -i sdc:max_physical_memory sdc:zonename
    "foo": "yes",
    "sdc:max_physical_memory": "512",
    "sdc:zonename": "9402a15e-a6a3-49c9-90a1-910c893c06ed"

# facts graphite_host | cfg /opt/cfg/templates/graphite/