replace duplicate commHost functions with a single communicator helper that checks for ssh_host and does a statebag lookup for a given key
This commit is contained in:
@@ -77,7 +77,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
|
||||
&stepSetupNetworking{},
|
||||
&communicator.StepConnect{
|
||||
Config: &b.config.Comm,
|
||||
Host: commHost(b.config.Comm.SSHHost),
|
||||
Host: communicator.CommHost(b.config.Comm.SSHHost, "ipaddress"),
|
||||
SSHConfig: b.config.Comm.SSHConfigFunc(),
|
||||
SSHPort: commPort,
|
||||
WinRMPort: commPort,
|
||||
|
||||
@@ -7,21 +7,6 @@ import (
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
)
|
||||
|
||||
func commHost(host string) func(multistep.StateBag) (string, error) {
|
||||
return func(state multistep.StateBag) (string, error) {
|
||||
if host != "" {
|
||||
log.Printf("Using ssh_host value: %s", host)
|
||||
return host, nil
|
||||
}
|
||||
ip, hasIP := state.Get("ipaddress").(string)
|
||||
if !hasIP {
|
||||
return "", fmt.Errorf("Failed to retrieve IP address")
|
||||
}
|
||||
|
||||
return ip, nil
|
||||
}
|
||||
}
|
||||
|
||||
func commPort(state multistep.StateBag) (int, error) {
|
||||
commPort, hasPort := state.Get("commPort").(int)
|
||||
if !hasPort {
|
||||
|
||||
Reference in New Issue
Block a user