|
|
|
|
@ -30,7 +30,6 @@ import (
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer/common"
|
|
|
|
|
"github.com/hashicorp/packer/common/adapter"
|
|
|
|
|
commonhelper "github.com/hashicorp/packer/helper/common"
|
|
|
|
|
"github.com/hashicorp/packer/helper/config"
|
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
|
"github.com/hashicorp/packer/packer/tmp"
|
|
|
|
|
@ -75,20 +74,14 @@ type Provisioner struct {
|
|
|
|
|
done chan struct{}
|
|
|
|
|
ansibleVersion string
|
|
|
|
|
ansibleMajVersion uint
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PassthroughTemplate struct {
|
|
|
|
|
WinRMPassword string
|
|
|
|
|
generatedData map[string]interface{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|
|
|
|
p.done = make(chan struct{})
|
|
|
|
|
|
|
|
|
|
// Create passthrough for winrm password so we can fill it in once we know
|
|
|
|
|
// it
|
|
|
|
|
p.config.ctx.Data = &PassthroughTemplate{
|
|
|
|
|
WinRMPassword: `{{.WinRMPassword}}`,
|
|
|
|
|
}
|
|
|
|
|
// Create passthrough for build-generated data
|
|
|
|
|
p.config.ctx.Data = common.PlaceholderData()
|
|
|
|
|
|
|
|
|
|
err := config.Decode(&p.config, &config.DecodeOpts{
|
|
|
|
|
Interpolate: true,
|
|
|
|
|
@ -214,12 +207,11 @@ func (p *Provisioner) getVersion() error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, _ map[string]interface{}) error {
|
|
|
|
|
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData map[string]interface{}) error {
|
|
|
|
|
ui.Say("Provisioning with Ansible...")
|
|
|
|
|
// Interpolate env vars to check for .WinRMPassword
|
|
|
|
|
p.config.ctx.Data = &PassthroughTemplate{
|
|
|
|
|
WinRMPassword: getWinRMPassword(p.config.PackerBuildName),
|
|
|
|
|
}
|
|
|
|
|
// Interpolate env vars to check for generated values like password and port
|
|
|
|
|
p.generatedData = generatedData
|
|
|
|
|
p.config.ctx.Data = generatedData
|
|
|
|
|
for i, envVar := range p.config.AnsibleEnvVars {
|
|
|
|
|
envVar, err := interpolate.Render(envVar, &p.config.ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
@ -227,7 +219,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C
|
|
|
|
|
}
|
|
|
|
|
p.config.AnsibleEnvVars[i] = envVar
|
|
|
|
|
}
|
|
|
|
|
// Interpolate extra vars to check for .WinRMPassword
|
|
|
|
|
// Interpolate extra vars to check for generated values like password and port
|
|
|
|
|
for i, arg := range p.config.ExtraArguments {
|
|
|
|
|
arg, err := interpolate.Render(arg, &p.config.ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
@ -502,9 +494,10 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator, pri
|
|
|
|
|
// remove winrm password from command, if it's been added
|
|
|
|
|
flattenedCmd := strings.Join(cmd.Args, " ")
|
|
|
|
|
sanitized := flattenedCmd
|
|
|
|
|
if len(getWinRMPassword(p.config.PackerBuildName)) > 0 {
|
|
|
|
|
winRMPass, ok := p.generatedData["WinRMPassword"]
|
|
|
|
|
if ok {
|
|
|
|
|
sanitized = strings.Replace(sanitized,
|
|
|
|
|
getWinRMPassword(p.config.PackerBuildName), "*****", -1)
|
|
|
|
|
winRMPass.(string), "*****", -1)
|
|
|
|
|
}
|
|
|
|
|
ui.Say(fmt.Sprintf("Executing Ansible: %s", sanitized))
|
|
|
|
|
|
|
|
|
|
@ -633,9 +626,3 @@ func newSigner(privKeyFile string) (*signer, error) {
|
|
|
|
|
|
|
|
|
|
return signer, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getWinRMPassword(buildName string) string {
|
|
|
|
|
winRMPass, _ := commonhelper.RetrieveSharedState("winrm_password", buildName)
|
|
|
|
|
packer.LogSecretFilter.Set(winRMPass)
|
|
|
|
|
return winRMPass
|
|
|
|
|
}
|
|
|
|
|
|