pass struct of generated data into provision() call
This commit is contained in:
parent
5e81c6f44e
commit
f4c3501af5
|
@ -23,6 +23,17 @@ type StepProvision struct {
|
||||||
Comm packer.Communicator
|
Comm packer.Communicator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PopulateProvisionHookData(state multistep.StateBag) packer.ProvisionHookData {
|
||||||
|
hookData := packer.NewProvisionHookData()
|
||||||
|
|
||||||
|
// Add WinRMPassword to runtime data
|
||||||
|
WinRMPassword, ok := state.GetOk("winrm_password")
|
||||||
|
if ok {
|
||||||
|
hookData.WinRMPassword = WinRMPassword.(string)
|
||||||
|
}
|
||||||
|
return hookData
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StepProvision) runWithHook(ctx context.Context, state multistep.StateBag, hooktype string) multistep.StepAction {
|
func (s *StepProvision) runWithHook(ctx context.Context, state multistep.StateBag, hooktype string) multistep.StepAction {
|
||||||
// hooktype will be either packer.HookProvision or packer.HookCleanupProvision
|
// hooktype will be either packer.HookProvision or packer.HookCleanupProvision
|
||||||
comm := s.Comm
|
comm := s.Comm
|
||||||
|
@ -32,9 +43,12 @@ func (s *StepProvision) runWithHook(ctx context.Context, state multistep.StateBa
|
||||||
comm = raw.(packer.Communicator)
|
comm = raw.(packer.Communicator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hook := state.Get("hook").(packer.Hook)
|
hook := state.Get("hook").(packer.Hook)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
|
hookData := PopulateProvisionHookData(state)
|
||||||
|
|
||||||
// Run the provisioner in a goroutine so we can continually check
|
// Run the provisioner in a goroutine so we can continually check
|
||||||
// for cancellations...
|
// for cancellations...
|
||||||
if hooktype == packer.HookProvision {
|
if hooktype == packer.HookProvision {
|
||||||
|
@ -44,7 +58,7 @@ func (s *StepProvision) runWithHook(ctx context.Context, state multistep.StateBa
|
||||||
}
|
}
|
||||||
errCh := make(chan error, 1)
|
errCh := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
errCh <- hook.Run(ctx, hooktype, ui, comm, nil)
|
errCh <- hook.Run(ctx, hooktype, ui, comm, &hookData)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -21,13 +21,13 @@ func (c *cmdProvisioner) Prepare(configs ...interface{}) error {
|
||||||
return c.p.Prepare(configs...)
|
return c.p.Prepare(configs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cmdProvisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (c *cmdProvisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData *packer.ProvisionHookData) error {
|
||||||
defer func() {
|
defer func() {
|
||||||
r := recover()
|
r := recover()
|
||||||
c.checkExit(r, nil)
|
c.checkExit(r, nil)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return c.p.Provision(ctx, ui, comm)
|
return c.p.Provision(ctx, ui, comm, generatedData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cmdProvisioner) checkExit(p interface{}, cb func()) {
|
func (c *cmdProvisioner) checkExit(p interface{}, cb func()) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ type Provisioner interface {
|
||||||
// given for cancellation, a UI is given to communicate with the user, and
|
// given for cancellation, a UI is given to communicate with the user, and
|
||||||
// a communicator is given that is guaranteed to be connected to some
|
// a communicator is given that is guaranteed to be connected to some
|
||||||
// machine so that provisioning can be done.
|
// machine so that provisioning can be done.
|
||||||
Provision(context.Context, Ui, Communicator) error
|
Provision(context.Context, Ui, Communicator, *ProvisionHookData) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// A HookedProvisioner represents a provisioner and information describing it
|
// A HookedProvisioner represents a provisioner and information describing it
|
||||||
|
@ -37,6 +37,21 @@ type ProvisionHook struct {
|
||||||
Provisioners []*HookedProvisioner
|
Provisioners []*HookedProvisioner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProvisionHookData struct {
|
||||||
|
WinRMPassword string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewProvisionHookData() ProvisionHookData {
|
||||||
|
// this is the function we use to create the provisionhookdata, and as a
|
||||||
|
// bonus the initialized state applies defaults that act as passthroughs so
|
||||||
|
// that when prepare is called the first time, we can save interpolating
|
||||||
|
// these values until provisioner run time.
|
||||||
|
hookData := ProvisionHookData{
|
||||||
|
WinRMPassword: `{{.WinRMPassword}}`,
|
||||||
|
}
|
||||||
|
return hookData
|
||||||
|
}
|
||||||
|
|
||||||
// Runs the provisioners in order.
|
// Runs the provisioners in order.
|
||||||
func (h *ProvisionHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data interface{}) error {
|
func (h *ProvisionHook) Run(ctx context.Context, name string, ui Ui, comm Communicator, data interface{}) error {
|
||||||
// Shortcut
|
// Shortcut
|
||||||
|
@ -44,6 +59,11 @@ func (h *ProvisionHook) Run(ctx context.Context, name string, ui Ui, comm Commun
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generatedData := NewProvisionHookData()
|
||||||
|
if data != nil {
|
||||||
|
generatedData = data.(ProvisionHookData)
|
||||||
|
}
|
||||||
|
|
||||||
if comm == nil {
|
if comm == nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"No communicator found for provisioners! This is usually because the\n" +
|
"No communicator found for provisioners! This is usually because the\n" +
|
||||||
|
@ -53,7 +73,7 @@ func (h *ProvisionHook) Run(ctx context.Context, name string, ui Ui, comm Commun
|
||||||
for _, p := range h.Provisioners {
|
for _, p := range h.Provisioners {
|
||||||
ts := CheckpointReporter.AddSpan(p.TypeName, "provisioner", p.Config)
|
ts := CheckpointReporter.AddSpan(p.TypeName, "provisioner", p.Config)
|
||||||
|
|
||||||
err := p.Provisioner.Provision(ctx, ui, comm)
|
err := p.Provisioner.Provision(ctx, ui, comm, &generatedData)
|
||||||
|
|
||||||
ts.End(err)
|
ts.End(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -75,7 +95,7 @@ func (p *PausedProvisioner) Prepare(raws ...interface{}) error {
|
||||||
return p.Provisioner.Prepare(raws...)
|
return p.Provisioner.Prepare(raws...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PausedProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator) error {
|
func (p *PausedProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData *ProvisionHookData) error {
|
||||||
|
|
||||||
// Use a select to determine if we get cancelled during the wait
|
// Use a select to determine if we get cancelled during the wait
|
||||||
ui.Say(fmt.Sprintf("Pausing %s before the next provisioner...", p.PauseBefore))
|
ui.Say(fmt.Sprintf("Pausing %s before the next provisioner...", p.PauseBefore))
|
||||||
|
@ -85,7 +105,7 @@ func (p *PausedProvisioner) Provision(ctx context.Context, ui Ui, comm Communica
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.Provisioner.Provision(ctx, ui, comm)
|
return p.Provisioner.Provision(ctx, ui, comm, generatedData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DebuggedProvisioner is a Provisioner implementation that waits until a key
|
// DebuggedProvisioner is a Provisioner implementation that waits until a key
|
||||||
|
@ -102,7 +122,7 @@ func (p *DebuggedProvisioner) Prepare(raws ...interface{}) error {
|
||||||
return p.Provisioner.Prepare(raws...)
|
return p.Provisioner.Prepare(raws...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *DebuggedProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator) error {
|
func (p *DebuggedProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData *ProvisionHookData) error {
|
||||||
// Use a select to determine if we get cancelled during the wait
|
// Use a select to determine if we get cancelled during the wait
|
||||||
message := "Pausing before the next provisioner . Press enter to continue."
|
message := "Pausing before the next provisioner . Press enter to continue."
|
||||||
|
|
||||||
|
@ -122,5 +142,5 @@ func (p *DebuggedProvisioner) Provision(ctx context.Context, ui Ui, comm Communi
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.Provisioner.Provision(ctx, ui, comm)
|
return p.Provisioner.Provision(ctx, ui, comm, generatedData)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ func (t *MockProvisioner) Prepare(configs ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MockProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator) error {
|
func (t *MockProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData *ProvisionHookData) error {
|
||||||
t.ProvCalled = true
|
t.ProvCalled = true
|
||||||
t.ProvCommunicator = comm
|
t.ProvCommunicator = comm
|
||||||
t.ProvUi = ui
|
t.ProvUi = ui
|
||||||
|
|
|
@ -13,7 +13,7 @@ type TimeoutProvisioner struct {
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *TimeoutProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator) error {
|
func (p *TimeoutProvisioner) Provision(ctx context.Context, ui Ui, comm Communicator, generatedData *ProvisionHookData) error {
|
||||||
ctx, cancel := context.WithTimeout(ctx, p.Timeout)
|
ctx, cancel := context.WithTimeout(ctx, p.Timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func (p *TimeoutProvisioner) Provision(ctx context.Context, ui Ui, comm Communic
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := p.Provisioner.Provision(ctx, ui, comm)
|
err := p.Provisioner.Provision(ctx, ui, comm, generatedData)
|
||||||
close(errC)
|
close(errC)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (p *provisioner) Prepare(configs ...interface{}) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData *packer.ProvisionHookData) error {
|
||||||
nextId := p.mux.NextId()
|
nextId := p.mux.NextId()
|
||||||
server := newServerWithMux(p.mux, nextId)
|
server := newServerWithMux(p.mux, nextId)
|
||||||
server.RegisterCommunicator(comm)
|
server.RegisterCommunicator(comm)
|
||||||
|
@ -66,7 +66,7 @@ func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *interfa
|
||||||
return p.p.Prepare(args.Configs...)
|
return p.p.Prepare(args.Configs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProvisionerServer) Provision(streamId uint32, reply *interface{}) error {
|
func (p *ProvisionerServer) Provision(streamId uint32, reply *interface{}, generatedData *packer.ProvisionHookData) error {
|
||||||
client, err := newClientWithMux(p.mux, streamId)
|
client, err := newClientWithMux(p.mux, streamId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NewBasicError(err)
|
return NewBasicError(err)
|
||||||
|
@ -77,7 +77,7 @@ func (p *ProvisionerServer) Provision(streamId uint32, reply *interface{}) error
|
||||||
p.context, p.contextCancel = context.WithCancel(context.Background())
|
p.context, p.contextCancel = context.WithCancel(context.Background())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.p.Provision(p.context, client.Ui(), client.Communicator()); err != nil {
|
if err := p.p.Provision(p.context, client.Ui(), client.Communicator(), generatedData); err != nil {
|
||||||
return NewBasicError(err)
|
return NewBasicError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
ui.Say("Provisioning with Ansible...")
|
ui.Say("Provisioning with Ansible...")
|
||||||
|
|
||||||
if len(p.config.PlaybookDir) > 0 {
|
if len(p.config.PlaybookDir) > 0 {
|
||||||
|
|
|
@ -214,7 +214,7 @@ func (p *Provisioner) getVersion() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
ui.Say("Provisioning with Ansible...")
|
ui.Say("Provisioning with Ansible...")
|
||||||
// Interpolate env vars to check for .WinRMPassword
|
// Interpolate env vars to check for .WinRMPassword
|
||||||
p.config.ctx.Data = &PassthroughTemplate{
|
p.config.ctx.Data = &PassthroughTemplate{
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
if p.config.Disable {
|
if p.config.Disable {
|
||||||
if p.config.Note != "" {
|
if p.config.Note != "" {
|
||||||
ui.Say(fmt.Sprintf(
|
ui.Say(fmt.Sprintf(
|
||||||
|
|
|
@ -244,7 +244,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
|
|
||||||
p.communicator = comm
|
p.communicator = comm
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
ui.Say("Provisioning with chef-solo")
|
ui.Say("Provisioning with chef-solo")
|
||||||
|
|
||||||
if !p.config.SkipInstall {
|
if !p.config.SkipInstall {
|
||||||
|
|
|
@ -108,7 +108,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provision node somehow. TODO: actual docs
|
// Provision node somehow. TODO: actual docs
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
ui.Say("Provisioning with Converge")
|
ui.Say("Provisioning with Converge")
|
||||||
|
|
||||||
// bootstrapping
|
// bootstrapping
|
||||||
|
|
|
@ -92,7 +92,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
if p.config.Direction == "download" {
|
if p.config.Direction == "download" {
|
||||||
return p.ProvisionDownload(ui, comm)
|
return p.ProvisionDownload(ui, comm)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -186,7 +186,7 @@ func (p *Provisioner) getVersion() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
ui.Say("Provisioning with Inspec...")
|
ui.Say("Provisioning with Inspec...")
|
||||||
|
|
||||||
for i, envVar := range p.config.InspecEnvVars {
|
for i, envVar := range p.config.InspecEnvVars {
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"github.com/hashicorp/packer/common/retry"
|
"github.com/hashicorp/packer/common/retry"
|
||||||
"github.com/hashicorp/packer/common/shell"
|
"github.com/hashicorp/packer/common/shell"
|
||||||
"github.com/hashicorp/packer/common/uuid"
|
"github.com/hashicorp/packer/common/uuid"
|
||||||
commonhelper "github.com/hashicorp/packer/helper/common"
|
|
||||||
"github.com/hashicorp/packer/helper/config"
|
"github.com/hashicorp/packer/helper/config"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/hashicorp/packer/packer/tmp"
|
"github.com/hashicorp/packer/packer/tmp"
|
||||||
|
@ -73,8 +72,9 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Provisioner struct {
|
type Provisioner struct {
|
||||||
config Config
|
config Config
|
||||||
communicator packer.Communicator
|
communicator packer.Communicator
|
||||||
|
generatedData *packer.ProvisionHookData
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExecuteCommandTemplate struct {
|
type ExecuteCommandTemplate struct {
|
||||||
|
@ -83,10 +83,6 @@ type ExecuteCommandTemplate struct {
|
||||||
WinRMPassword string
|
WinRMPassword string
|
||||||
}
|
}
|
||||||
|
|
||||||
type EnvVarsTemplate struct {
|
|
||||||
WinRMPassword string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Provisioner) defaultExecuteCommand() string {
|
func (p *Provisioner) defaultExecuteCommand() string {
|
||||||
baseCmd := `& { if (Test-Path variable:global:ProgressPreference)` +
|
baseCmd := `& { if (Test-Path variable:global:ProgressPreference)` +
|
||||||
`{set-variable -name variable:global:ProgressPreference -value 'SilentlyContinue'};` +
|
`{set-variable -name variable:global:ProgressPreference -value 'SilentlyContinue'};` +
|
||||||
|
@ -101,9 +97,7 @@ func (p *Provisioner) defaultExecuteCommand() string {
|
||||||
func (p *Provisioner) Prepare(raws ...interface{}) error {
|
func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
// Create passthrough for winrm password so we can fill it in once we know
|
// Create passthrough for winrm password so we can fill it in once we know
|
||||||
// it
|
// it
|
||||||
p.config.ctx.Data = &EnvVarsTemplate{
|
p.config.ctx.Data = packer.NewProvisionHookData()
|
||||||
WinRMPassword: `{{.WinRMPassword}}`,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := config.Decode(&p.config, &config.DecodeOpts{
|
err := config.Decode(&p.config, &config.DecodeOpts{
|
||||||
Interpolate: true,
|
Interpolate: true,
|
||||||
|
@ -232,9 +226,12 @@ func extractScript(p *Provisioner) (string, error) {
|
||||||
return temp.Name(), nil
|
return temp.Name(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData *packer.ProvisionHookData) error {
|
||||||
ui.Say(fmt.Sprintf("Provisioning with Powershell..."))
|
ui.Say(fmt.Sprintf("Provisioning with Powershell..."))
|
||||||
p.communicator = comm
|
p.communicator = comm
|
||||||
|
p.generatedData = generatedData
|
||||||
|
|
||||||
|
packer.LogSecretFilter.Set(p.generatedData.WinRMPassword)
|
||||||
|
|
||||||
scripts := make([]string, len(p.config.Scripts))
|
scripts := make([]string, len(p.config.Scripts))
|
||||||
copy(scripts, p.config.Scripts)
|
copy(scripts, p.config.Scripts)
|
||||||
|
@ -344,9 +341,8 @@ func (p *Provisioner) createFlattenedEnvVars(elevated bool) (flattened string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// interpolate environment variables
|
// interpolate environment variables
|
||||||
p.config.ctx.Data = &EnvVarsTemplate{
|
p.config.ctx.Data = p.generatedData
|
||||||
WinRMPassword: getWinRMPassword(p.config.PackerBuildName),
|
|
||||||
}
|
|
||||||
// Split vars into key/value components
|
// Split vars into key/value components
|
||||||
for _, envVar := range p.config.Vars {
|
for _, envVar := range p.config.Vars {
|
||||||
envVar, err := interpolate.Render(envVar, &p.config.ctx)
|
envVar, err := interpolate.Render(envVar, &p.config.ctx)
|
||||||
|
@ -421,7 +417,7 @@ func (p *Provisioner) createCommandTextNonPrivileged() (command string, err erro
|
||||||
p.config.ctx.Data = &ExecuteCommandTemplate{
|
p.config.ctx.Data = &ExecuteCommandTemplate{
|
||||||
Path: p.config.RemotePath,
|
Path: p.config.RemotePath,
|
||||||
Vars: p.config.RemoteEnvVarPath,
|
Vars: p.config.RemoteEnvVarPath,
|
||||||
WinRMPassword: getWinRMPassword(p.config.PackerBuildName),
|
WinRMPassword: p.generatedData.WinRMPassword,
|
||||||
}
|
}
|
||||||
command, err = interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)
|
command, err = interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)
|
||||||
|
|
||||||
|
@ -433,12 +429,6 @@ func (p *Provisioner) createCommandTextNonPrivileged() (command string, err erro
|
||||||
return command, nil
|
return command, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getWinRMPassword(buildName string) string {
|
|
||||||
winRMPass, _ := commonhelper.RetrieveSharedState("winrm_password", buildName)
|
|
||||||
packer.LogSecretFilter.Set(winRMPass)
|
|
||||||
return winRMPass
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Provisioner) createCommandTextPrivileged() (command string, err error) {
|
func (p *Provisioner) createCommandTextPrivileged() (command string, err error) {
|
||||||
// Prepare everything needed to enable the required env vars within the
|
// Prepare everything needed to enable the required env vars within the
|
||||||
// remote environment
|
// remote environment
|
||||||
|
@ -450,7 +440,7 @@ func (p *Provisioner) createCommandTextPrivileged() (command string, err error)
|
||||||
p.config.ctx.Data = &ExecuteCommandTemplate{
|
p.config.ctx.Data = &ExecuteCommandTemplate{
|
||||||
Path: p.config.RemotePath,
|
Path: p.config.RemotePath,
|
||||||
Vars: p.config.RemoteEnvVarPath,
|
Vars: p.config.RemoteEnvVarPath,
|
||||||
WinRMPassword: getWinRMPassword(p.config.PackerBuildName),
|
WinRMPassword: p.generatedData.WinRMPassword,
|
||||||
}
|
}
|
||||||
command, err = interpolate.Render(p.config.ElevatedExecuteCommand, &p.config.ctx)
|
command, err = interpolate.Render(p.config.ElevatedExecuteCommand, &p.config.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -475,9 +465,7 @@ func (p *Provisioner) ElevatedUser() string {
|
||||||
|
|
||||||
func (p *Provisioner) ElevatedPassword() string {
|
func (p *Provisioner) ElevatedPassword() string {
|
||||||
// Replace ElevatedPassword for winrm users who used this feature
|
// Replace ElevatedPassword for winrm users who used this feature
|
||||||
p.config.ctx.Data = &EnvVarsTemplate{
|
p.config.ctx.Data = p.generatedData
|
||||||
WinRMPassword: getWinRMPassword(p.config.PackerBuildName),
|
|
||||||
}
|
|
||||||
|
|
||||||
elevatedPassword, _ := interpolate.Render(p.config.ElevatedPassword, &p.config.ctx)
|
elevatedPassword, _ := interpolate.Render(p.config.ElevatedPassword, &p.config.ctx)
|
||||||
|
|
||||||
|
|
|
@ -259,7 +259,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
ui.Say("Provisioning with Puppet...")
|
ui.Say("Provisioning with Puppet...")
|
||||||
p.communicator = comm
|
p.communicator = comm
|
||||||
ui.Message("Creating Puppet staging directory...")
|
ui.Message("Creating Puppet staging directory...")
|
||||||
|
|
|
@ -229,7 +229,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
ui.Say("Provisioning with Puppet...")
|
ui.Say("Provisioning with Puppet...")
|
||||||
p.communicator = comm
|
p.communicator = comm
|
||||||
ui.Message("Creating Puppet staging directory...")
|
ui.Message("Creating Puppet staging directory...")
|
||||||
|
|
|
@ -222,7 +222,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
var err error
|
var err error
|
||||||
var src, dst string
|
var src, dst string
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, _ packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, _ packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
_, retErr := sl.Run(ctx, ui, &p.config)
|
_, retErr := sl.Run(ctx, ui, &p.config)
|
||||||
|
|
||||||
return retErr
|
return retErr
|
||||||
|
|
|
@ -179,7 +179,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
scripts := make([]string, len(p.config.Scripts))
|
scripts := make([]string, len(p.config.Scripts))
|
||||||
copy(scripts, p.config.Scripts)
|
copy(scripts, p.config.Scripts)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return config.Decode(&p, &config.DecodeOpts{}, raws...)
|
return config.Decode(&p, &config.DecodeOpts{}, raws...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, _ packer.Ui, _ packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, _ packer.Ui, _ packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
|
|
|
@ -96,7 +96,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
p.cancelLock.Lock()
|
p.cancelLock.Lock()
|
||||||
p.cancel = make(chan struct{})
|
p.cancel = make(chan struct{})
|
||||||
p.cancelLock.Unlock()
|
p.cancelLock.Unlock()
|
||||||
|
|
|
@ -156,7 +156,7 @@ func extractScript(p *Provisioner) (string, error) {
|
||||||
return temp.Name(), nil
|
return temp.Name(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error {
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ *packer.ProvisionHookData) error {
|
||||||
ui.Say(fmt.Sprintf("Provisioning with windows-shell..."))
|
ui.Say(fmt.Sprintf("Provisioning with windows-shell..."))
|
||||||
scripts := make([]string, len(p.config.Scripts))
|
scripts := make([]string, len(p.config.Scripts))
|
||||||
copy(scripts, p.config.Scripts)
|
copy(scripts, p.config.Scripts)
|
||||||
|
|
Loading…
Reference in New Issue