pkg

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: GPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllowedFacts = map[string]struct{}{
	"platform":                           {},
	"user":                               {},
	"inventory_hostname":                 {},
	"ssh_host_pub_keys":                  {},
	"inventory_hostname_short":           {},
	"ansible_distribution":               {},
	"ansible_distribution_major_version": {},
	"ansible_os_family":                  {},
}

Facts that can be gathered by the setup module

View Source
var SpecialVars = []string{
	"previous",
}

Don't look for dependencies for these vars

Functions

func ChangeCWDToPlaybookDir added in v1.0.0

func ChangeCWDToPlaybookDir(playbookPath string) (string, error)

func CheckIfVariableIsUnused added in v1.0.0

func CheckIfVariableIsUnused(s string) bool

CheckIfVariableIsUnused returns true if the template string uses the default() pattern anywhere. This allows treating variables inside such expressions as optional (no graph dependency).

func ClearSourceFSForCLI added in v1.0.0

func ClearSourceFSForCLI()

func ConvertOutputToFactsMap

func ConvertOutputToFactsMap(output ModuleOutput) interface{}

func EvaluateExpression

func EvaluateExpression(s string, closure *Closure) (interface{}, error)

func ExecuteGraph

func ExecuteGraph(executor GraphExecutor, graph *Graph, inventoryFile string, cfg *config.Config, daemonClientInterface interface{}) error

func ExecuteGraphWithLimit added in v1.0.0

func ExecuteGraphWithLimit(executor GraphExecutor, graph *Graph, inventoryFile string, cfg *config.Config, daemonClientInterface interface{}, limitPattern string) error

func GenerateUnifiedDiff added in v1.0.0

func GenerateUnifiedDiff(filePath, originalContent, newContent string) (string, error)

GenerateUnifiedDiff creates a unified diff string between two text contents.

func GetContextForRun added in v1.0.0

func GetContextForRun(inventory *Inventory, graph *Graph, cfg *config.Config) (map[string]*HostContext, error)

func GetHostContexts

func GetHostContexts(inventory *Inventory, graph *Graph, cfg *config.Config) (map[string]*HostContext, error)

Execute implements the main execution loop for a Spage graph.

func GetOrderedGraph

func GetOrderedGraph(cfg *config.Config, graph *Graph) ([][]GraphNode, error)

func GetVariableUsageFromModule

func GetVariableUsageFromModule(input ConcreteModuleInputProvider) ([]string, error)

func GetVariableUsageFromTemplate

func GetVariableUsageFromTemplate(s string) []string

func Indent

func Indent(n int) string

func IsAnsibleVaultString added in v1.0.0

func IsAnsibleVaultString(yamlContent string) bool

func JinjaStringToStringList added in v1.0.0

func JinjaStringToStringList(jinjaStr string) ([]string, error)

JinjaStringToStringList Evaluate string list "['abc', 'def']" into Golang []string{"abc", "def"}

func ListRegisteredModules added in v1.0.0

func ListRegisteredModules() map[string]BaseModule

ListRegisteredModules returns a copy of the registered modules map. This function is useful for tooling like documentation generators that need to introspect available modules without mutating the registry.

func MapToSyncMap

func MapToSyncMap(m map[string]interface{}) *sync.Map

Helper function to convert map[string]interface{} to *sync.Map

func ParsePlayAttributes added in v1.0.0

func ParsePlayAttributes(blocks []map[string]interface{}) (map[string]interface{}, error)

func ProcessRecursive added in v1.0.0

func ProcessRecursive(originalVal reflect.Value, closure *Closure) (reflect.Value, error)

ProcessRecursive is the core recursive function that creates a new reflect.Value based on originalVal, with string fields templated. It returns a new reflect.Value representing the copied and processed value, or an error.

func ReadLocalFile

func ReadLocalFile(filename string) (string, error)

func ReadSourceFile added in v1.0.0

func ReadSourceFile(filename string) (string, error)

ReadSourceFile reads a file that may be part of the source bundle FS (if configured), falling back to the local filesystem.

func ReadTemplateFile

func ReadTemplateFile(filename string) (string, error)

