add support for chef_environment
This commit is contained in:
parent
1b659d270f
commit
25386f8e8e
|
@ -20,6 +20,7 @@ import (
|
|||
type Config struct {
|
||||
common.PackerConfig `mapstructure:",squash"`
|
||||
|
||||
ChefEnvironment string `mapstructure:"chef_environment"`
|
||||
ConfigTemplate string `mapstructure:"config_template"`
|
||||
ExecuteCommand string `mapstructure:"execute_command"`
|
||||
InstallCommand string `mapstructure:"install_command"`
|
||||
|
@ -47,6 +48,7 @@ type ConfigTemplate struct {
|
|||
ServerUrl string
|
||||
ValidationKeyPath string
|
||||
ValidationClientName string
|
||||
ChefEnvironment string
|
||||
}
|
||||
|
||||
type ExecuteTemplate struct {
|
||||
|
@ -94,10 +96,11 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
errs := common.CheckUnusedConfig(md)
|
||||
|
||||
templates := map[string]*string{
|
||||
"config_template": &p.config.ConfigTemplate,
|
||||
"node_name": &p.config.NodeName,
|
||||
"staging_dir": &p.config.StagingDir,
|
||||
"chef_server_url": &p.config.ServerUrl,
|
||||
"config_template": &p.config.ConfigTemplate,
|
||||
"node_name": &p.config.NodeName,
|
||||
"staging_dir": &p.config.StagingDir,
|
||||
"chef_server_url": &p.config.ServerUrl,
|
||||
"chef_environment": &p.config.ChefEnvironment,
|
||||
}
|
||||
|
||||
for n, ptr := range templates {
|
||||
|
@ -202,7 +205,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|||
}
|
||||
|
||||
configPath, err := p.createConfig(
|
||||
ui, comm, nodeName, serverUrl, remoteValidationKeyPath, p.config.ValidationClientName)
|
||||
ui, comm, nodeName, serverUrl, remoteValidationKeyPath, p.config.ValidationClientName, p.config.ChefEnvironment)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating Chef config file: %s", err)
|
||||
}
|
||||
|
@ -256,7 +259,7 @@ func (p *Provisioner) uploadDirectory(ui packer.Ui, comm packer.Communicator, ds
|
|||
return comm.UploadDir(dst, src, nil)
|
||||
}
|
||||
|
||||
func (p *Provisioner) createConfig(ui packer.Ui, comm packer.Communicator, nodeName string, serverUrl string, remoteKeyPath string, validationClientName string) (string, error) {
|
||||
func (p *Provisioner) createConfig(ui packer.Ui, comm packer.Communicator, nodeName string, serverUrl string, remoteKeyPath string, validationClientName string, chefEnvironment string) (string, error) {
|
||||
ui.Message("Creating configuration file 'client.rb'")
|
||||
|
||||
// Read the template
|
||||
|
@ -281,6 +284,7 @@ func (p *Provisioner) createConfig(ui packer.Ui, comm packer.Communicator, nodeN
|
|||
ServerUrl: serverUrl,
|
||||
ValidationKeyPath: remoteKeyPath,
|
||||
ValidationClientName: validationClientName,
|
||||
ChefEnvironment: chefEnvironment,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -548,4 +552,7 @@ validation_key "{{.ValidationKeyPath}}"
|
|||
{{if ne .NodeName ""}}
|
||||
node_name "{{.NodeName}}"
|
||||
{{end}}
|
||||
{{if ne .ChefEnvironment ""}}
|
||||
environment "{{.ChefEnvironment}}"
|
||||
{{end}}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue