diff --git a/provisioner/puppet-server/provisioner.go b/provisioner/puppet-server/provisioner.go index 0166827f0..72863f2ee 100644 --- a/provisioner/puppet-server/provisioner.go +++ b/provisioner/puppet-server/provisioner.go @@ -32,6 +32,9 @@ type Config struct { // Additional options to be passed to `puppet agent`. Options string `mapstructure:"options"` + // If true, `sudo` will NOT be used to execute Puppet. + PreventSudo bool `mapstructure:"prevent_sudo"` + // The directory where files will be uploaded. Packer requires write // permissions in this directory. StagingDir string `mapstructure:"staging_dir"` @@ -48,6 +51,7 @@ type ExecuteTemplate struct { PuppetNode string PuppetServer string Options string + Sudo bool } func (p *Provisioner) Prepare(raws ...interface{}) error { @@ -182,6 +186,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { PuppetNode: p.config.PuppetNode, PuppetServer: p.config.PuppetServer, Options: p.config.Options, + Sudo: !p.config.PreventSudo, }) if err != nil { return err @@ -240,7 +245,7 @@ func (p *Provisioner) uploadDirectory(ui packer.Ui, comm packer.Communicator, ds } func (p *Provisioner) commandTemplate() string { - return "{{.FacterVars}} " + + return "{{.FacterVars}} {{if .Sudo}} sudo -E {{end}}" + "puppet agent --onetime --no-daemonize " + "{{if ne .PuppetServer \"\"}}--server='{{.PuppetServer}}' {{end}}" + "{{if ne .Options \"\"}}{{.Options}} {{end}}" + diff --git a/website/source/docs/provisioners/puppet-server.html.markdown b/website/source/docs/provisioners/puppet-server.html.markdown index d9c4bdc8e..fce35bb03 100644 --- a/website/source/docs/provisioners/puppet-server.html.markdown +++ b/website/source/docs/provisioners/puppet-server.html.markdown @@ -60,6 +60,10 @@ required. They are listed below: * `puppet_server` (string) - Hostname of the Puppet server. By default "puppet" will be used. +* `prevent_sudo` (boolean) - By default, the configured commands that are + executed to run Puppet are executed with `sudo`. If this is true, + then the sudo will be omitted. + * `staging_directory` (string) - This is the directory where all the configuration of Puppet by Packer will be placed. By default this is "/tmp/packer-puppet-server". This directory doesn't need to exist but must have proper permissions so that