func RegisterMetaModule added in v1.0.0

func RegisterMetaModule(name string, module MetaModule)

RegisterModule allows modules to register themselves by name.

func RegisterModule

func RegisterModule(name string, module Module)

RegisterModule allows modules to register themselves by name.

func RegisterVariableIfNeeded

func RegisterVariableIfNeeded(result TaskResult, task Task, c *Closure)

func ReportPlayCompletion added in v1.0.0

func ReportPlayCompletion(client *daemon.Client) error

func ReportPlayError added in v1.0.0

func ReportPlayError(client *daemon.Client, err error) error

func ReportPlayStart added in v1.0.0

func ReportPlayStart(client *daemon.Client, playbook, inventory, executor string) error

func ReportTaskCompletion added in v1.0.0

func ReportTaskCompletion(client *daemon.Client, task Task, result TaskResult, hostName string, executionLevel int) error

ReportTaskCompletion reports the completion of a task with metrics

func ReportTaskSkipped added in v1.0.0

func ReportTaskSkipped(client *daemon.Client, taskId int, taskName, hostName string, executionLevel int) error

func ReportTaskStart added in v1.0.0

func ReportTaskStart(client *daemon.Client, taskId int, taskName, hostName string, executionLevel int) error

ReportTaskStart reports the start of a task execution

func ResolveExecutionLevel

func ResolveExecutionLevel(task GraphNode, taskNameMapping map[string]GraphNode, dependsOn map[string][]string, executedOnStep map[int]int) map[int]int

func SetSourceFSForCLI added in v1.0.0

func SetSourceFSForCLI(fsys fs.FS)

Exported wrappers used by CLI without exposing internals elsewhere

func ShouldShowDiff added in v1.0.0

func ShouldShowDiff(closure *Closure) bool

ShouldShowDiff determines if diff output should be displayed based on: 1. Global ansible_diff setting (set by --diff flag or task level setting) 2. Task-level diff setting (overrides global setting)

func TemplateString

func TemplateString(s string, closure *Closure) (string, error)

TemplateString processes a Jinja2 template string with provided variables.

func WaitForPendingReportsWithTimeout added in v1.0.0

func WaitForPendingReportsWithTimeout(timeout time.Duration) error

WaitForPendingReportsWithTimeout waits for all pending daemon reports to complete with a timeout to prevent indefinite hanging

Types

type AnsibleVaultString added in v1.0.0

type AnsibleVaultString struct {
	FormatId   string `yaml:"format_id"` // Only valid format so far is "$ANSIBLE_VAULT"
	Version    string `yaml:"version"`
	VaultId    string `yaml:"vault_id"` // Version 1.2 only, optionally
	CipherText string `yaml:"ciphertext"`
}

AnsibleVaultString is a struct that represents an Ansible vault string, like $ANSIBLE_VAULT;1.2;AES256;some-vault-id 623133...

func Encrypt added in v1.0.0

func Encrypt(plaintext, password string) (*AnsibleVaultString, error)

func NewAnsibleVaultString added in v1.0.0

func NewAnsibleVaultString(yamlContent string) (*AnsibleVaultString, error)

func (AnsibleVaultString) Decrypt added in v1.0.0

func (a AnsibleVaultString) Decrypt(password string) (string, error)

type BaseModule added in v1.0.0

type BaseModule interface {
	InputType() reflect.Type
	OutputType() reflect.Type
	ParameterAliases() map[string]string
}

type Closure

type Closure struct {
	HostContext *HostContext
	ExtraFacts  map[string]interface{}
	Config      *config.Config
}

func (*Closure) Clone added in v1.0.0

func (c *Closure) Clone() *Closure

func (*Closure) GetFact

func (c *Closure) GetFact(key string) (interface{}, bool)

func (*Closure) GetFacts

func (c *Closure) GetFacts() map[string]interface{}

func (*Closure) IsCheckMode added in v1.0.0

func (c *Closure) IsCheckMode() bool

IsCheckMode returns true if ansible_check_mode fact is set to true

type ConcreteModuleInputProvider

