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"` Condition string `yaml:"cond" toml:"cond,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) GetCondition ¶ added in v1.1.0
GetCondition returns a condition command as a string and an io.Reader based on whether the command is a single line or multiline
func (*Cmd) GetScript ¶
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
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 ¶
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"` // ignore errors and continue NoAuto bool `yaml:"no_auto" toml:"no_auto"` // don't run command automatically Local bool `yaml:"local" toml:"local"` // run command on localhost Sudo bool `yaml:"sudo" toml:"sudo"` // run command with sudo Secrets []string `yaml:"secrets" toml:"secrets"` // list of secrets (keys) to load OnlyOn []string `yaml:"only_on" toml:"only_on"` // only run on these hosts }
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 the 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 ¶
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.
func (*PlayBook) Task ¶
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.
func (*PlayBook) UpdateTasksTargets ¶ added in v1.1.0
UpdateTasksTargets updates the targets of all tasks in the playbook with the values from the specified map of variables. The method is used to replace variables in the targets of tasks with their actual values and this way provide dynamic targets.
type SecretsProvider ¶
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 Target string `yaml:"target" toml:"target"` // a single target to run task on 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:"-" toml:"-"` // name of target, set from the map key 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 task, mandatory User string `yaml:"user" toml:"user"` Commands []Cmd `yaml:"commands" toml:"commands"` OnError string `yaml:"on_error" toml:"on_error"` Targets []string `yaml:"targets" toml:"targets"` // optional list of targets to run task on, names or groups }
Task defines multiple commands runs together