Documentation
¶
Index ¶
- Constants
- type FactDefinition
- type InstallOptions
- type InstallResult
- type PackageInstaller
- type PuppetInstaller
- func (pi *PuppetInstaller) GenerateInstallScript(os string, _ map[string]string) ([]string, error)
- func (pi *PuppetInstaller) GenerateInstallScriptWithAutoDetect(ctx context.Context, instance *cloud.Instance, provider cloud.CloudProvider, ...) ([]string, error)
- func (*PuppetInstaller) GetFailureTags(_ error) map[string]string
- func (pi *PuppetInstaller) GetInstallMetadata() map[string]string
- func (*PuppetInstaller) GetSuccessTags() map[string]string
- func (*PuppetInstaller) Name() string
- func (pi *PuppetInstaller) ValidatePrerequisites(ctx context.Context, instance *cloud.Instance, provider cloud.CloudProvider) error
- func (*PuppetInstaller) VerifyInstallation(ctx context.Context, instance *cloud.Instance, provider cloud.CloudProvider) error
- type PuppetOptions
Constants ¶
const ( OSTypeDebian = "debian" OSTypeRHEL = "rhel" )
OS type constants for normalized OS detection
const DefaultSSMTimeout = 30 * time.Second
Default timeout for SSM commands (AWS SSM requires minimum 30 seconds)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FactDefinition ¶
type FactDefinition struct {
// FilePath is the filename (e.g., "location.yaml")
FilePath string
// FactName is the top-level key in the YAML file (e.g., "location")
FactName string
// Fields maps CSV column names to fact field names
// Example: {"account": "account", "environment": "environment"}
Fields map[string]string
}
FactDefinition defines a custom fact file to be created on the instance. Facts are stored in /opt/puppetlabs/facter/facts.d/ and read by Facter.
Example:
FactDefinition{
FilePath: "location.yaml",
FactName: "location",
Fields: map[string]string{
"account": "account",
"environment": "environment",
},
}
type InstallOptions ¶
type InstallOptions struct {
// DryRun simulates installation without executing real commands
DryRun bool
// SkipValidation skips prerequisite validations (use with caution!)
SkipValidation bool
// SkipTagging doesn't apply tags after installation (useful for testing)
SkipTagging bool
// MaxConcurrency defines maximum number of simultaneous installations
MaxConcurrency int
// Timeout global timeout per installation
Timeout time.Duration
// CustomOptions package-specific options
// E.g., for Puppet: {"server": "puppet.example.com", "environment": "production"}
CustomOptions map[string]string
}
InstallOptions contains generic installation options. Used to pass common configurations between all installers.
type InstallResult ¶
type InstallResult struct {
Instance *cloud.Instance // Instance where it was installed
Success bool // true if installation was successful
Error error // Error if it failed
Duration time.Duration // Time it took
Output string // Output of executed commands
StartTime time.Time // When it started
EndTime time.Time // When it finished
Tagged bool // true if tags were applied successfully
}
InstallResult represents the result of an installation
func (*InstallResult) String ¶
func (ir *InstallResult) String() string
String returns readable representation of the result
type PackageInstaller ¶
type PackageInstaller interface {
// Name returns the package name (puppet, docker, kubernetes-agent, etc)
Name() string
// GenerateInstallScript generates installation script based on the operating system.
// os: detected operating system (ubuntu, debian, rhel, amzn)
// options: custom options (version, specific configurations)
// Returns: slice of shell commands to execute
GenerateInstallScript(os string, options map[string]string) ([]string, error)
// ValidatePrerequisites validates prerequisites BEFORE installing.
// E.g., Puppet needs to validate connectivity with Puppet Server
// E.g., Docker can validate if there are sufficient resources
// Returns error if any prerequisite is not met.
ValidatePrerequisites(ctx context.Context, instance *cloud.Instance, provider cloud.CloudProvider) error
// VerifyInstallation verifies if installation was successful.
// E.g., execute 'puppet --version' and verify exit code
// E.g., execute 'docker ps' and verify it works
// Returns error if verification fails.
VerifyInstallation(ctx context.Context, instance *cloud.Instance, provider cloud.CloudProvider) error
// GetSuccessTags returns tags that should be applied after successful installation.
// E.g., puppet=true, puppet_server=puppet.example.com, puppet_installed_at=2025-01-15
// This marks the instance and enables idempotency (don't reinstall).
GetSuccessTags() map[string]string
// GetFailureTags returns tags to apply when installation fails (optional).
// E.g., puppet=failed, puppet_error=connection_timeout
// Useful for troubleshooting and later retry.
GetFailureTags(err error) map[string]string
// GetInstallMetadata returns metadata from the last installation attempt.
// E.g., os=rhel, certname=abc123.puppet, certname_preserved=true
// Used for reporting and auditing purposes.
// Returns empty map if no installation attempt was made yet.
GetInstallMetadata() map[string]string
}
PackageInstaller abstracts the installation of any package/software. Each package (Puppet, Docker, K8s agent, etc) implements this interface. This is the STRATEGY PATTERN in Go - different installation strategies.
type PuppetInstaller ¶
type PuppetInstaller struct {
// contains filtered or unexported fields
}
PuppetInstaller implements PackageInstaller for Puppet Agent. Supports Debian/Ubuntu and RHEL/Amazon Linux distributions.
func NewPuppetInstaller ¶
func NewPuppetInstaller(opts PuppetOptions) *PuppetInstaller
NewPuppetInstaller creates a new Puppet installer with given options.
func (*PuppetInstaller) GenerateInstallScript ¶
GenerateInstallScript generates installation script based on OS. Supports: debian (for Debian/Ubuntu) and rhel (for RHEL/CentOS/Amazon Linux).
The script will: 1. Detect OS version 2. Install Puppet repository 3. Install puppet-agent package 4. Configure puppet.conf with unique certname 5. Enable and start puppet service 6. Run initial puppet agent
Note: For automatic OS detection, use GenerateInstallScriptWithAutoDetect instead.
func (*PuppetInstaller) GenerateInstallScriptWithAutoDetect ¶
func (pi *PuppetInstaller) GenerateInstallScriptWithAutoDetect(ctx context.Context, instance *cloud.Instance, provider cloud.CloudProvider, _ map[string]string) ([]string, error)
GenerateInstallScriptWithAutoDetect generates installation script with automatic OS detection. This is a convenience method that detects the OS and then calls GenerateInstallScript. Use this method when you want automatic OS detection instead of providing it manually.
func (*PuppetInstaller) GetFailureTags ¶
func (*PuppetInstaller) GetFailureTags(_ error) map[string]string
GetFailureTags returns tags to apply when installation fails. Currently returns empty map as connectivity validation already indicates if puppet is not managing the instance.
func (*PuppetInstaller) GetInstallMetadata ¶
func (pi *PuppetInstaller) GetInstallMetadata() map[string]string
GetInstallMetadata returns metadata from the last installation attempt. Metadata includes:
- os: detected operating system (debian, rhel)
- certname: Puppet certname used for installation
- certname_preserved: "true" if certname was preserved from existing installation, "false" if newly generated
Returns empty map if no installation attempt was made yet.
func (*PuppetInstaller) GetSuccessTags ¶
func (*PuppetInstaller) GetSuccessTags() map[string]string
GetSuccessTags returns tags to apply after successful installation. Tags include:
- puppet: "true"
GetSuccessTags returns tags to apply after successful installation. Currently only applies the basic puppet=true tag. Additional tags can be added later if needed.
func (*PuppetInstaller) ValidatePrerequisites ¶
func (pi *PuppetInstaller) ValidatePrerequisites(ctx context.Context, instance *cloud.Instance, provider cloud.CloudProvider) error
ValidatePrerequisites validates prerequisites before installation. For Puppet, we check: 1. Instance is accessible (SSM connectivity) 2. Instance can reach Puppet Server on configured port
func (*PuppetInstaller) VerifyInstallation ¶
func (*PuppetInstaller) VerifyInstallation(ctx context.Context, instance *cloud.Instance, provider cloud.CloudProvider) error
VerifyInstallation verifies that Puppet was installed successfully. Checks: 1. Puppet binary exists and is executable 2. Puppet service is active 3. Can execute 'puppet --version' successfully
type PuppetOptions ¶
type PuppetOptions struct {
Server string // Puppet Server hostname (required)
Port int // Puppet Server port (default: 8140)
Version string // Puppet version (default: "7")
Environment string // Puppet environment (default: "production")
CustomFacts map[string]FactDefinition // Custom facts to create on instances (optional)
}
PuppetOptions contains Puppet-specific installation options.