type ConcreteModuleInputProvider interface {
	ToCode() string
	GetVariableUsage() []string
	Validate() error
	// HasRevert indicates if this input defines a revert action.
	HasRevert() bool
	// ProvidesVariables returns a list of variable names this input might define (e.g., keys in set_fact).
	ProvidesVariables() []string
}

ModuleInput is a marker interface for module input parameters. It ensures that module parameters have a method to generate their code representation.

func TemplateModuleInputFields

func TemplateModuleInputFields(originalProvider ConcreteModuleInputProvider, closure *Closure) (ConcreteModuleInputProvider, error)

TemplateModuleInputFields creates a *copy* of the input provider's underlying struct, walking all string fields in the copied struct (recursively) and templates them. The original input struct is NOT mutated. It accepts a ConcreteModuleInputProvider and returns a new ConcreteModuleInputProvider of the same underlying kind (value or pointer) as the input, or an error.

type FactProvider

type FactProvider interface {
	AsFacts() map[string]interface{}
}

FactProvider is an interface that module outputs can implement to provide a map representation suitable for registering as facts.

type GenericMapOutput added in v1.0.0

type GenericMapOutput map[string]interface{}

GenericMapOutput provides a generic, map-based implementation of ModuleOutput. This is useful for reconstructing ModuleOutput from history where type information may have been lost.

func (GenericMapOutput) Changed added in v1.0.0

func (g GenericMapOutput) Changed() bool

Changed checks for a "changed" key in the map.

func (GenericMapOutput) String added in v1.0.0

func (g GenericMapOutput) String() string

String provides a simple string representation of the map.

type GenericOutput added in v1.0.0

type GenericOutput map[string]interface{}

GenericOutput is a flexible map-based implementation of pkg.ModuleOutput.

func (GenericOutput) Changed added in v1.0.0

func (g GenericOutput) Changed() bool

Changed checks for a "changed" key in the map.

func (GenericOutput) Facts added in v1.0.0

func (g GenericOutput) Facts() map[string]interface{}

Facts returns the output map itself, so all keys become facts.

func (GenericOutput) String added in v1.0.0

func (g GenericOutput) String() string

String provides a simple string representation of the map.

type Graph

type Graph struct {
	RequiredInputs []string
	Nodes          [][]GraphNode
	Handlers       []GraphNode
	Vars           map[string]interface{}
	PlaybookPath   string
}

func NewGraph

func NewGraph(nodes []GraphNode, graphAttributes map[string]interface{}, playbookPath string) (Graph, error)

func NewGraphFromFS added in v1.0.0

func NewGraphFromFS(sourceFS fs.FS, playbookPath string, rolesPaths string) (Graph, error)

NewGraphFromFS builds a graph from a playbook path within an fs.FS. The playbookPath must be the POSIX-style path inside the provided FS.

func NewGraphFromFile

func NewGraphFromFile(playbookPath string, rolesPaths string) (Graph, error)

func (Graph) CheckForRequiredInputs added in v1.0.0

func (g Graph) CheckForRequiredInputs(hostContexts map[string]*HostContext) error

func (Graph) MarshalJSON added in v1.0.0

func (g Graph) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling for Graph to handle GraphNode interfaces.

func (Graph) ParallelTasks

func (g Graph) ParallelTasks() [][]GraphNode

Order tasks based on execution level

func (Graph) SaveToFile

func (g Graph) SaveToFile(path string) error

func (Graph) SequentialTasks

func (g Graph) SequentialTasks() [][]GraphNode

Order tasks by their id

func (Graph) String

func (g Graph) String() string

func (Graph) ToCode

func (g Graph) ToCode() string

func (*Graph) UnmarshalJSON added in v1.0.0

func (g *Graph) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling for Graph to handle GraphNode interfaces.

type GraphExecutor

type GraphExecutor interface {
	Execute(hostContexts map[string]*HostContext, orderedGraph [][]GraphNode, cfg *config.Config) error
	Revert(ctx context.Context, executedTasks []map[string]chan GraphNode, hostContexts map[string]*HostContext, cfg *config.Config) error
}

GraphExecutor defines the interface for running a Spage graph.

