Fix ssh_host bug in hyper-v builders.

This commit is contained in:
Ladar Levison 2018-12-27 02:33:58 -06:00
parent 141f3b29f3
commit cb0011d665
3 changed files with 24 additions and 14 deletions

View File

@ -1,22 +1,32 @@
package common package common
import ( import (
"log"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
) )
func CommHost(state multistep.StateBag) (string, error) { func CommHost(host string) func(multistep.StateBag) (string, error) {
vmName := state.Get("vmName").(string) return func(state multistep.StateBag) (string, error) {
driver := state.Get("driver").(Driver)
mac, err := driver.Mac(vmName) if host != "" {
if err != nil { log.Println("Using ssh_host value: %s", ipAddress)
return "", err return host, nil
} }
ip, err := driver.IpAddress(mac) vmName := state.Get("vmName").(string)
if err != nil { driver := state.Get("driver").(Driver)
return "", err
}
return ip, nil mac, err := driver.Mac(vmName)
if err != nil {
return "", err
}
ip, err := driver.IpAddress(mac)
if err != nil {
return "", err
}
return ip, nil
}
} }

View File

@ -459,7 +459,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// configure the communicator ssh, winrm // configure the communicator ssh, winrm
&communicator.StepConnect{ &communicator.StepConnect{
Config: &b.config.SSHConfig.Comm, Config: &b.config.SSHConfig.Comm,
Host: hypervcommon.CommHost, Host: hypervcommon.CommHost(b.config.SSHConfig.Comm.SSHHost),
SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(), SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(),
}, },

View File

@ -482,7 +482,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// configure the communicator ssh, winrm // configure the communicator ssh, winrm
&communicator.StepConnect{ &communicator.StepConnect{
Config: &b.config.SSHConfig.Comm, Config: &b.config.SSHConfig.Comm,
Host: hypervcommon.CommHost, Host: hypervcommon.CommHost(b.config.SSHConfig.Comm.SSHHost),
SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(), SSHConfig: b.config.SSHConfig.Comm.SSHConfigFunc(),
}, },