diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index a01d3f4cb..a221d02da 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -58,7 +58,7 @@ type Config struct { UseSFTP bool `mapstructure:"use_sftp"` InventoryDirectory string `mapstructure:"inventory_directory"` InventoryFile string `mapstructure:"inventory_file"` - SetPackerPasswd bool `mapstructure:"set_packer_passwd"` + SetWinrmPasswd bool `mapstructure:"set_winrm_passwd"` } type Provisioner struct { @@ -120,11 +120,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { p.config.AnsibleEnvVars = append(p.config.AnsibleEnvVars, "ANSIBLE_SCP_IF_SSH=True") } - if p.config.SetPackerPasswd { - var PackerEnvVar string = fmt.Sprintf("PACKER_RANDOM_PASSWORD=%s", getWinRMPassword()) - p.config.AnsibleEnvVars = append(p.config.AnsibleEnvVars, PackerEnvVar) - } - if len(p.config.LocalPort) > 0 { if _, err := strconv.ParseUint(p.config.LocalPort, 10, 16); err != nil { errs = packer.MultiErrorAppend(errs, fmt.Errorf("local_port: %s must be a valid port", p.config.LocalPort)) @@ -196,6 +191,12 @@ func (p *Provisioner) getVersion() error { func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { ui.Say("Provisioning with Ansible...") + if p.config.SetWinrmPasswd { + var WinrmEnvVar string = fmt.Sprintf("GENERATED_WINRM_PASSWORD=%s", getWinRMPassword(p.config.PackerBuildName)) + p.config.AnsibleEnvVars = append(p.config.AnsibleEnvVars, WinrmEnvVar) + ui.Say("Setting Environment variable GENERATED_WINRM_PASSWORD to WinRM password.") + } + k, err := newUserKey(p.config.SSHAuthorizedKeyFile) if err != nil { return err @@ -515,10 +516,9 @@ func newSigner(privKeyFile string) (*signer, error) { return signer, nil } -func getWinRMPassword() string { - winRMPass, _ := commonhelper.RetrieveSharedState("winrm_password") +func getWinRMPassword(buildName string) string { + winRMPass, _ := commonhelper.RetrieveSharedState("winrm_password", buildName) return winRMPass - } // Ui provides concurrency-safe access to packer.Ui.