From 843731d98dfa9c2dc8cfc92c4a49a9134c2179af Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Wed, 28 Dec 2016 08:19:03 -0600 Subject: [PATCH] provisioner(converge): add prevent_sudo --- provisioner/converge/provisioner.go | 5 ++++- website/source/docs/provisioners/converge.html.md | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/provisioner/converge/provisioner.go b/provisioner/converge/provisioner.go index aabaf45e7..55233b504 100644 --- a/provisioner/converge/provisioner.go +++ b/provisioner/converge/provisioner.go @@ -39,6 +39,7 @@ type Config struct { WorkingDirectory string `mapstructure:"working_directory"` Params map[string]string `mapstucture:"params"` ExecuteCommand string `mapstructure:"execute_command"` + PreventSudo bool `mapstructure:"prevent_sudo"` ctx interpolate.Context } @@ -83,7 +84,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { } if p.config.ExecuteCommand == "" { - p.config.ExecuteCommand = "cd {{.WorkingDirectory}} && sudo converge apply --local --log-level=WARNING --paramsJSON '{{.ParamsJSON}}' {{.Module}}" + p.config.ExecuteCommand = "cd {{.WorkingDirectory}} && {{if .Sudo}}sudo {{end}}converge apply --local --log-level=WARNING --paramsJSON '{{.ParamsJSON}}' {{.Module}}" } // validate version @@ -191,10 +192,12 @@ func (p *Provisioner) applyModules(ui packer.Ui, comm packer.Communicator) error p.config.ctx.Data = struct { ParamsJSON, WorkingDirectory, Module string + Sudo bool }{ ParamsJSON: string(params), WorkingDirectory: p.config.WorkingDirectory, Module: p.config.Module, + Sudo: !p.config.PreventSudo, } command, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx) if err != nil { diff --git a/website/source/docs/provisioners/converge.html.md b/website/source/docs/provisioners/converge.html.md index 32624b936..057604324 100644 --- a/website/source/docs/provisioners/converge.html.md +++ b/website/source/docs/provisioners/converge.html.md @@ -57,6 +57,9 @@ Optional parameters: various [configuration template variables](/docs/templates/configuration-templates.html) available. +- `prevent_sudo` (bool) - stop Converge from running with adminstrator + privileges via sudo + ### Module Directories The provisioner can transfer module directories to the remote host for @@ -76,7 +79,7 @@ By default, Packer uses the following command (broken across multiple lines for ``` {.liquid} cd {{.WorkingDirectory}} && \ -sudo converge apply \ +{{if .Sudo}}sudo {{end}}converge apply \ --local \ --log-level=WARNING \ --paramsJSON '{{.ParamsJSON}}' \ @@ -87,6 +90,7 @@ This command can be customized using the `execute_command` configuration. As you can see from the default value above, the value of this configuration can contain various template variables: -- `WorkingDirectory` - `directory` from the configuration +- `WorkingDirectory` - `directory` from the configuration. +- `Sudo` - the opposite of `prevent_sudo` from the configuration. - `ParamsJSON` - The unquoted JSONified form of `params` from the configuration. - `Module` - `module` from the configuration.