diff --git a/builder/vmware/common/ssh.go b/builder/vmware/common/ssh.go index c463f5f78..a931dd734 100644 --- a/builder/vmware/common/ssh.go +++ b/builder/vmware/common/ssh.go @@ -17,6 +17,10 @@ func SSHAddressFunc(config *SSHConfig) func(multistep.StateBag) (string, error) driver := state.Get("driver").(Driver) vmxPath := state.Get("vmx_path").(string) + if config.SSHHost != "" { + return fmt.Sprintf("%s:%d", config.SSHHost, config.SSHPort), nil + } + log.Println("Lookup up IP information...") f, err := os.Open(vmxPath) if err != nil { diff --git a/builder/vmware/common/ssh_config.go b/builder/vmware/common/ssh_config.go index 1299bc772..8bb616c17 100644 --- a/builder/vmware/common/ssh_config.go +++ b/builder/vmware/common/ssh_config.go @@ -3,6 +3,7 @@ package common import ( "errors" "fmt" + "net" "os" "time" @@ -13,6 +14,7 @@ type SSHConfig struct { SSHUser string `mapstructure:"ssh_username"` SSHKeyPath string `mapstructure:"ssh_key_path"` SSHPassword string `mapstructure:"ssh_password"` + SSHHost string `mapstructure:"ssh_host"` SSHPort uint `mapstructure:"ssh_port"` SSHSkipRequestPty bool `mapstructure:"ssh_skip_request_pty"` RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"` @@ -53,6 +55,14 @@ func (c *SSHConfig) Prepare(t *packer.ConfigTemplate) []error { } } + if c.SSHHost != "" { + if ip := net.ParseIP(c.SSHHost); ip == nil { + if _, err := net.LookupHost(c.SSHHost); err != nil { + errs = append(errs, errors.New("ssh_host is an invalid IP or hostname")) + } + } + } + if c.SSHUser == "" { errs = append(errs, errors.New("An ssh_username must be specified.")) } diff --git a/website/source/docs/builders/vmware-iso.html.markdown b/website/source/docs/builders/vmware-iso.html.markdown index 8de9e13ec..dd545f56a 100644 --- a/website/source/docs/builders/vmware-iso.html.markdown +++ b/website/source/docs/builders/vmware-iso.html.markdown @@ -185,6 +185,9 @@ Optional: The associated public key is expected to already be configured on the VM being prepared by some other process (kickstart, etc.). +* `ssh_host` (string) - Hostname or IP address of the host. By default, DHCP + is used to connect to the host and this field is not used. + * `ssh_password` (string) - The password for `ssh_username` to use to authenticate with SSH. By default this is the empty string.