Add version selection for chef-solo provisioner
Prevents issues such as #1751 when chef changes major versions
This commit is contained in:
parent
b9bea70e59
commit
c418307162
|
@ -28,7 +28,7 @@ type guestOSTypeConfig struct {
|
||||||
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
||||||
provisioner.UnixOSType: {
|
provisioner.UnixOSType: {
|
||||||
executeCommand: "{{if .Sudo}}sudo {{end}}chef-solo --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
executeCommand: "{{if .Sudo}}sudo {{end}}chef-solo --no-color -c {{.ConfigPath}} -j {{.JsonPath}}",
|
||||||
installCommand: "curl -L https://omnitruck.chef.io/install.sh | {{if .Sudo}}sudo {{end}}bash",
|
installCommand: "curl -L https://omnitruck.chef.io/install.sh | {{if .Sudo}}sudo {{end}}bash -s --{{if .Version}} -v {{.Version}}{{end}}",
|
||||||
stagingDir: "/tmp/packer-chef-solo",
|
stagingDir: "/tmp/packer-chef-solo",
|
||||||
},
|
},
|
||||||
provisioner.WindowsOSType: {
|
provisioner.WindowsOSType: {
|
||||||
|
@ -57,6 +57,7 @@ type Config struct {
|
||||||
SkipInstall bool `mapstructure:"skip_install"`
|
SkipInstall bool `mapstructure:"skip_install"`
|
||||||
StagingDir string `mapstructure:"staging_directory"`
|
StagingDir string `mapstructure:"staging_directory"`
|
||||||
GuestOSType string `mapstructure:"guest_os_type"`
|
GuestOSType string `mapstructure:"guest_os_type"`
|
||||||
|
Version string `mapstructure:"version"`
|
||||||
|
|
||||||
ctx interpolate.Context
|
ctx interpolate.Context
|
||||||
}
|
}
|
||||||
|
@ -92,6 +93,7 @@ type ExecuteTemplate struct {
|
||||||
|
|
||||||
type InstallChefTemplate struct {
|
type InstallChefTemplate struct {
|
||||||
Sudo bool
|
Sudo bool
|
||||||
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Prepare(raws ...interface{}) error {
|
func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
|
@ -229,7 +231,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
||||||
ui.Say("Provisioning with chef-solo")
|
ui.Say("Provisioning with chef-solo")
|
||||||
|
|
||||||
if !p.config.SkipInstall {
|
if !p.config.SkipInstall {
|
||||||
if err := p.installChef(ui, comm); err != nil {
|
if err := p.installChef(ui, comm, p.config.Version); err != nil {
|
||||||
return fmt.Errorf("Error installing Chef: %s", err)
|
return fmt.Errorf("Error installing Chef: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,11 +464,12 @@ func (p *Provisioner) executeChef(ui packer.Ui, comm packer.Communicator, config
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) installChef(ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) installChef(ui packer.Ui, comm packer.Communicator, version string) error {
|
||||||
ui.Message("Installing Chef...")
|
ui.Message("Installing Chef...")
|
||||||
|
|
||||||
p.config.ctx.Data = &InstallChefTemplate{
|
p.config.ctx.Data = &InstallChefTemplate{
|
||||||
Sudo: !p.config.PreventSudo,
|
Sudo: !p.config.PreventSudo,
|
||||||
|
Version: version,
|
||||||
}
|
}
|
||||||
command, err := interpolate.Render(p.config.InstallCommand, &p.config.ctx)
|
command, err := interpolate.Render(p.config.InstallCommand, &p.config.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue