Skip to content

Commit

Permalink
Add support for overriding Omnitruck URL
Browse files Browse the repository at this point in the history
  • Loading branch information
bdwyertech committed Mar 15, 2023
1 parent bd2068d commit 58f60f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 13 additions & 6 deletions provisioner/chef-solo/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ type guestOSTypeConfig struct {
var guestOSTypeConfigs = map[string]guestOSTypeConfig{
guestexec.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 -s --{{if .Version}} -v {{.Version}}{{end}}",
stagingDir: "/tmp/packer-chef-solo",
installCommand: "curl -L {{.OmnitruckUrl}}/install.sh | {{if .Sudo}}sudo {{end}}bash -s --{{if .Version}} -v {{.Version}}{{end}}",
},
guestexec.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-Project{{if .Version}} -version {{.Version}}{{end}}\"",
stagingDir: "C:/Windows/Temp/packer-chef-solo",
installCommand: "powershell.exe -Command \". { iwr -useb {{.OmnitruckUrl}}/install.ps1 } | iex; Install-Project{{if .Version}} -version {{.Version}}{{end}}\"",
},
}

Expand Down Expand Up @@ -67,6 +67,7 @@ type Config struct {

RetryOnExitCode map[int]bool `mapstructure:"retry_on_exit_code"`
WaitForRetry time.Duration `mapstructure:"wait_for_retry"`
OmnitruckUrl string `mapstructure:"omnitruck_url"`
RunList []string `mapstructure:"run_list"`
SkipInstall bool `mapstructure:"skip_install"`
StagingDir string `mapstructure:"staging_directory"`
Expand Down Expand Up @@ -107,8 +108,9 @@ type ExecuteTemplate struct {
}

type InstallChefTemplate struct {
Sudo bool
Version string
OmnitruckUrl string
Sudo bool
Version string
}

func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { return p.config.FlatMapstructure().HCL2Spec() }
Expand Down Expand Up @@ -163,6 +165,10 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
p.config.InstallCommand = p.guestOSTypeConfig.installCommand
}

if p.config.OmnitruckUrl == "" {
p.config.OmnitruckUrl = "https://omnitruck.chef.io"
}

if p.config.RunList == nil {
p.config.RunList = make([]string, 0)
}
Expand Down Expand Up @@ -515,8 +521,9 @@ func (p *Provisioner) installChef(ctx context.Context, ui packersdk.Ui, comm pac
ui.Message("Installing Chef...")

p.config.ctx.Data = &InstallChefTemplate{
Sudo: !p.config.PreventSudo,
Version: version,
OmnitruckUrl: p.config.OmnitruckUrl,
Sudo: !p.config.PreventSudo,
Version: version,
}
command, err := interpolate.Render(p.config.InstallCommand, &p.config.ctx)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions provisioner/chef-solo/provisioner.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 58f60f6

Please sign in to comment.