|
|
|
|
@ -44,6 +44,10 @@ type Config struct {
|
|
|
|
|
// The directory where files will be uploaded. Packer requires write
|
|
|
|
|
// permissions in this directory.
|
|
|
|
|
StagingDir string `mapstructure:"staging_directory"`
|
|
|
|
|
|
|
|
|
|
// The directory from which the command will be executed.
|
|
|
|
|
// Packer requires the directory to exist when running puppet.
|
|
|
|
|
WorkingDir string `mapstructure:"working_directory"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Provisioner struct {
|
|
|
|
|
@ -51,6 +55,7 @@ type Provisioner struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ExecuteTemplate struct {
|
|
|
|
|
WorkingDir string
|
|
|
|
|
FacterVars string
|
|
|
|
|
HieraConfigPath string
|
|
|
|
|
ModulePath string
|
|
|
|
|
@ -74,7 +79,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|
|
|
|
|
|
|
|
|
// Set some defaults
|
|
|
|
|
if p.config.ExecuteCommand == "" {
|
|
|
|
|
p.config.ExecuteCommand = "{{.FacterVars}} {{if .Sudo}} sudo -E {{end}}" +
|
|
|
|
|
p.config.ExecuteCommand = "cd {{.WorkingDir}} && " +
|
|
|
|
|
"{{.FacterVars}} {{if .Sudo}} sudo -E {{end}}" +
|
|
|
|
|
"puppet apply --verbose --modulepath='{{.ModulePath}}' " +
|
|
|
|
|
"{{if ne .HieraConfigPath \"\"}}--hiera_config='{{.HieraConfigPath}}' {{end}}" +
|
|
|
|
|
"{{if ne .ManifestDir \"\"}}--manifestdir='{{.ManifestDir}}' {{end}}" +
|
|
|
|
|
@ -86,6 +92,10 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|
|
|
|
p.config.StagingDir = "/tmp/packer-puppet-masterless"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if p.config.WorkingDir == "" {
|
|
|
|
|
p.config.WorkingDir = p.config.StagingDir
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Validation
|
|
|
|
|
var errs *packer.MultiError
|
|
|
|
|
if p.config.HieraConfigPath != "" {
|
|
|
|
|
@ -200,6 +210,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|
|
|
|
ManifestFile: remoteManifestFile,
|
|
|
|
|
ModulePath: strings.Join(modulePaths, ":"),
|
|
|
|
|
Sudo: !p.config.PreventSudo,
|
|
|
|
|
WorkingDir: p.config.WorkingDir,
|
|
|
|
|
}
|
|
|
|
|
command, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
|