inventory

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package inventory reads hosts from a Markdown file, for running roles without a manager:

# Databases
- db1 ubuntu@10.0.0.5 env=prod
- db2 ubuntu@10.0.0.6:2222 env=prod

# Web
- web1 deploy@web1.internal env=staging
- web2.internal

Headings are groups, nested by level. Each bullet is a host: an optional name, the SSH address as [user@]host[:port], and KEY=VALUE labels. A bullet with only an address, or an alias from ~/.ssh/config, uses it as the name.

A "user:" or "identity:" line sets the SSH user or private key file for the hosts that follow in its group and subgroups, or for every host when it comes before the first heading:

# Production
identity: ~/.ssh/prod_ed25519
user: ubuntu
- db1 10.0.0.5
- db2 10.0.0.6 identity=~/.ssh/db2_key

A host's own user@ or identity= wins over its group's.

Labels are also the variables roles use as {{ name }}. A "vars:" line sets them for a group, and a host's own KEY=VALUE wins:

# Shop
vars: domain=shop.example.com app_port=3000
- web1 deploy@10.0.0.5
- web2 deploy@10.0.0.6 app_port=4000 title="Shop two"

Quote values that contain spaces or commas. Other text is notes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Groups

func Groups(hosts []Host) []string

Groups lists every group heading in the inventory.

Types

type Host

type Host struct {
	Name    string            `json:"name"`
	User    string            `json:"user,omitempty"` // empty: ~/.ssh/config or the local user
	Address string            `json:"address"`
	Port    int               `json:"port,omitempty"` // 0: ~/.ssh/config or 22
	Labels  map[string]string `json:"labels,omitempty"`
	Groups  []string          `json:"groups,omitempty"`
	// Identity is the private key file as written, before ~ and ${VAR}
	// are expanded on the machine that runs korta.
	Identity string `json:"identity,omitempty"`
	Line     int    `json:"line"`
}

Host is one inventory entry.

func Parse

func Parse(src string) ([]Host, error)

Parse reads a Markdown inventory. Mistakes are reported with their line.

func Select

func Select(hosts []Host, limit string) ([]Host, error)

Select keeps the hosts matching any comma-separated selector: a group heading, a host name, or KEY=VALUE label. An empty limit keeps all hosts. A selector that matches nothing is an error, which catches typos.

func (Host) Matches

func (h Host) Matches(sel string) bool

Matches reports whether a selector picks this host.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL