provisioner(converge): add prevent_sudo

This commit is contained in:
Brian Hicks 2016-12-28 08:19:03 -06:00
parent 30a393d4c2
commit 843731d98d
No known key found for this signature in database
GPG Key ID: FF1F407C0D3C2430
2 changed files with 10 additions and 3 deletions

View File

@ -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 {

View File

@ -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.