Documentation ¶
Index ¶
- type Cmd
- type CmdOptions
- type CopyInternal
- type DeleteInternal
- type Destination
- type InventoryData
- type Overrides
- type PlayBook
- func (p *PlayBook) AllSecretValues() []string
- func (p *PlayBook) AllTasks() []Task
- func (p *PlayBook) TargetHosts(name string) ([]Destination, error)
- func (p *PlayBook) Task(name string) (*Task, error)
- func (p *PlayBook) UpdateRegisteredVars(vars map[string]string)
- func (p *PlayBook) UpdateTasksTargets(vars map[string]string)
- type SecretsProvider
- type SimplePlayBook
- type SyncInternal
- type Target
- type Task
- type WaitInternal
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"` // multiple copy commands, implemented internally Sync SyncInternal `yaml:"sync" toml:"sync"` MSync []SyncInternal `yaml:"msync" toml:"msync"` // multiple sync commands, implemented internally Delete DeleteInternal `yaml:"delete" toml:"delete"` MDelete []DeleteInternal `yaml:"mdelete" toml:"mdelete"` // multiple delete commands, implemented internally Wait WaitInternal `yaml:"wait" toml:"wait"` Script string `yaml:"script" toml:"script,multiline"` Echo string `yaml:"echo" toml:"echo"` Environment map[string]string `yaml:"env" toml:"env"` Options CmdOptions `yaml:"options" toml:"options,omitempty"` Condition string `yaml:"cond" toml:"cond,omitempty"` Register []string `yaml:"register" toml:"register"` // register variables from command OnExit string `yaml:"on_exit" toml:"on_exit"` // script to run on exit Secrets map[string]string `yaml:"-" toml:"-"` // loaded secrets, filled by playbook SSHShell string `yaml:"-" toml:"-"` // shell to use for ssh commands, filled by playbook LocalShell string `yaml:"-" toml:"-"` // shell to use for local commands, filled by playbooks }
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", "sync" and "delete" from a single field or a slice All other fields are unmarshalled as usual.
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"` // source must be a file or a glob pattern Dest string `yaml:"dst" toml:"dst"` // destination must be a file or a directory Mkdir bool `yaml:"mkdir" toml:"mkdir"` // create destination directory if it does not exist Force bool `yaml:"force" toml:"force"` // force copy even if source and destination are the same Exclude []string `yaml:"exclude" toml:"exclude"` // exclude files matching these patterns ChmodX bool `yaml:"chmod+x" toml:"chmod+x"` // chmod +x on destination file }
CopyInternal defines copy command, implemented internally
type DeleteInternal ¶
type DeleteInternal struct { Location string `yaml:"path" toml:"path"` Recursive bool `yaml:"recur" toml:"recur"` Exclude []string `yaml:"exclude" toml:"exclude"` }
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 SSHShell 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 SSHShell string `yaml:"ssh_shell" toml:"ssh_shell"` // ssh shell to use LocalShell string `yaml:"local_shell" toml:"local_shell"` // local shell to use 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) AllTasks ¶ added in v1.6.0
AllTasks returns the playbook's list of tasks. This method performs a deep copy of the tasks to avoid side effects of overrides on the original config.
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) UpdateRegisteredVars ¶ added in v1.16.0
UpdateRegisteredVars takes the list of registered vars from the caller handling task execution and updates the environment variables of all commands in the playbook with the values from the list.
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 SSHShell string `yaml:"ssh_shell" toml:"ssh_shell"` // ssh shell to uses LocalShell string `yaml:"local_shell" toml:"local_shell"` // local shell to use 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 Options CmdOptions `yaml:"options" toml:"options,omitempty"` // options for all 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"` // source must be a directory Dest string `yaml:"dst" toml:"dst"` // destination must be a directory Delete bool `yaml:"delete" toml:"delete"` // delete files in destination that are not in source Exclude []string `yaml:"exclude" toml:"exclude"` // exclude files matching these patterns Force bool `yaml:"force" toml:"force"` // force sync even if source and destination are the same }
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 Options CmdOptions `yaml:"options" toml:"options,omitempty"` // options for all commands }
Task defines multiple commands runs together