nanog mailing list archives

Re: Templating/automating configuration


From: Alexis Letessier <alexis.letessier () gmail com>
Date: Tue, 6 Jun 2017 23:03:14 +0200

Go templates: http://golang.org <http://golang.org/> Fast and simple with gRPC and other good stuff like kelsey’s confd 
(a daemon that watches for changes and update templates)

% go doc text/template
package template // import "text/template"

Package template implements data-driven templates for generating textual
output.

To generate HTML output, see package html/template, which has the same
interface as this package but automatically secures HTML output against
certain attacks.

Templates are executed by applying them to a data structure. Annotations in
the template refer to elements of the data structure (typically a field of a
struct or a key in a map) to control execution and derive values to be
displayed. Execution of the template walks the structure and sets the
cursor, represented by a period '.' and called "dot", to the value at the
current location in the structure as execution proceeds.

The input text for a template is UTF-8-encoded text in any format.
"Actions"--data evaluations or control structures--are delimited by "{{" and
"}}"; all text outside actions is copied to the output unchanged. Except for
raw strings, actions may not span newlines, although comments can.

Once parsed, a template may be executed safely in parallel.

Here is a trivial example that prints "17 items are made of wool".

    type Inventory struct {
        Material string
        Count    uint
    }
    sweaters := Inventory{"wool", 17}
    tmpl, err := template.New("test").Parse("{{.Count}} items are made of {{.Material}}")
    if err != nil { panic(err) }
    err = tmpl.Execute(os.Stdout, sweaters)
    if err != nil { panic(err) }

Alexis

On 6 Jun 2017, at 15:22, Graham Johnston <johnstong () westmancom com> wrote:

Short of complete SDN, for those of you that have some degree of configuration templating and/or automation tools 
what is it that you run? I'm envisioning some sort of tool that let's me define template snippets of configuration 
and aids in their deployment to devices. I'm okay doing the heaving lifting in defining everything, I'm just looking 
for the tool that stitches it together and hopefully makes things a little less error prone for those who aren't as 
adept.

Graham Johnston
Network Planner
Westman Communications Group
204.717.2829
johnstong () westmancom com<mailto:johnstong () westmancom com>



Current thread: