ansible

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InventoryFormatINI     = "ini"
	InventoryFormatYAML    = "yaml"
	InventorySourcePvetui  = "pvetui"
	InventorySourceProxmox = "community_proxmox"
	InventoryStyleCompact  = "compact"
	InventoryStyleExpanded = "expanded"
)

Variables

This section is empty.

Functions

func NormalizeInventoryFormat

func NormalizeInventoryFormat(format string) string

NormalizeInventoryFormat validates and canonicalizes inventory format.

func NormalizeInventorySource added in v1.4.1

func NormalizeInventorySource(source string) string

NormalizeInventorySource validates and canonicalizes an inventory source.

func NormalizeInventoryStyle

func NormalizeInventoryStyle(style string) string

NormalizeInventoryStyle validates and canonicalizes inventory style.

func SaveInventory

func SaveInventory(path, content string) error

SaveInventory writes inventory text to a user-selected path.

Types

type AdhocOptions added in v1.3.2

type AdhocOptions struct {
	Pattern    string
	Module     string
	ModuleArgs string
	Limit      string
	ExtraArgs  []string
}

AdhocOptions describes ansible ad-hoc module invocation options.

type CommandResult

type CommandResult struct {
	Command  string
	Output   string
	Duration time.Duration
	Err      error
}

CommandResult stores process execution details.

type CommunityProxmoxOptions added in v1.4.1

type CommunityProxmoxOptions struct {
	URL                         string
	User                        string
	TokenID                     string
	Password                    string
	TokenSecret                 string
	NodeSSHUser                 string
	VMSSHUser                   string
	SSHPrivateKeyFile           string
	DefaultPassword             string
	InventoryVars               map[string]string
	ValidateCerts               bool
	WantFacts                   bool
	WantPostFilterFacts         bool
	WantProxmoxNodesAnsibleHost *bool
	ExcludeNodes                bool
	Filters                     []string
	Compose                     map[string]string
	Groups                      map[string]string
	KeyedGroups                 []map[string]string
}

CommunityProxmoxOptions describes a generated community.proxmox.proxmox dynamic inventory source.

type InventoryDefaults

type InventoryDefaults struct {
	NodeSSHUser       string
	VMSSHUser         string
	SSHPrivateKeyFile string
	DefaultPassword   string
	InventoryVars     map[string]string
	Style             string
}

InventoryDefaults defines default SSH users for inventory generation.

type InventoryHost

type InventoryHost struct {
	Alias      string
	Target     string
	GroupNames []string
	Vars       map[string]string
}

InventoryHost captures one generated host entry.

type InventoryResult

type InventoryResult struct {
	Source string
	Format string
	Text   string
	Hosts  []InventoryHost
	Env    map[string]string
}

InventoryResult contains the final inventory text and generated host metadata.

func BuildCommunityProxmoxInventory added in v1.4.1

func BuildCommunityProxmoxInventory(opts CommunityProxmoxOptions) (InventoryResult, error)

BuildCommunityProxmoxInventory renders an Ansible dynamic inventory source for the community.proxmox.proxmox collection. Non-secret connection values are written to the source so it can be reused outside pvetui; secrets are returned as environment variables so they are not written to disk.

func BuildInventory

func BuildInventory(nodes []*api.Node, guests []*api.VM, defaults InventoryDefaults) InventoryResult

BuildInventory renders an INI-style Ansible inventory from Proxmox nodes and guests.

func BuildInventoryWithFormat

func BuildInventoryWithFormat(nodes []*api.Node, guests []*api.VM, defaults InventoryDefaults, format string) InventoryResult

BuildInventoryWithFormat renders an inventory in the requested format.

type OutputLineHandler

type OutputLineHandler func(line string)

OutputLineHandler receives a single line of command output.

type PlaybookOptions

type PlaybookOptions struct {
	PlaybookPath string
	Limit        string
	ExtraArgs    []string
	CheckMode    bool
}

PlaybookOptions describes ansible-playbook invocation options.

type Runner

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

Runner executes local ansible commands.

func NewRunner

func NewRunner() *Runner

NewRunner creates a new command runner.

func (*Runner) CheckAvailability

func (r *Runner) CheckAvailability() error

CheckAvailability verifies that required ansible binaries are available in PATH.

func (*Runner) CheckInventoryAvailability added in v1.4.1

func (r *Runner) CheckInventoryAvailability() error

CheckInventoryAvailability verifies that ansible-inventory is available.

func (*Runner) RunAdhoc added in v1.3.2

func (r *Runner) RunAdhoc(ctx context.Context, inventoryText, inventoryFormat string, opts AdhocOptions) CommandResult

RunAdhoc executes ansible ad-hoc commands with a generated temporary inventory.

func (*Runner) RunAdhocInventory added in v1.4.1

func (r *Runner) RunAdhocInventory(
	ctx context.Context,
	inventory InventoryResult,
	opts AdhocOptions,
	handler OutputLineHandler,
) CommandResult

RunAdhocInventory executes ansible ad-hoc commands with an inventory source.

func (*Runner) RunAdhocStream added in v1.3.2

func (r *Runner) RunAdhocStream(
	ctx context.Context,
	inventoryText,
	inventoryFormat string,
	opts AdhocOptions,
	handler OutputLineHandler,
) CommandResult

RunAdhocStream executes ansible ad-hoc commands and streams output lines when handler is provided.

func (*Runner) RunInventoryList added in v1.4.1

func (r *Runner) RunInventoryList(ctx context.Context, inventory InventoryResult) CommandResult

RunInventoryList resolves an inventory source with ansible-inventory --list.

func (*Runner) RunPing

func (r *Runner) RunPing(ctx context.Context, inventoryText, inventoryFormat, limit string, extraArgs []string) CommandResult

RunPing executes `ansible -m ping` using the generated inventory.

func (*Runner) RunPingStream

func (r *Runner) RunPingStream(
	ctx context.Context,
	inventoryText,
	inventoryFormat,
	limit string,
	extraArgs []string,
	handler OutputLineHandler,
) CommandResult

RunPingStream executes `ansible -m ping` and streams output lines when handler is provided.

func (*Runner) RunPlaybook

func (r *Runner) RunPlaybook(ctx context.Context, inventoryText, inventoryFormat string, opts PlaybookOptions) CommandResult

RunPlaybook executes ansible-playbook with a generated temporary inventory.

func (*Runner) RunPlaybookInventory added in v1.4.1

func (r *Runner) RunPlaybookInventory(
	ctx context.Context,
	inventory InventoryResult,
	opts PlaybookOptions,
	handler OutputLineHandler,
) CommandResult

RunPlaybookInventory executes ansible-playbook with an inventory source.

func (*Runner) RunPlaybookStream

func (r *Runner) RunPlaybookStream(
	ctx context.Context,
	inventoryText,
	inventoryFormat string,
	opts PlaybookOptions,
	handler OutputLineHandler,
) CommandResult

RunPlaybookStream executes ansible-playbook and streams output lines when handler is provided.

func (*Runner) SetEnv added in v1.3.3

func (r *Runner) SetEnv(env map[string]string)

SetEnv merges the provided key/value pairs on top of os.Environ and stores the result so every subsequent ansible invocation inherits them.

Jump to

Keyboard shortcuts

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