alphabetize datastructures

This commit is contained in:
Matthew Patton 2018-05-01 16:38:01 -04:00
parent f5f69df84e
commit 514a597825
2 changed files with 55 additions and 46 deletions

View File

@ -20,21 +20,27 @@ type Config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
ctx interpolate.Context ctx interpolate.Context
// If true, staging directory is removed after executing puppet.
CleanStagingDir bool `mapstructure:"clean_staging_directory"`
// The Guest OS Type (unix or windows)
GuestOSType string `mapstructure:"guest_os_type"`
// The command used to execute Puppet. // The command used to execute Puppet.
ExecuteCommand string `mapstructure:"execute_command"` ExecuteCommand string `mapstructure:"execute_command"`
// Additional arguments to pass when executing Puppet // Additional arguments to pass when executing Puppet
ExtraArguments []string `mapstructure:"extra_arguments"` ExtraArguments []string `mapstructure:"extra_arguments"`
// The Guest OS Type (unix or windows)
GuestOSType string `mapstructure:"guest_os_type"`
// Additional facts to set when executing Puppet // Additional facts to set when executing Puppet
Facter map[string]string Facter map[string]string
// Path to a hiera configuration file to upload and use. // Path to a hiera configuration file to upload and use.
HieraConfigPath string `mapstructure:"hiera_config_path"` HieraConfigPath string `mapstructure:"hiera_config_path"`
// If true, packer will ignore all exit-codes from a puppet run
IgnoreExitCodes bool `mapstructure:"ignore_exit_codes"`
// An array of local paths of modules to upload. // An array of local paths of modules to upload.
ModulePaths []string `mapstructure:"module_paths"` ModulePaths []string `mapstructure:"module_paths"`
@ -48,32 +54,26 @@ type Config struct {
// If true, `sudo` will NOT be used to execute Puppet. // If true, `sudo` will NOT be used to execute Puppet.
PreventSudo bool `mapstructure:"prevent_sudo"` PreventSudo bool `mapstructure:"prevent_sudo"`
// The directory that contains the puppet binary.
// E.g. if it can't be found on the standard path.
PuppetBinDir string `mapstructure:"puppet_bin_dir"`
// The directory where files will be uploaded. Packer requires write // The directory where files will be uploaded. Packer requires write
// permissions in this directory. // permissions in this directory.
StagingDir string `mapstructure:"staging_directory"` StagingDir string `mapstructure:"staging_directory"`
// If true, staging directory is removed after executing puppet.
CleanStagingDir bool `mapstructure:"clean_staging_directory"`
// The directory from which the command will be executed. // The directory from which the command will be executed.
// Packer requires the directory to exist when running puppet. // Packer requires the directory to exist when running puppet.
WorkingDir string `mapstructure:"working_directory"` WorkingDir string `mapstructure:"working_directory"`
// The directory that contains the puppet binary.
// E.g. if it can't be found on the standard path.
PuppetBinDir string `mapstructure:"puppet_bin_dir"`
// If true, packer will ignore all exit-codes from a puppet run
IgnoreExitCodes bool `mapstructure:"ignore_exit_codes"`
} }
type guestOSTypeConfig struct { type guestOSTypeConfig struct {
tempDir string
stagingDir string
executeCommand string executeCommand string
facterVarsFmt string facterVarsFmt string
facterVarsJoiner string facterVarsJoiner string
modulePathJoiner string modulePathJoiner string
stagingDir string
tempDir string
} }
// FIXME assumes both Packer host and target are same OS // FIXME assumes both Packer host and target are same OS
@ -122,6 +122,8 @@ type Provisioner struct {
} }
type ExecuteTemplate struct { type ExecuteTemplate struct {
Debug bool
ExtraArguments string
FacterVars string FacterVars string
HieraConfigPath string HieraConfigPath string
ModulePath string ModulePath string
@ -130,8 +132,6 @@ type ExecuteTemplate struct {
PuppetBinDir string PuppetBinDir string
Sudo bool Sudo bool
WorkingDir string WorkingDir string
Debug bool
ExtraArguments string
} }
func (p *Provisioner) Prepare(raws ...interface{}) error { func (p *Provisioner) Prepare(raws ...interface{}) error {
@ -291,6 +291,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
} }
data := ExecuteTemplate{ data := ExecuteTemplate{
ExtraArguments: "",
FacterVars: strings.Join(facterVars, p.guestOSTypeConfig.facterVarsJoiner), FacterVars: strings.Join(facterVars, p.guestOSTypeConfig.facterVarsJoiner),
HieraConfigPath: remoteHieraConfigPath, HieraConfigPath: remoteHieraConfigPath,
ManifestDir: remoteManifestDir, ManifestDir: remoteManifestDir,
@ -299,7 +300,6 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
PuppetBinDir: p.config.PuppetBinDir, PuppetBinDir: p.config.PuppetBinDir,
Sudo: !p.config.PreventSudo, Sudo: !p.config.PreventSudo,
WorkingDir: p.config.WorkingDir, WorkingDir: p.config.WorkingDir,
ExtraArguments: "",
} }
p.config.ctx.Data = &data p.config.ctx.Data = &data

View File

@ -19,17 +19,8 @@ type Config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
ctx interpolate.Context ctx interpolate.Context
// The command used to execute Puppet. // If true, staging directory is removed after executing puppet.
ExecuteCommand string `mapstructure:"execute_command"` CleanStagingDir bool `mapstructure:"clean_staging_directory"`
// Additional argument to pass when executing Puppet.
ExtraArguments []string `mapstructure:"extra_arguments"`
// The Guest OS Type (unix or windows)
GuestOSType string `mapstructure:"guest_os_type"`
// Additional facts to set when executing Puppet
Facter map[string]string
// A path to the client certificate // A path to the client certificate
ClientCertPath string `mapstructure:"client_cert_path"` ClientCertPath string `mapstructure:"client_cert_path"`
@ -37,15 +28,34 @@ type Config struct {
// A path to a directory containing the client private keys // A path to a directory containing the client private keys
ClientPrivateKeyPath string `mapstructure:"client_private_key_path"` ClientPrivateKeyPath string `mapstructure:"client_private_key_path"`
// The command used to execute Puppet.
ExecuteCommand string `mapstructure:"execute_command"`
// Additional argument to pass when executing Puppet.
ExtraArguments []string `mapstructure:"extra_arguments"`
// Additional facts to set when executing Puppet
Facter map[string]string
// The Guest OS Type (unix or windows)
GuestOSType string `mapstructure:"guest_os_type"`
// If true, packer will ignore all exit-codes from a puppet run
IgnoreExitCodes bool `mapstructure:"ignore_exit_codes"`
// If true, `sudo` will NOT be used to execute Puppet.
PreventSudo bool `mapstructure:"prevent_sudo"`
// The directory that contains the puppet binary.
// E.g. if it can't be found on the standard path.
PuppetBinDir string `mapstructure:"puppet_bin_dir"`
// The hostname of the Puppet node. // The hostname of the Puppet node.
PuppetNode string `mapstructure:"puppet_node"` PuppetNode string `mapstructure:"puppet_node"`
// The hostname of the Puppet server. // The hostname of the Puppet server.
PuppetServer string `mapstructure:"puppet_server"` PuppetServer string `mapstructure:"puppet_server"`
// If true, `sudo` will NOT be used to execute Puppet.
PreventSudo bool `mapstructure:"prevent_sudo"`
// The directory where files will be uploaded. Packer requires write // The directory where files will be uploaded. Packer requires write
// permissions in this directory. // permissions in this directory.
StagingDir string `mapstructure:"staging_dir"` StagingDir string `mapstructure:"staging_dir"`
@ -53,21 +63,14 @@ type Config struct {
// The directory from which the command will be executed. // The directory from which the command will be executed.
// Packer requires the directory to exist when running puppet. // Packer requires the directory to exist when running puppet.
WorkingDir string `mapstructure:"working_directory"` WorkingDir string `mapstructure:"working_directory"`
// The directory that contains the puppet binary.
// E.g. if it can't be found on the standard path.
PuppetBinDir string `mapstructure:"puppet_bin_dir"`
// If true, packer will ignore all exit-codes from a puppet run
IgnoreExitCodes bool `mapstructure:"ignore_exit_codes"`
} }
type guestOSTypeConfig struct { type guestOSTypeConfig struct {
tempDir string
stagingDir string
executeCommand string executeCommand string
facterVarsFmt string facterVarsFmt string
facterVarsJoiner string facterVarsJoiner string
stagingDir string
tempDir string
} }
// FIXME assumes both Packer host and target are same OS // FIXME assumes both Packer host and target are same OS
@ -114,16 +117,16 @@ type Provisioner struct {
} }
type ExecuteTemplate struct { type ExecuteTemplate struct {
FacterVars string
ClientCertPath string ClientCertPath string
ClientPrivateKeyPath string ClientPrivateKeyPath string
Debug bool
ExtraArguments string
FacterVars string
PuppetNode string PuppetNode string
PuppetServer string PuppetServer string
PuppetBinDir string PuppetBinDir string
Sudo bool Sudo bool
WorkingDir string WorkingDir string
Debug bool
ExtraArguments string
} }
func (p *Provisioner) Prepare(raws ...interface{}) error { func (p *Provisioner) Prepare(raws ...interface{}) error {
@ -243,15 +246,15 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
} }
data := ExecuteTemplate{ data := ExecuteTemplate{
FacterVars: strings.Join(facterVars, p.guestOSTypeConfig.facterVarsJoiner),
ClientCertPath: remoteClientCertPath, ClientCertPath: remoteClientCertPath,
ClientPrivateKeyPath: remoteClientPrivateKeyPath, ClientPrivateKeyPath: remoteClientPrivateKeyPath,
ExtraArguments: "",
FacterVars: strings.Join(facterVars, p.guestOSTypeConfig.facterVarsJoiner),
PuppetNode: p.config.PuppetNode, PuppetNode: p.config.PuppetNode,
PuppetServer: p.config.PuppetServer, PuppetServer: p.config.PuppetServer,
PuppetBinDir: p.config.PuppetBinDir, PuppetBinDir: p.config.PuppetBinDir,
Sudo: !p.config.PreventSudo, Sudo: !p.config.PreventSudo,
WorkingDir: p.config.WorkingDir, WorkingDir: p.config.WorkingDir,
ExtraArguments: "",
} }
p.config.ctx.Data = &data p.config.ctx.Data = &data
@ -279,6 +282,12 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
return fmt.Errorf("Puppet exited with a non-zero exit status: %d", cmd.ExitStatus) return fmt.Errorf("Puppet exited with a non-zero exit status: %d", cmd.ExitStatus)
} }
if p.config.CleanStagingDir {
if err := p.removeDir(ui, comm, p.config.StagingDir); err != nil {
return fmt.Errorf("Error removing staging directory: %s", err)
}
}
return nil return nil
} }