config

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	Name        string            `yaml:"name" toml:"name"`
	Copy        CopyInternal      `yaml:"copy" toml:"copy"`
	MCopy       []CopyInternal    `yaml:"mcopy" toml:"mcopy"`
	Sync        SyncInternal      `yaml:"sync" toml:"sync"`
	Delete      DeleteInternal    `yaml:"delete" toml:"delete"`
	Wait        WaitInternal      `yaml:"wait" toml:"wait"`
	Script      string            `yaml:"script" toml:"script,multiline"`
	Environment map[string]string `yaml:"env" toml:"env"`
	Options     CmdOptions        `yaml:"options" toml:"options,omitempty"`

	Secrets map[string]string `yaml:"-" toml:"-"` // loaded Secrets, filled by playbook
}

Cmd defines a single command. Yaml parsing is custom, because we want to allow "copy" to accept both single and multiple values

func (*Cmd) GetScript

func (cmd *Cmd) GetScript() (command string, rdr io.Reader)

GetScript returns a script string and an io.Reader based on the command being single line or multiline.

func (*Cmd) UnmarshalYAML

func (cmd *Cmd) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler interface It allows to unmarshal a "copy" from a single field or a slice All other fields are unmarshalled as usual. Limited to string, in, struct, slice or map

type CmdOptions

type CmdOptions struct {
	IgnoreErrors bool     `yaml:"ignore_errors" toml:"ignore_errors"`
	NoAuto       bool     `yaml:"no_auto" toml:"no_auto"`
	Local        bool     `yaml:"local" toml:"local"`
	Sudo         bool     `yaml:"sudo" toml:"sudo"`
	Secrets      []string `yaml:"secrets" toml:"secrets"`
}

CmdOptions defines options for a command

type CopyInternal

type CopyInternal struct {
	Source string `yaml:"src" toml:"src"`
	Dest   string `yaml:"dst" toml:"dst"`
	Mkdir  bool   `yaml:"mkdir" toml:"mkdir"`
}

CopyInternal defines copy command, implemented internally

type DeleteInternal

type DeleteInternal struct {
	Location  string `yaml:"path" toml:"path"`
	Recursive bool   `yaml:"recur" toml:"recur"`
}

DeleteInternal defines delete command, implemented internally

type Destination

type Destination struct {
	Name string   `yaml:"name" toml:"name"`
	Host string   `yaml:"host" toml:"host"`
	Port int      `yaml:"port" toml:"port"`
	User string   `yaml:"user" toml:"user"`
	Tags []string `yaml:"tags" toml:"tags"`
}

Destination defines destination info

type InventoryData

type InventoryData struct {
	Groups map[string][]Destination `yaml:"groups" toml:"groups"`
	Hosts  []Destination            `yaml:"hosts" toml:"hosts"`
}

InventoryData defines inventory data format

type Overrides

type Overrides struct {
	User         string
	Inventory    string
	Environment  map[string]string
	AdHocCommand string
}

Overrides defines override for task passed from cli

type PlayBook

type PlayBook struct {
	User      string            `yaml:"user" toml:"user"`           // ssh user
	SSHKey    string            `yaml:"ssh_key" toml:"ssh_key"`     // ssh key
	Inventory string            `yaml:"inventory" toml:"inventory"` // inventory file or url
	Targets   map[string]Target `yaml:"targets" toml:"targets"`     // list of targets/environments
	Tasks     []Task            `yaml:"tasks" toml:"tasks"`         // list of tasks
	// contains filtered or unexported fields
}

PlayBook defines top-level config object

func New

func New(fname string, overrides *Overrides, secProvider SecretsProvider) (res *PlayBook, err error)

New makes new config from yml

func (*PlayBook) AllSecretValues

func (p *PlayBook) AllSecretValues() []string

AllSecretValues returns all secret values from all tasks and all commands. It is used to mask Secrets in logs.

func (*PlayBook) TargetHosts

func (p *PlayBook) TargetHosts(name string) ([]Destination, error)

TargetHosts returns target hosts for given target name. After it gets destinations from targetHosts(name) it applies overrides of user, set default port 22 if needed and deduplicate results.

func (*PlayBook) Task

func (p *PlayBook) Task(name string) (*Task, error)

Task returns task by name

type SecretsProvider

type SecretsProvider interface {
	Get(key string) (string, error)
}

SecretsProvider defines interface for secrets providers

type SimplePlayBook

type SimplePlayBook struct {
	User      string   `yaml:"user" toml:"user"`           // ssh user
	SSHKey    string   `yaml:"ssh_key" toml:"ssh_key"`     // ssh key
	Inventory string   `yaml:"inventory" toml:"inventory"` // inventory file or url
	Targets   []string `yaml:"targets" toml:"targets"`     // list of names
	Task      []Cmd    `yaml:"task" toml:"task"`           // single task is a list of commands
}

SimplePlayBook defines simplified top-level config It is used for unmarshalling only, and result used to make the usual PlayBook

type SyncInternal

type SyncInternal struct {
	Source string `yaml:"src" toml:"src"`
	Dest   string `yaml:"dst" toml:"dst"`
	Delete bool   `yaml:"delete" toml:"delete"`
}

SyncInternal defines sync command (recursive copy), implemented internally

type Target

type Target struct {
	Name   string        `yaml:"name" toml:"name"`     // name of target
	Hosts  []Destination `yaml:"hosts" toml:"hosts"`   // direct list of hosts to run commands on, no need to use inventory
	Groups []string      `yaml:"groups" toml:"groups"` // list of groups to run commands on, matches to inventory
	Names  []string      `yaml:"names" toml:"names"`   // list of host names to run commands on, matches to inventory
	Tags   []string      `yaml:"tags" toml:"tags"`     // list of tags to run commands on, matches to inventory
}

Target defines hosts to run commands on

type Task

type Task struct {
	Name     string `yaml:"name" toml:"name"` // name of target, set by config caller
	User     string `yaml:"user" toml:"user"`
	Commands []Cmd  `yaml:"commands" toml:"commands"`
	OnError  string `yaml:"on_error" toml:"on_error"`
}

Task defines multiple commands runs together

type WaitInternal

type WaitInternal struct {
	Timeout       time.Duration `yaml:"timeout" toml:"timeout"`
	CheckDuration time.Duration `yaml:"interval" toml:"interval"`
	Command       string        `yaml:"cmd" toml:"cmd,multiline"`
}

WaitInternal defines wait command, implemented internally

Directories

Path Synopsis
Package deepcopy makes deep copies of things.
Package deepcopy makes deep copies of things.

Jump to

Keyboard shortcuts

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