|
|
|
|
@ -34,13 +34,13 @@ type guestOSTypeConfig struct {
|
|
|
|
|
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
|
|
|
|
|
provisioner.UnixOSType: {
|
|
|
|
|
executeCommand: "{{if .Sudo}}sudo {{end}}chef-client --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}}",
|
|
|
|
|
knifeCommand: "{{if .Sudo}}sudo {{end}}knife {{.Args}} {{.Flags}}",
|
|
|
|
|
stagingDir: "/tmp/packer-chef-client",
|
|
|
|
|
},
|
|
|
|
|
provisioner.WindowsOSType: {
|
|
|
|
|
executeCommand: "c:/opscode/chef/bin/chef-client.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}} -version {{.Version}}{{end}}\"",
|
|
|
|
|
knifeCommand: "c:/opscode/chef/bin/knife.bat {{.Args}} {{.Flags}}",
|
|
|
|
|
stagingDir: "C:/Windows/Temp/packer-chef-client",
|
|
|
|
|
},
|
|
|
|
|
@ -77,6 +77,7 @@ type Config struct {
|
|
|
|
|
StagingDir string `mapstructure:"staging_directory"`
|
|
|
|
|
ValidationClientName string `mapstructure:"validation_client_name"`
|
|
|
|
|
ValidationKeyPath string `mapstructure:"validation_key_path"`
|
|
|
|
|
Version string `mapstructure:"version"`
|
|
|
|
|
|
|
|
|
|
ctx interpolate.Context
|
|
|
|
|
}
|
|
|
|
|
@ -114,7 +115,8 @@ type ExecuteTemplate struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type InstallChefTemplate struct {
|
|
|
|
|
Sudo bool
|
|
|
|
|
Sudo bool
|
|
|
|
|
Version string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type KnifeTemplate struct {
|
|
|
|
|
@ -256,7 +258,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C
|
|
|
|
|
serverUrl := p.config.ServerUrl
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -604,12 +606,13 @@ 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...")
|
|
|
|
|
ctx := context.TODO()
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|