diff --git a/provisioner/salt-masterless/provisioner.go b/provisioner/salt-masterless/provisioner.go index 9c9d558a1..e04da58f3 100644 --- a/provisioner/salt-masterless/provisioner.go +++ b/provisioner/salt-masterless/provisioner.go @@ -49,6 +49,9 @@ type Config struct { // Don't exit packer if salt-call returns an error code NoExitOnFailure bool `mapstructure:"no_exit_on_failure"` + // Set the logging level for the salt highstate run + LogLevel string `mapstructure:"log_level"` + // Command line args passed onto salt-call CmdArgs string "" @@ -123,6 +126,13 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { cmd_args.WriteString(" --retcode-passthrough") } + if p.config.LogLevel == "" { + cmd_args.WriteString(" -l info") + } else { + cmd_args.WriteString(" -l ") + cmd_args.WriteString(p.config.LogLevel) + } + p.config.CmdArgs = cmd_args.String() if errs != nil && len(errs.Errors) > 0 { @@ -224,7 +234,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { } ui.Message("Running highstate") - cmd := &packer.RemoteCmd{Command: p.sudo(fmt.Sprintf("salt-call --local state.highstate -l info %s", p.config.CmdArgs))} + cmd := &packer.RemoteCmd{Command: p.sudo(fmt.Sprintf("salt-call --local state.highstate %s", p.config.CmdArgs))} if err = cmd.StartWithUi(comm, ui); err != nil || cmd.ExitStatus != 0 { if err == nil { err = fmt.Errorf("Bad exit status: %d", cmd.ExitStatus) diff --git a/provisioner/salt-masterless/provisioner_test.go b/provisioner/salt-masterless/provisioner_test.go index 523e133b1..da16c1a3b 100644 --- a/provisioner/salt-masterless/provisioner_test.go +++ b/provisioner/salt-masterless/provisioner_test.go @@ -237,3 +237,27 @@ func TestProvisionerPrepare_NoExitOnFailure(t *testing.T) { t.Fatal("--retcode-passthrough should not be set in CmdArgs") } } + +func TestProvisionerPrepare_LogLevel(t *testing.T) { + var p Provisioner + config := testConfig() + + err := p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } + + if !strings.Contains(p.config.CmdArgs, "-l info") { + t.Fatal("-l info should be set in CmdArgs") + } + + config["log_level"] = "debug" + err = p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } + + if !strings.Contains(p.config.CmdArgs, "-l debug") { + t.Fatal("-l debug should be set in CmdArgs") + } +} diff --git a/website/source/docs/provisioners/salt-masterless.html.markdown b/website/source/docs/provisioners/salt-masterless.html.markdown index 7abe7e633..55c91ad69 100644 --- a/website/source/docs/provisioners/salt-masterless.html.markdown +++ b/website/source/docs/provisioners/salt-masterless.html.markdown @@ -71,3 +71,5 @@ Optional: - `no_exit_on_failure` (boolean) - Packer will exit if the Salt highstate command fails. Set this option to true to ignore Salt failures. + +- `log_level` (string) - Set the logging level for the Salt highstate run.