type GraphNode

type GraphNode interface {
	String() string
	ToCode() string
	GetVariableUsage() ([]string, error)
	ConstructClosure(c *HostContext, cfg *config.Config) *Closure
	ExecuteModule(closure *Closure) chan TaskResult
	RevertModule(closure *Closure) chan TaskResult
	ShouldExecute(closure *Closure) (bool, error)
	json.Marshaler

	// Interface marker to point to params
	HasParams
}

GraphNode represents either a list of tasks or a nested graph

func TextToGraphNodes

func TextToGraphNodes(blocks []map[string]interface{}) ([]GraphNode, error)

type Group

type Group = types.Group

type HandlerTracker added in v1.0.0

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

HandlerTracker tracks which handlers have been notified and which have already run

func NewHandlerTracker added in v1.0.0

func NewHandlerTracker(hostName string, handlers []GraphNode) *HandlerTracker

NewHandlerTracker creates a new HandlerTracker for the given host and handlers

func (*HandlerTracker) GetAllHandlers added in v1.0.0

func (ht *HandlerTracker) GetAllHandlers() []GraphNode

GetAllHandlers returns all handlers registered with this tracker

func (*HandlerTracker) GetNotifiedHandlers added in v1.0.0

func (ht *HandlerTracker) GetNotifiedHandlers() []GraphNode

GetNotifiedHandlers returns a list of handlers that have been notified but not yet executed

func (*HandlerTracker) GetStats added in v1.0.0

func (ht *HandlerTracker) GetStats() map[string]interface{}

GetStats returns statistics about handler notifications and executions

func (*HandlerTracker) IsExecuted added in v1.0.0

func (ht *HandlerTracker) IsExecuted(handlerName string) bool

IsExecuted checks if a handler has been executed

func (*HandlerTracker) IsNotified added in v1.0.0

func (ht *HandlerTracker) IsNotified(handlerName string) bool

IsNotified checks if a handler has been notified

func (*HandlerTracker) MarkExecuted added in v1.0.0

func (ht *HandlerTracker) MarkExecuted(handlerName string)

MarkExecuted marks a handler as executed

func (*HandlerTracker) NotifyHandler added in v1.0.0

func (ht *HandlerTracker) NotifyHandler(handlerName string)

NotifyHandler marks a handler as notified

func (*HandlerTracker) NotifyHandlers added in v1.0.0

func (ht *HandlerTracker) NotifyHandlers(handlerNames []string)

NotifyHandlers marks multiple handlers as notified

func (*HandlerTracker) Reset added in v1.0.0

func (ht *HandlerTracker) Reset()

Reset clears all notification and execution status

type HasParams added in v1.0.0

type HasParams interface {
	Params() *TaskParams
}

type Host

type Host = types.Host

type HostContext

type HostContext struct {
	Host           *Host
	Facts          *sync.Map
	History        *sync.Map
	HandlerTracker *HandlerTracker
	// contains filtered or unexported fields
}

HostContext represents the context for a specific host during playbook execution. It contains host-specific data like facts, variables, and SSH connections.

func GetContextForHost added in v1.0.0

func GetContextForHost(inventory *Inventory, host *Host, cfg *config.Config) (*HostContext, error)

GetContextForHost creates a host context from inventory and host data

func InitializeHostContext

func InitializeHostContext(host *Host, cfg *config.Config) (*HostContext, error)

func (*HostContext) Close

func (c *HostContext) Close() error

func (*HostContext) Copy

func (c *HostContext) Copy(src, dst string) error

func (*HostContext) GetOrCreateSSHPool added in v1.0.0

func (c *HostContext) GetOrCreateSSHPool() (*desopssshpool.Pool, error)

GetOrCreateSSHPool returns an existing SSH pool or creates a new one

func (*HostContext) GetOrCreateSftpClient added in v1.0.0

func (c *HostContext) GetOrCreateSftpClient() (*runtime.SftpClient, error)

GetOrCreateSftpClient returns an existing SFTP client or creates a new one using the SSH pool

func (*HostContext) InitializeHandlerTracker added in v1.0.0

func (c *HostContext) InitializeHandlerTracker(handlers []GraphNode)

InitializeHandlerTracker initializes the HandlerTracker with the provided handlers

func (*HostContext) ReadFile

func (c *HostContext) ReadFile(filename string, username string) (string, error)

func (*HostContext) ReadFileBytes

func (c *HostContext) ReadFileBytes(filename string, username string) ([]byte, error)

func (*HostContext) RunCommand

func (c *HostContext) RunCommand(command, username string) (int, string, string, error)

func (*HostContext) RunCommandWithShell added in v1.0.0

func (c *HostContext) RunCommandWithShell(command, username string, useShell bool) (int, string, string, error)

func (*HostContext) SetFileMode

func (c *HostContext) SetFileMode(path, mode, username string) error

func (*HostContext) Stat

func (c *HostContext) Stat(path string, follow bool) (os.FileInfo, error)

func (*HostContext) WriteFile

func (c *HostContext) WriteFile(filename, contents, username string) error

type IgnoredTaskError

type IgnoredTaskError struct {
	OriginalErr error
}

IgnoredTaskError is a custom error type used when a task fails but IgnoreErrors is set to true. It wraps the original error.

func (*IgnoredTaskError) Error

func (e *IgnoredTaskError) Error() string

Error implements the error interface for IgnoredTaskError.

func (*IgnoredTaskError) Unwrap

func (e *IgnoredTaskError) Unwrap() error

Unwrap allows errors.Is and errors.As to work with the wrapped original error.

type Inventory

type Inventory = types.Inventory

Use types from shared package

func LoadInventory

func LoadInventory(path string, cfg *config.Config) (*Inventory, error)

func LoadInventoryWithLimit added in v1.0.0

func LoadInventoryWithLimit(path string, limitPattern string, cfg *config.Config) (*Inventory, error)

func LoadInventoryWithPaths added in v1.0.0

func LoadInventoryWithPaths(path string, inventoryPaths string, workingDir string, limitPattern string, cfg *config.Config) (*Inventory, error)

type JinjaExpression added in v1.0.0

type JinjaExpression struct {
	Expression string
}

func (JinjaExpression) Evaluate added in v1.0.0

func (e JinjaExpression) Evaluate(closure *Closure) (any, error)

func (JinjaExpression) IsEmpty added in v1.0.0

func (e JinjaExpression) IsEmpty() bool

func (JinjaExpression) IsTruthy added in v1.0.0

func (e JinjaExpression) IsTruthy(closure *Closure) bool

func (JinjaExpression) String added in v1.0.0

func (e JinjaExpression) String() string

func (JinjaExpression) ToCode added in v1.0.0

func (e JinjaExpression) ToCode() string

func (*JinjaExpression) UnmarshalJSON added in v1.0.0

func (e *JinjaExpression) UnmarshalJSON(data []byte) error

UnmarshalJSON allows JinjaExpression to be parsed from JSON as a string or bool

func (*JinjaExpression) UnmarshalYAML added in v1.0.0

func (e *JinjaExpression) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML allows JinjaExpression to be parsed from YAML as a string or bool

type JinjaExpressionList added in v1.0.0

type JinjaExpressionList []JinjaExpression

func (JinjaExpressionList) IsEmpty added in v1.0.0

func (el JinjaExpressionList) IsEmpty() bool

func (JinjaExpressionList) IsTruthy added in v1.0.0

func (el JinjaExpressionList) IsTruthy(closure *Closure) bool

func (JinjaExpressionList) ToCode added in v1.0.0

func (el JinjaExpressionList) ToCode() string

func (*JinjaExpressionList) UnmarshalJSON added in v1.0.0

func (el *JinjaExpressionList) UnmarshalJSON(data []byte) error

UnmarshalJSON for JinjaExpressionList supports both a single value or a list

func (*JinjaExpressionList) UnmarshalYAML added in v1.0.0

func (el *JinjaExpressionList) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML for JinjaExpressionList supports both a single value or a list

type MemFS added in v1.0.0

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

func NewMemFSFromTarGz added in v1.0.0

func NewMemFSFromTarGz(r io.Reader) (*MemFS, error)

NewMemFSFromTarGz builds a MemFS from a tar.gz stream.

func (*MemFS) Open added in v1.0.0

func (m *MemFS) Open(name string) (fs.File, error)

func (*MemFS) Stat added in v1.0.0

func (m *MemFS) Stat(name string) (fs.FileInfo, error)

Stat implements fs.StatFS

type MetaModule added in v1.0.0

type MetaModule interface {
	BaseModule
	EvaluateExecute(task *MetaTask, c *Closure) chan TaskResult
	EvaluateRevert(task *MetaTask, c *Closure) chan TaskResult
}

func GetMetaModule added in v1.0.0

func GetMetaModule(name string) (MetaModule, bool)

GetMetaModule retrieves a registered meta module by name.

type MetaTask added in v1.0.0

type MetaTask struct {
	*TaskParams
	Children []GraphNode `yaml:"children" json:"children"`
	Rescue   []GraphNode `yaml:"rescue,omitempty" json:"rescue,omitempty"`
	Always   []GraphNode `yaml:"always,omitempty" json:"always,omitempty"`
}

func (*MetaTask) ConstructClosure added in v1.0.0

func (mt *MetaTask) ConstructClosure(c *HostContext, cfg *config.Config) *Closure

func (*MetaTask) ExecuteModule added in v1.0.0

func (mt *MetaTask) ExecuteModule(closure *Closure) chan TaskResult

func (*MetaTask) GetId added in v1.0.0

func (mt *MetaTask) GetId() int

func (*MetaTask) GetIsHandler added in v1.0.0

func (mt *MetaTask) GetIsHandler() bool

func (*MetaTask) GetName added in v1.0.0

func (mt *MetaTask) GetName() string

func (*MetaTask) GetTags added in v1.0.0

func (mt *MetaTask) GetTags() []string

func (*MetaTask) GetVariableUsage added in v1.0.0

func (mt *MetaTask) GetVariableUsage() ([]string, error)

func (*MetaTask) MarshalJSON added in v1.0.0

func (mt *MetaTask) MarshalJSON() ([]byte, error)

func (*MetaTask) Params added in v1.0.0

func (mt *MetaTask) Params() *TaskParams

func (*MetaTask) RevertModule added in v1.0.0

func (mt *MetaTask) RevertModule(closure *Closure) chan TaskResult

func (*MetaTask) SetId added in v1.0.0

func (mt *MetaTask) SetId(id int)

func (*MetaTask) ShouldExecute added in v1.0.0

func (mt *MetaTask) ShouldExecute(closure *Closure) (bool, error)

func (*MetaTask) String added in v1.0.0

func (mt *MetaTask) String() string

func (*MetaTask) ToCode added in v1.0.0

func (mt *MetaTask) ToCode() string

func (*MetaTask) UnmarshalJSON added in v1.0.0

func (mt *MetaTask) UnmarshalJSON(data []byte) error

type Module

type Module interface {
	BaseModule
	Execute(params ConcreteModuleInputProvider, c *Closure, runAs string) (ModuleOutput, error)
	Revert(params ConcreteModuleInputProvider, c *Closure, previous ModuleOutput, runAs string) (ModuleOutput, error)
	ParameterAliases() map[string]string
}

func GetModule

func GetModule(name string) (Module, bool)

GetModule retrieves a registered module by name.

type ModuleDocProvider added in v1.0.0

type ModuleDocProvider interface {
	Doc() string
}

ModuleDocProvider is an optional interface that a Module can implement to provide additional Markdown documentation (description, examples, notes). If implemented, tooling like docgen can surface this content in generated docs.

type ModuleInput

type ModuleInput struct {
	// Actual holds the concrete *ShellInput, *CopyInput, etc.
	// Let the standard marshalers handle this field when marshaling the parent Task struct,
	// using the custom Task MarshalJSON.
	Actual ConcreteModuleInputProvider `json:"actual,omitempty" yaml:"actual,omitempty"`
}

Its primary role is to facilitate correct JSON/YAML marshaling/unmarshaling when it's a field within another struct (like Task).

func (*ModuleInput) GetVariableUsage

func (mi *ModuleInput) GetVariableUsage() []string

GetVariableUsage delegates to the Actual ConcreteModuleInputProvider.

func (*ModuleInput) HasRevert

func (mi *ModuleInput) HasRevert() bool

HasRevert delegates to the Actual ConcreteModuleInputProvider.

func (*ModuleInput) ProvidesVariables

func (mi *ModuleInput) ProvidesVariables() []string

ProvidesVariables delegates to the Actual ConcreteModuleInputProvider.

func (*ModuleInput) ToCode

func (mi *ModuleInput) ToCode() string

ToCode delegates to the Actual ConcreteModuleInputProvider. It's called during code generation, Actual must be populated.

func (*ModuleInput) Validate

func (mi *ModuleInput) Validate() error

Validate delegates to the Actual ConcreteModuleInputProvider.

type ModuleOutput

type ModuleOutput interface {
	Changed() bool
	String() string
}

ModuleOutput is a marker interface for module output results. It ensures that module results can indicate whether they represent a change.

type ParameterDoc added in v1.0.0

type ParameterDoc struct {
	Description string   // Human-readable description
	Required    *bool    // Whether the parameter is required (nil = unspecified)
	Default     string   // Default value rendered as text
	Choices     []string // Enumerated valid values, if applicable
}

ParameterDoc carries additional documentation for a single input parameter. All fields are optional; tooling will merge these with reflected types and comments.

type ParameterDocsProvider added in v1.0.0

type ParameterDocsProvider interface {
	ParameterDocs() map[string]ParameterDoc
}

ParameterDocsProvider is an optional interface that a Module can implement to provide enriched documentation for its input parameters. The map key should be the YAML parameter name (e.g., "name", "state").

type RevertableChange

type RevertableChange[T comparable] struct {
	Before T
	After  T
}

func (RevertableChange[T]) Changed

func (r RevertableChange[T]) Changed() bool

func (RevertableChange[T]) DiffOutput added in v1.0.0

func (r RevertableChange[T]) DiffOutput() (string, error)

type Task

type Task struct {
	*TaskParams
}

func (Task) ConstructClosure added in v1.0.0

func (t Task) ConstructClosure(c *HostContext, cfg *config.Config) *Closure

func (Task) ExecuteModule

func (t Task) ExecuteModule(closure *Closure) chan TaskResult

func (Task) GetId added in v1.0.0

func (t Task) GetId() int

Conform to GraphNode interface

func (Task) GetIsHandler added in v1.0.0

func (t Task) GetIsHandler() bool

func (Task) GetName added in v1.0.0

func (t Task) GetName() string

func (Task) GetTags added in v1.0.0

func (t Task) GetTags() []string

func (Task) GetVariableUsage added in v1.0.0

func (t Task) GetVariableUsage() ([]string, error)

func (Task) MarshalJSON

func (t Task) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Task. This ensures that the Params field is marshaled correctly by handling the Actual field.

func (Task) Params

func (t Task) Params() *TaskParams

func (Task) RevertModule

func (t Task) RevertModule(closure *Closure) chan TaskResult

func (*Task) SetId added in v1.0.0

func (t *Task) SetId(id int)

func (Task) ShouldExecute

func (t Task) ShouldExecute(closure *Closure) (bool, error)

func (Task) String

func (t Task) String() string

func (Task) ToCode

func (t Task) ToCode() string

func (*Task) UnmarshalJSON

func (t *Task) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Task.

type TaskParams added in v1.0.0

