From c4183071624736af1b5f195a60142dfa94ef3931 Mon Sep 17 00:00:00 2001 From: Weilu Jia Date: Wed, 12 Apr 2017 16:18:00 -0700 Subject: [PATCH 1/4] Add version selection for chef-solo provisioner Prevents issues such as #1751 when chef changes major versions --- provisioner/chef-solo/provisioner.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/provisioner/chef-solo/provisioner.go b/provisioner/chef-solo/provisioner.go index 981619a18..5611d48bd 100644 --- a/provisioner/chef-solo/provisioner.go +++ b/provisioner/chef-solo/provisioner.go @@ -28,7 +28,7 @@ type guestOSTypeConfig struct { var guestOSTypeConfigs = map[string]guestOSTypeConfig{ provisioner.UnixOSType: { 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", }, provisioner.WindowsOSType: { @@ -57,6 +57,7 @@ type Config struct { SkipInstall bool `mapstructure:"skip_install"` StagingDir string `mapstructure:"staging_directory"` GuestOSType string `mapstructure:"guest_os_type"` + Version string `mapstructure:"version"` ctx interpolate.Context } @@ -91,7 +92,8 @@ type ExecuteTemplate struct { } type InstallChefTemplate struct { - Sudo bool + Sudo bool + Version string } 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") 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) } } @@ -462,11 +464,12 @@ func (p *Provisioner) executeChef(ui packer.Ui, comm packer.Communicator, config 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...") 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) if err != nil { From 05d46c61f7b6bdb54db625bbd8c812c846bc646c Mon Sep 17 00:00:00 2001 From: Weilu Jia Date: Wed, 12 Apr 2017 16:27:59 -0700 Subject: [PATCH 2/4] Add documentation for chef-solo version pinning --- website/source/docs/provisioners/chef-solo.html.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/source/docs/provisioners/chef-solo.html.md b/website/source/docs/provisioners/chef-solo.html.md index 6a27635dd..954456084 100644 --- a/website/source/docs/provisioners/chef-solo.html.md +++ b/website/source/docs/provisioners/chef-solo.html.md @@ -110,6 +110,8 @@ configuration is actually required, but at least `run_list` is recommended. able to create directories and write into this folder. If the permissions are not correct, use a shell provisioner prior to this to configure it properly. +- `version` (string) - The version of Chef to be installed. By default this is + empty which will install the latest version of Chef. ## Chef Configuration @@ -177,7 +179,7 @@ install Chef in another way. ```text curl -L https://www.chef.io/chef/install.sh | \ - {{if .Sudo}}sudo{{end}} bash + {{if .Sudo}}sudo{{end}} bash -s --{{if .Version}} -v {{.Version}}{{end}} ``` When guest_os_type is set to "windows", Packer uses the following command to From 943563e957afe8ac6ee47479e163e3369754db91 Mon Sep 17 00:00:00 2001 From: Weilu Jia Date: Wed, 12 Apr 2017 16:30:07 -0700 Subject: [PATCH 3/4] Update chef-solo documentation to match latest changes --- website/source/docs/provisioners/chef-solo.html.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/source/docs/provisioners/chef-solo.html.md b/website/source/docs/provisioners/chef-solo.html.md index 954456084..7adddf85d 100644 --- a/website/source/docs/provisioners/chef-solo.html.md +++ b/website/source/docs/provisioners/chef-solo.html.md @@ -178,7 +178,7 @@ readability) to install Chef. This command can be customized if you want to install Chef in another way. ```text -curl -L https://www.chef.io/chef/install.sh | \ +curl -L https://omnitruck.chef.io/install.sh | \ {{if .Sudo}}sudo{{end}} bash -s --{{if .Version}} -v {{.Version}}{{end}} ``` @@ -186,7 +186,7 @@ When guest_os_type is set to "windows", Packer uses the following command to install the latest version of Chef: ```text -powershell.exe -Command "(New-Object System.Net.WebClient).DownloadFile('http://chef.io/chef/install.msi', 'C:\\Windows\\Temp\\chef.msi');Start-Process 'msiexec' -ArgumentList '/qb /i C:\\Windows\\Temp\\chef.msi' -NoNewWindow -Wait" +powershell.exe -Command \". { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; install\" ``` This command can be customized using the `install_command` configuration. From b1c5ccd3e27c05e1e899619d02fffea89a888566 Mon Sep 17 00:00:00 2001 From: Weilu Jia Date: Mon, 17 Apr 2017 18:15:53 -0700 Subject: [PATCH 4/4] Add version selection for chef-solo provisioner in Windows too --- provisioner/chef-solo/provisioner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provisioner/chef-solo/provisioner.go b/provisioner/chef-solo/provisioner.go index 5611d48bd..99d73ec36 100644 --- a/provisioner/chef-solo/provisioner.go +++ b/provisioner/chef-solo/provisioner.go @@ -33,7 +33,7 @@ var guestOSTypeConfigs = map[string]guestOSTypeConfig{ }, provisioner.WindowsOSType: { executeCommand: "c:/opscode/chef/bin/chef-solo.bat --no-color -c {{.ConfigPath}} -j {{.JsonPath}}", - installCommand: "powershell.exe -Command \". { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; install\"", + installCommand: "powershell.exe -Command \". { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; Install-Project{{if .Version}} -v {{.Version}}{{end}}\"", stagingDir: "C:/Windows/Temp/packer-chef-solo", }, }