runner

package
v1.0.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: ISC Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeParamsForState

func NormalizeParamsForState(source, params, sourceBecome, become map[string]any) map[string]any

func ParamHash

func ParamHash(params map[string]any) string

ParamHash computes a SHA256 hash of the params map as a hex string.

func StateParamHash

func StateParamHash(source, params, sourceBecome, become map[string]any) string

func StateParamSummary

func StateParamSummary(source, params, sourceBecome, become map[string]any) any

func SummarizeParams

func SummarizeParams(params map[string]any) any

SummarizeParams produces a redacted, JSON-friendly summary of parameters for state diff output.

Types

type BoundTask

type BoundTask struct {
	Name   string
	When   string
	Params map[string]any
	Become map[string]any
}

type ComparisonStatus

type ComparisonStatus string
const (
	ComparisonStatusNew        ComparisonStatus = "NEW"
	ComparisonStatusChanged    ComparisonStatus = "CHANGED"
	ComparisonStatusUnchanged  ComparisonStatus = "UNCHANGED"
	ComparisonStatusRemoved    ComparisonStatus = "REMOVED"
	ComparisonStatusStatusOnly ComparisonStatus = "STATUS-ONLY"
)

type Config

type Config struct {
	DryRun                        bool
	Tags                          []string
	SkipTags                      []string
	Concurrency                   int
	ProjectDir                    string
	ProjectName                   string
	ProjectEnv                    string
	ProjectVars                   map[string]any
	InventoryVars                 map[string]any
	Vars                          map[string]any // from --var CLI flags
	TargetVars                    map[string]any
	TargetName                    string
	Phase                         string // "plan", "fetch", "stage", "apply" (empty = all)
	SkipFetch                     bool
	Renderer                      output.Renderer
	Secrets                       *secrets.Resolver
	SecretsConfig                 config.SecretsConfig
	StatePath                     string
	ModuleRegistry                target.ModuleRegistry
	BundleOutputDir               string
	BundlePlugins                 []plugins.LoadedPlugin
	AllowPlaintextSecretsInBundle bool
	Lockfile                      *action.Lockfile
	Version                       string
	Commit                        string
	BuildDate                     string
}

Config holds the options that control runner behavior.

type DAG

type DAG struct {
	// contains filtered or unexported fields
}

DAG is a directed acyclic graph of tasks for dependency-ordered execution.

func BuildDAG

func BuildDAG(tasks []*PlanTask) (*DAG, error)

BuildDAG constructs a DAG from the given tasks. DependsOn values are resolved by canonical dependency refs prepared during planning. Returns an error if a dependency references an unknown task ref or if there is a cycle.

func (*DAG) DependencyIDs

func (d *DAG) DependencyIDs(task *PlanTask) ([]string, error)

DependencyIDs resolves a task's dependency refs to stable task IDs.

func (*DAG) TopologicalOrder

func (d *DAG) TopologicalOrder() []*PlanTask

TopologicalOrder returns tasks in dependency-first execution order.

type ExecutionPlan

type ExecutionPlan struct {
	PlaybookName string
	Tasks        []*PlanTask
	Vars         map[string]any
	// contains filtered or unexported fields
}

ExecutionPlan is the result of the Plan phase: a flat, ordered list of tasks with all variables resolved.

func (*ExecutionPlan) DAG

func (p *ExecutionPlan) DAG() (*DAG, error)

DAG returns the plan's validated dependency graph, rebuilding it only for hand-constructed test plans or older callers that did not come from Plan().

type PlanTask

type PlanTask struct {
	ID           string // unique ID, e.g. "task-0", "task-1"
	Name         string
	Ref          string
	ActionPath   string // human-readable parent path, e.g. "Apply machine baseline/Configure computer name"
	Module       string
	Params       map[string]any
	Become       map[string]any
	TemplateVars map[string]any
	DependsOn    []string
	When         string
	Tags         []string
	IgnoreErrors bool
}

PlanTask is a single task entry in the execution plan.

func PreviewTask

func PreviewTask(task *PlanTask, targetVars map[string]any) (*PlanTask, error)

type PlannedTaskState

