config

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: May 10, 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) GetWait added in v0.14.5

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

GetWait returns a wait command as a string and an io.Reader based on whether the command is a 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, int, 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 creates a new PlayBook instance by loading the playbook configuration from the specified file. If the file cannot be found, and an ad-hoc command is specified in the overrides, a fake playbook with the ad-hoc command is created. The method also loads any secrets from the specified secrets provider and the inventory data from the specified location (if set). Returns an error if the playbook configuration cannot be loaded or parsed, or if the inventory data cannot be loaded.

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.

func (*PlayBook) Task

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

Task returns the task with the specified name from the playbook's list of tasks. If the name is "ad-hoc" and an ad-hoc command is specified in the playbook's overrides, a fake task with a single command is created. The method performs a deep copy of the task to avoid side effects of overrides on the original config and also applies any overrides for the user and environment variables to the task and its commands. Returns an error if the task cannot be found or copied.

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