type TaskParams struct {
	Id           int                 `yaml:"id" json:"id"`
	Name         string              `yaml:"name" json:"name"`
	Module       string              `yaml:"module" json:"module"`
	Params       ModuleInput         `yaml:"params" json:"params"`
	Validate     string              `yaml:"validate" json:"validate,omitempty"`
	Before       string              `yaml:"before" json:"before,omitempty"`
	After        string              `yaml:"after" json:"after,omitempty"`
	When         JinjaExpressionList `yaml:"when" json:"when,omitempty"`
	Register     string              `yaml:"register" json:"register,omitempty"`
	Become       bool                `yaml:"become" json:"become,omitempty"`
	BecomeUser   string              `yaml:"become_user" json:"become_user,omitempty"`
	IgnoreErrors JinjaExpression     `yaml:"ignore_errors,omitempty" json:"ignore_errors,omitempty"`
	FailedWhen   JinjaExpressionList `yaml:"failed_when,omitempty" json:"failed_when,omitempty"`
	ChangedWhen  JinjaExpressionList `yaml:"changed_when,omitempty" json:"changed_when,omitempty"`
	Loop         interface{}         `yaml:"loop,omitempty" json:"loop,omitempty"`
	DelegateTo   string              `yaml:"delegate_to,omitempty" json:"delegate_to,omitempty"`
	RunOnce      JinjaExpression     `yaml:"run_once,omitempty" json:"run_once,omitempty"`
	NoLog        JinjaExpression     `yaml:"no_log,omitempty" json:"no_log,omitempty"`
	Tags         []string            `yaml:"tags,omitempty" json:"tags,omitempty"`
	Vars         interface{}         `yaml:"vars,omitempty" json:"vars,omitempty"`
	Rescue       []GraphNode         `yaml:"rescue,omitempty" json:"rescue,omitempty"`
	Always       []GraphNode         `yaml:"always,omitempty" json:"always,omitempty"`

	Until   JinjaExpression `yaml:"until,omitempty" json:"until,omitempty"`
	Retries int             `yaml:"retries,omitempty" json:"retries,omitempty"`
	Delay   int             `yaml:"delay,omitempty" json:"delay,omitempty"`

	CheckMode *bool    `yaml:"check_mode,omitempty" json:"check_mode,omitempty"`
	Diff      *bool    `yaml:"diff,omitempty" json:"diff,omitempty"`
	Notify    []string `yaml:"notify,omitempty" json:"notify,omitempty"`
	IsHandler bool     `yaml:"is_handler,omitempty" json:"is_handler,omitempty"`

	// Role context information for resource resolution
	RoleName string `yaml:"_role_name,omitempty" json:"_role_name,omitempty"`
	RolePath string `yaml:"_role_path,omitempty" json:"_role_path,omitempty"`
}

func (TaskParams) GetVariableUsage added in v1.0.0

func (t TaskParams) GetVariableUsage() ([]string, error)

func (*TaskParams) MarshalJSON added in v1.0.0

func (tp *TaskParams) MarshalJSON() ([]byte, error)

func (*TaskParams) ToCode added in v1.0.0

func (tp *TaskParams) ToCode() string

func (*TaskParams) UnmarshalJSON added in v1.0.0

func (tp *TaskParams) UnmarshalJSON(data []byte) error

type TaskResult

type TaskResult struct {
	Output   ModuleOutput
	Error    error // This can now be nil, a normal error, or an IgnoredTaskError
	Closure  *Closure
	Task     GraphNode
	Duration time.Duration
	Status   TaskStatus
	Failed   bool
	Changed  bool
	// ExecutionSpecificOutput can store runner-specific results, e.g., SpageActivityResult for Temporal.
	ExecutionSpecificOutput interface{}
}

Useful for having a single type to pass around in channels

func HandleResult

func HandleResult(r *TaskResult, t Task, c *Closure) TaskResult

type TaskRunner

type TaskRunner interface {
	ExecuteTask(ctx context.Context, task GraphNode, closure *Closure, cfg *config.Config) chan TaskResult
	RevertTask(ctx context.Context, task GraphNode, closure *Closure, cfg *config.Config) chan TaskResult
}

TaskRunner defines an interface for how a single task is executed. This allows the core execution logic to be generic, while the actual task dispatch (local, Temporal activity, etc.) can be specific.

type TaskStatus

type TaskStatus string
const (
	TaskStatusSkipped TaskStatus = "skipped"
	TaskStatusFailed  TaskStatus = "failed"
	TaskStatusChanged TaskStatus = "changed"
	TaskStatusOk      TaskStatus = "ok"
)

func (TaskStatus) String

func (s TaskStatus) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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