Documentation
¶
Overview ¶
Package bolt is a pragmatic, pure-Go (cgo-free) port of the core of Puppet Bolt — the agentless orchestrator — covering the pieces that are fully deterministic and stdlib-expressible:
- Inventory (inventory.yaml v2): targets, nested groups, per-group and per-target config / facts / vars / features, target uri / name / alias, effective-value resolution through the group hierarchy, and target selection by name, alias, group or glob (Inventory, Group, Target).
- Tasks: task metadata (the Bolt task *.json shape — typed parameters, input_method, supports_noop, implementations, files) plus validation of a set of arguments against the declared parameter types (Task, TaskMetadata, TaskParameter).
- Plans: YAML plans (plan.yaml — parameters and an ordered list of task / command / script / eval / plan / resources / message steps, targets and a return expression), parsed and executed by a step runner (YAMLPlan, Step, Executor.RunYAMLPlan); and Puppet-language (.pp) plans, run through github.com/go-puppet/puppet with the run_task / run_command / run_script / get_targets / apply plan functions dispatched to real targets (Executor.RunPuppetPlan).
- Transports (Transport): a host-local transport (LocalTransport) driven through an injectable CommandRunner seam; a full SSH transport (SSHTransport, pure-Go over golang.org/x/crypto/ssh) that honours the target's config.ssh (user, port, key/password auth, host-key-check, run-as/sudo, tty, tmpdir) and uploads-then-runs scripts and tasks; and a full WinRM transport (WinRMTransport, pure-Go WS-Management/MS-WSMV over net/http with basic, NTLM-negotiate and TLS-client-certificate auth) that honours config.winrm and uploads-then-runs scripts and tasks on Windows.
- apply blocks and the YAML `resources` step: the manifest is compiled to a catalog via github.com/go-puppet/puppet and an apply ResultSet is produced (Executor.ApplyCatalog).
- An executor that runs a command, script or task across a set of targets, collecting a per-target Result into a ResultSet.
Scope and boundaries ¶
The following are honestly bounded rather than silently capped:
- apply execution: Executor.ApplyCatalog compiles the catalog and reports what would be enforced (resource references and count) per target. It does not remotely enforce resources — real enforcement needs a Puppet agent on the target (Bolt's apply_prep model), which is out of scope for the agentless core.
- WinRM Kerberos/CredSSP authentication: only basic, NTLM-negotiate and TLS-client-certificate auth are implemented (transport "basic", "negotiate" and "ssl"). Kerberos ("realm") is rejected with a clear error.
- PuppetDB and other plugin resolvers (`_plugin` inventory references).
Everything here is pure Go with no cgo, so it cross-compiles to and runs on every 64-bit Go target and links into a static binary by default. Non-stdlib dependencies are all pure Go: github.com/go-ruby-yaml/yaml (inventory/plan YAML), golang.org/x/crypto/ssh (the ssh transport), github.com/Azure/go-ntlmssp (WinRM NTLM negotiate) and github.com/go-puppet/puppet (the .pp plan evaluator and catalog compiler).
Index ¶
- type CommandRunner
- type Executor
- func (e *Executor) ApplyCatalog(targets []*Target, cat *catalog.Catalog) ResultSet
- func (e *Executor) RunCommand(targets []*Target, command string) ResultSet
- func (e *Executor) RunPuppetPlan(src, planName string, params map[string]any) (PlanResult, error)
- func (e *Executor) RunScript(targets []*Target, path string, args []string) ResultSet
- func (e *Executor) RunTask(targets []*Target, task *Task, params map[string]any) (ResultSet, error)
- func (e *Executor) RunYAMLPlan(p *YAMLPlan, params map[string]any) (PlanResult, error)
- type FileCopier
- type Group
- type Implementation
- type Inventory
- type LocalTransport
- func (l *LocalTransport) RunCommand(target *Target, command string) Result
- func (l *LocalTransport) RunScript(target *Target, scriptPath string, args []string) Result
- func (l *LocalTransport) RunTask(target *Target, task *Task, params map[string]any) Result
- func (l *LocalTransport) Upload(target *Target, src, dst string) Result
- type OSFileCopier
- type OSRunner
- type PlanParameter
- type PlanResult
- type Result
- type ResultSet
- func (rs ResultSet) Count() int
- func (rs ResultSet) Empty() bool
- func (rs ResultSet) ErrorSet() ResultSet
- func (rs ResultSet) Find(target string) (Result, bool)
- func (rs ResultSet) Names() []string
- func (rs ResultSet) Ok() bool
- func (rs ResultSet) OkSet() ResultSet
- func (rs ResultSet) Results() []Result
- type SSHTransport
- func (s *SSHTransport) RunCommand(target *Target, command string) Result
- func (s *SSHTransport) RunScript(target *Target, scriptPath string, args []string) Result
- func (s *SSHTransport) RunTask(target *Target, task *Task, params map[string]any) Result
- func (s *SSHTransport) Upload(target *Target, src, dst string) Result
- type Step
- type StepKind
- type Target
- type Task
- type TaskMetadata
- type TaskParameter
- type Transport
- type WinRMTransport
- func (t *WinRMTransport) RunCommand(target *Target, command string) Result
- func (t *WinRMTransport) RunScript(target *Target, scriptPath string, args []string) Result
- func (t *WinRMTransport) RunTask(target *Target, task *Task, params map[string]any) Result
- func (t *WinRMTransport) Upload(target *Target, src, dst string) Result
- type YAMLPlan
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandRunner ¶
type CommandRunner interface {
Run(name string, args []string, stdin string) (stdout, stderr string, exitCode int, err error)
}
CommandRunner is the seam through which LocalTransport executes processes. The default implementation (OSRunner) uses os/exec; tests inject a fake so no real process runs. stdin is fed to the process; the returned exit code is the process exit status (non-zero is not an error — err is only for failures to start or run the process).
type Executor ¶
type Executor struct {
Transport Transport
Inventory *Inventory
// TaskLoader resolves a task-step's task by name. Required to run task steps.
TaskLoader func(name string) (*Task, error)
// PlanLoader resolves a plan-step's sub-plan by name. Required to run plan
// steps.
PlanLoader func(name string) (*YAMLPlan, error)
}
Executor runs actions on targets through a Transport and executes YAML plans. Inventory (optional) resolves plan target-specs into Target values; TaskLoader and PlanLoader resolve the task and sub-plan steps of a plan.
func (*Executor) ApplyCatalog ¶
ApplyCatalog applies cat to each target and returns a per-target ResultSet.
Execution boundary: this pure-Go port compiles the catalog (done by github.com/go-puppet/puppet before this point) and produces an apply result describing what would be enforced — the resource references and count — for each target. It does not remotely enforce resources: real enforcement needs a Puppet agent on the target (Bolt's apply_prep model), which is out of scope for the agentless core. The ResultSet is Ok when the catalog is non-empty.
func (*Executor) RunCommand ¶
RunCommand runs command on every target, collecting a ResultSet.
func (*Executor) RunPuppetPlan ¶
RunPuppetPlan runs a Puppet-language (.pp) plan. src is the plan source (`plan name(...) { ... }`); planName is the fully-qualified plan to invoke; params are its arguments. The plan's run_task / run_command / run_script / get_targets / apply functions are dispatched through this executor's Transport and Inventory against real targets, so a `.pp` plan orchestrates exactly like a YAML plan does.
It returns the plan's return value plus any messages logged by notice()/ warning()/… during the run. Task steps require a Executor.TaskLoader; a plan that calls run_task without one fails with a descriptive error.
func (*Executor) RunTask ¶
RunTask validates params against the task's declared parameters, then runs the task on every target. A validation error is returned before anything runs.
func (*Executor) RunYAMLPlan ¶
RunYAMLPlan executes a parsed YAML plan with the given arguments. It binds parameters (applying defaults and type-checking), runs each step in order, binds each named step's result into the plan scope, and returns the resolved `return` expression plus any message-step output.
type FileCopier ¶
FileCopier is the seam through which LocalTransport.Upload copies files. The default (OSFileCopier) uses the filesystem.
type Group ¶
type Group struct {
Name string
Targets []*Target
Groups []*Group
Config map[string]any
Facts map[string]any
Vars map[string]any
Features []string
// contains filtered or unexported fields
}
Group is a named collection of targets and nested subgroups, carrying config, facts, vars and features inherited by the targets beneath it.
type Implementation ¶
Implementation is one platform-specific implementation of a task.
type Inventory ¶
type Inventory struct {
Version int
// Root is the implicit top-level "all" group holding the inventory's
// top-level targets, groups, config, facts, vars and features.
Root *Group
// contains filtered or unexported fields
}
Inventory is a parsed Bolt inventory (inventory.yaml v2): a tree of groups rooted at a synthetic "all" group, plus a registry of the targets they reference. Targets are deduplicated by name across the whole inventory, so a target listed in several groups is a single Target linked to each.
func ParseInventory ¶
ParseInventory parses an inventory.yaml v2 document.
func (*Inventory) GetOrCreateTarget ¶
GetOrCreateTarget resolves a target by name/alias/uri, registering an ad-hoc target (attached to no group) when none exists. It is how a plan turns a bare target-spec string into a Target.
func (*Inventory) Group ¶
Group finds a group by name anywhere in the tree (depth-first, "all" included).
func (*Inventory) GroupTargets ¶
GroupTargets returns every target in the named group, including those in its subgroups, deduplicated in first-seen order.
type LocalTransport ¶
type LocalTransport struct {
Runner CommandRunner
Copier FileCopier
// Shell is the shell used for command steps; defaults to "sh -c".
Shell string
ShellFlag string
}
LocalTransport runs actions on the host itself. It drives a CommandRunner and a FileCopier so behaviour is deterministic and injectable in tests.
func NewLocalTransport ¶
func NewLocalTransport() *LocalTransport
NewLocalTransport returns a LocalTransport using the OS runner and copier.
func (*LocalTransport) RunCommand ¶
func (l *LocalTransport) RunCommand(target *Target, command string) Result
RunCommand runs command through the configured shell.
func (*LocalTransport) RunScript ¶
func (l *LocalTransport) RunScript(target *Target, scriptPath string, args []string) Result
RunScript runs the script at scriptPath with args.
type OSFileCopier ¶
type OSFileCopier struct{}
OSFileCopier is the default FileCopier; it copies via the filesystem.
func (OSFileCopier) Copy ¶
func (OSFileCopier) Copy(src, dst string) error
Copy copies the file at src to dst.
type OSRunner ¶
type OSRunner struct{}
OSRunner is the default CommandRunner; it shells out through os/exec.
type PlanParameter ¶
PlanParameter describes one declared plan parameter.
type PlanResult ¶
PlanResult is the outcome of running a plan: its return value plus any messages emitted by message steps.
type Result ¶
type Result struct {
Target string
Action string // "command" | "script" | "task" | "upload"
Object string // the command line, script path or task name
Value map[string]any
Err error
}
Result is the outcome of one action (command, script, task or upload) on one target, mirroring Bolt's Result. Value holds the structured output (stdout / stderr / exit_code for a command, or the task's own JSON output); Err is set when the action could not run at all (e.g. the transport failed) as opposed to running and exiting non-zero.
type ResultSet ¶
type ResultSet struct {
// contains filtered or unexported fields
}
ResultSet aggregates the per-target Result values of running one action across several targets.
func NewResultSet ¶
NewResultSet builds a ResultSet from results.
type SSHTransport ¶
type SSHTransport struct {
// Dialer establishes the transport-level connection. It defaults to a
// net.Dialer honouring the target's connect-timeout. Tests inject a dialer
// that reaches an in-process server (and can force connect failures).
Dialer func(ctx context.Context, network, addr string) (net.Conn, error)
// KnownHostsFile is consulted when a target enables host-key-check. Empty
// means host-key-check requires an explicit known-hosts path in config.
KnownHostsFile string
}
SSHTransport runs actions on a target over SSH, mirroring Bolt's ssh transport. It honours the target's effective `config.ssh` block (user, port, private-key/password, host-key-check, run-as/sudo, tty, tmpdir, connect timeout) and implements the full Transport surface:
- RunCommand runs a command through the login shell.
- RunScript uploads the script to a remote temp dir, makes it executable, runs it with arguments, then removes it.
- RunTask uploads the task executable, feeds parameters by the task's input_method (stdin JSON, PT_-prefixed environment, PowerShell, or both), runs it, then removes it.
- Upload copies a local file to a destination via a stdin-streamed write.
The connection itself (dial, auth, host-key verification, exec/upload wire protocol, sudo/su/doas escalation) is github.com/go-remoteexec/transport, shared with go-ansible; this file only resolves Bolt's own config shape and layers Bolt's task-input-method conventions on top.
func NewSSHTransport ¶
func NewSSHTransport() *SSHTransport
NewSSHTransport returns an SSHTransport using a real TCP dialer.
func (*SSHTransport) RunCommand ¶
func (s *SSHTransport) RunCommand(target *Target, command string) Result
RunCommand runs command on the target through its login shell.
func (*SSHTransport) RunScript ¶
func (s *SSHTransport) RunScript(target *Target, scriptPath string, args []string) Result
RunScript uploads the script to the remote temp dir, executes it with args, and removes it afterwards.
func (*SSHTransport) RunTask ¶
RunTask uploads the task executable, feeds it parameters by its input method, runs it, then removes it. A JSON object printed on stdout is merged into the result (matching Bolt and LocalTransport.RunTask).
type Step ¶
type Step struct {
Name string
Kind StepKind
Targets any // string, []string, or "$var" — resolved at run time
Task string // Kind == StepTask
Command string // Kind == StepCommand
Script string // Kind == StepScript
Plan string // Kind == StepPlan
Message any // Kind == StepMessage
Eval any // Kind == StepEval
Parameters map[string]any // task/plan parameters
Arguments []any // script arguments
Resources []any // Kind == StepResources
}
Step is one step of a YAML plan. Only the fields relevant to Kind are set.
type Target ¶
type Target struct {
Name string
URI string
Aliases []string
Config map[string]any
Facts map[string]any
Vars map[string]any
Features []string
// contains filtered or unexported fields
}
Target is a single node the orchestrator can act on. Config, Facts, Vars and Features hold the target's own declared data; the Effective* methods resolve the values seen after group inheritance.
func TargetsForQuery ¶
TargetsForQuery resolves a Bolt-style target query: a comma-separated list of group names, target names/aliases/uris, or globs (matched against target names with path.Match). Results are deduplicated in first-seen order.
func (*Target) EffectiveConfig ¶
EffectiveConfig resolves the target's config after group inheritance: group data merged from least- to most-specific (deep merge of nested mappings), then the target's own config on top.
func (*Target) EffectiveFacts ¶
EffectiveFacts resolves the target's facts after group inheritance.
func (*Target) EffectiveFeatures ¶
EffectiveFeatures resolves the union of the target's own features and those of every group affecting it, in first-seen order.
func (*Target) EffectiveVars ¶
EffectiveVars resolves the target's vars after group inheritance.
type Task ¶
type Task struct {
// Name is the task's fully-qualified name (e.g. "package" or "mymod::run").
Name string
// File is the path to the executable this task runs (the implementation
// selected for the local platform). Empty means the task carries metadata
// only.
File string
// Metadata is the parsed *.json metadata; nil if the task has none.
Metadata *TaskMetadata
}
Task is a Bolt task: a named executable file plus optional metadata declaring its parameters, input method and implementations.
func (*Task) ValidateParams ¶
ValidateParams checks a set of task arguments against the task's declared parameters: it rejects unknown parameters, reports missing required ones (declared, without a default), and type-checks provided values. A task without metadata (or without a parameters block) accepts any arguments.
type TaskMetadata ¶
type TaskMetadata struct {
Description string
Parameters map[string]TaskParameter
InputMethod string
SupportsNoop bool
Implementations []Implementation
Files []string
}
TaskMetadata is the parsed content of a task's *.json metadata file.
func ParseTaskMetadata ¶
func ParseTaskMetadata(src []byte) (*TaskMetadata, error)
ParseTaskMetadata parses a task's *.json metadata.
func (*TaskMetadata) ParameterNames ¶
func (md *TaskMetadata) ParameterNames() []string
ParameterNames returns the declared parameter names in sorted order.
type TaskParameter ¶
type TaskParameter struct {
Type string
Description string
Sensitive bool
Default any
HasDefault bool
}
TaskParameter describes one declared task parameter.
type Transport ¶
type Transport interface {
// RunCommand runs a shell command on the target.
RunCommand(target *Target, command string) Result
// RunScript uploads and runs a script with arguments on the target.
RunScript(target *Target, scriptPath string, args []string) Result
// RunTask runs a task with parameters on the target.
RunTask(target *Target, task *Task, params map[string]any) Result
// Upload copies a local file/directory to a destination on the target.
Upload(target *Target, src, dst string) Result
}
Transport runs actions on a target. It is implemented by LocalTransport, SSHTransport and WinRMTransport; the interface is the extension point for any further transport.
type WinRMTransport ¶
type WinRMTransport struct {
// NewDoer builds the HTTP client used to reach a target. Defaults to
// the shared transport's own client. Tests inject a doer that reaches
// an in-process WS-Man server (and can force connect/auth failures).
NewDoer func(remoteexec.WinRMConfig) (remoteexec.HTTPDoer, error)
}
WinRMTransport runs actions on a Windows target over WinRM, mirroring Bolt's winrm transport. It honours the target's effective config.winrm block (host, port, user, password, ssl, ssl-verify, cacert, transport, realm, cert/key, tmpdir, connect-timeout, path) and implements the full Transport surface:
- RunCommand runs a command line through the remote shell.
- RunScript uploads the script to a remote temp dir, runs it (PowerShell for .ps1, directly otherwise) with arguments, then removes it.
- RunTask uploads the task executable, feeds parameters by the task's input_method (stdin JSON, PT_-prefixed shell environment, PowerShell named arguments, or both), runs it, then removes it.
- Upload writes a local file to a destination.
The connection itself (WS-Management wire protocol, NTLM/basic/TLS-client-cert auth) is github.com/go-remoteexec/transport, shared with go-ansible; this file only resolves Bolt's own config shape and layers Bolt's task-input-method conventions on top.
func NewWinRMTransport ¶
func NewWinRMTransport() *WinRMTransport
NewWinRMTransport returns a WinRMTransport using the default HTTP client.
func (*WinRMTransport) RunCommand ¶
func (t *WinRMTransport) RunCommand(target *Target, command string) Result
RunCommand runs command on the target through the remote shell.
func (*WinRMTransport) RunScript ¶
func (t *WinRMTransport) RunScript(target *Target, scriptPath string, args []string) Result
RunScript uploads the script to the remote temp dir, runs it with args, and removes it afterwards.
type YAMLPlan ¶
type YAMLPlan struct {
Description string
Parameters map[string]PlanParameter
ParamOrder []string
Steps []Step
// Return is the plan's return expression (a literal or a "$var" reference),
// or nil when the plan has no return key.
Return any
HasReturn bool
}
YAMLPlan is a parsed Bolt YAML plan (plan.yaml).