Skip to content

packethost/gornir

 
 

Repository files navigation

GoDoc Build Status codecov Go Report Card

gornir

Gornir is a pluggable framework with inventory management to help operate collections of devices. It's similar to nornir but in golang.

The goal is to be able to operate on many devices with little effort. For instance:

package main

import (
	"os"

	"github.com/nornir-automation/gornir/pkg/gornir"
	"github.com/nornir-automation/gornir/pkg/plugins/inventory"
	"github.com/nornir-automation/gornir/pkg/plugins/logger"
	"github.com/nornir-automation/gornir/pkg/plugins/output"
	"github.com/nornir-automation/gornir/pkg/plugins/runner"
	"github.com/nornir-automation/gornir/pkg/plugins/task"
)

func main() {
	log := logger.NewLogrus(false)

	file := "/go/src/github.com/nornir-automation/gornir/examples/hosts.yaml"
	plugin := inventory.FromYAML{HostsFile: file}
	inv, err := plugin.Create()
	if err != nil {
		log.Fatal(err)
	}

	gr := gornir.New().WithInventory(inv).WithLogger(log).WithRunner(runner.Parallel())

	results, err := gr.RunSync(
		"What's my ip?",
		&task.RemoteCommand{Command: "ip addr | grep \\/24 | awk '{ print $2 }'"},
	)
	if err != nil {
		log.Fatal(err)
	}
	output.RenderResults(os.Stdout, results, true)
}

would render:

# What's my ip?
@ dev5.no_group
  - err: failed to dial: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain

@ dev1.group_1
 * Stdout: 10.21.33.101/24

 * Stderr:
  - err: <nil>

@ dev2.group_1
 * Stdout: 10.21.33.102/24

 * Stderr:
  - err: <nil>

@ dev3.group_2
 * Stdout: 10.21.33.103/24

 * Stderr:
  - err: <nil>

@ dev4.group_2
 * Stdout: 10.21.33.104/24

 * Stderr:
  - err: <nil>

Examples

You can see more examples in the examples folder and run them with Docker-Compose as follows:

  1. Create a development enviroment
make start-dev-env
  1. Run any of the examples in the examples folder with make example. Specify the name of the example with EXAMPLE; for instance 2_simple_with_filter.
make example EXAMPLE=2_simple_with_filter
  1. After you are done, make sure you stop the development enviroment
make stop-dev-env

The project is still work in progress and feedback/help is welcomed.

Releases

No releases published

Packages

No packages published

Languages

  • Go 95.0%
  • Makefile 4.7%
  • Dockerfile 0.3%