type PlannedTaskState struct {
	TaskKey      string
	TaskName     string
	Module       string
	DependsOn    []string
	TaskHash     string
	ParamHash    string
	ParamSummary any
}

func BuildPlannedTaskState

func BuildPlannedTaskState(ctx context.Context, plan *ExecutionPlan, execCtx *executionContext, resolver *secrets.Resolver) ([]PlannedTaskState, error)

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner orchestrates the Plan→Fetch→Stage→Apply pipeline.

func New

func New(t target.Target, resolver action.Chain, cfg Config) *Runner

New creates a new Runner with the given target, resolver chain, and config.

func (*Runner) Apply

func (r *Runner) Apply(ctx context.Context, plan *ExecutionPlan) (err error)

func (*Runner) Fetch

func (r *Runner) Fetch(ctx context.Context, playbook *action.Playbook) error

func (*Runner) Plan

func (r *Runner) Plan(ctx context.Context, playbook *action.Playbook) (*ExecutionPlan, error)

func (*Runner) PlannedTaskState

func (r *Runner) PlannedTaskState(ctx context.Context, plan *ExecutionPlan) ([]PlannedTaskState, error)

PlannedTaskState renders the current plan with execution-time target context so state comparisons use the same task names and params that apply records.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, playbook *action.Playbook) (err error)

Run executes the playbook through the configured phases. If Config.Phase is empty, all phases run in order: plan, fetch, stage, apply. Otherwise only the specified phase runs (plan is always required first).

func (*Runner) Stage

func (r *Runner) Stage(ctx context.Context, plan *ExecutionPlan) (err error)

type SecretValueAnalysis

type SecretValueAnalysis struct {
	RefNames          []string
	HasLiteralSecrets bool
}

func AnalyzeSecretValues

func AnalyzeSecretValues(value any) SecretValueAnalysis

type State

type State struct {
	Version     int                     `json:"version,omitempty"`
	LastApplied time.Time               `json:"last_applied"`
	Tasks       map[string]TaskSnapshot `json:"tasks,omitempty"`
	Results     map[string]TaskResult   `json:"results,omitempty"`
}

State holds persisted runner state written to disk after each apply.

func LoadState

func LoadState(path string) (*State, error)

LoadState reads a state file from path. If the file does not exist, an empty State is returned (not an error).

func (*State) Record

func (s *State) Record(result TaskResult)

Record preserves legacy result-only writes by promoting them to v2 snapshots.

func (*State) RecordTask

func (s *State) RecordTask(snapshot TaskSnapshot)

RecordTask stores a v2 snapshot in the state, keyed by stable task key.

func (*State) Save

func (s *State) Save(path string) error

Save writes the state to path as JSON. The file is written atomically by writing to a temp file and renaming it.

type TaskComparison

type TaskComparison struct {
	Status          ComparisonStatus
	TaskKey         string
	TaskName        string
	Module          string
	RecordedStatus  target.Status
	RecordedSummary any
	PlannedSummary  any
}

func ComparePlannedTasks

func ComparePlannedTasks(planned []PlannedTaskState, state *State) []TaskComparison

type TaskResult

type TaskResult struct {
	TaskID    string        `json:"task_id"`
	TaskName  string        `json:"task_name"`
	Status    target.Status `json:"status"`
	Timestamp time.Time     `json:"timestamp"`
	ParamHash string        `json:"param_hash"`
}

TaskResult is the legacy per-task result shape kept for backward-compatible state loading.

type TaskSnapshot

type TaskSnapshot struct {
	TaskKey      string        `json:"task_key"`
	TaskName     string        `json:"task_name"`
	Module       string        `json:"module,omitempty"`
	DependsOn    []string      `json:"depends_on,omitempty"`
	TaskHash     string        `json:"task_hash,omitempty"`
	ParamHash    string        `json:"param_hash,omitempty"`
	ParamSummary any           `json:"param_summary,omitempty"`
	Status       target.Status `json:"status"`
	Message      string        `json:"message,omitempty"`
	Timestamp    time.Time     `json:"timestamp"`
}

TaskSnapshot is the v2 persisted state model used for comparison and audit.

Jump to

Keyboard shortcuts

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