From 20541a7eda085aa5cf35bfed5069592ca49d106e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 27 Aug 2013 16:51:05 -0700 Subject: [PATCH] builder/vmware: ability to not request a PTY for SSH [GH-270] --- CHANGELOG.md | 2 ++ builder/vmware/builder.go | 2 ++ common/step_connect_ssh.go | 4 ++++ communicator/ssh/communicator.go | 21 ++++++++++++------- .../source/docs/builders/vmware.html.markdown | 4 ++++ 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 801acdef6..52d312039 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ IMPROVEMENTS: * core: Output message when Ctrl-C received that we're cleaning up. [GH-338] * builder/amazon: Tagging now works with all amazon builder types. +* builder/vmware: Option `ssh_skip_request_pty` for not requesting a PTY + for the SSH connection. [GH-270] * command/build: Machine-readable output now contains build errors, if any. * command/build: An "end" sentinel is outputted in machine-readable output for artifact listing so it is easier to know when it is over. diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index fa0707e90..8f56e9e23 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -45,6 +45,7 @@ type config struct { SSHUser string `mapstructure:"ssh_username"` SSHPassword string `mapstructure:"ssh_password"` SSHPort uint `mapstructure:"ssh_port"` + SSHSkipRequestPty bool `mapstructure:"ssh_skip_request_pty"` ToolsUploadFlavor string `mapstructure:"tools_upload_flavor"` ToolsUploadPath string `mapstructure:"tools_upload_path"` VMXData map[string]string `mapstructure:"vmx_data"` @@ -342,6 +343,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe SSHAddress: sshAddress, SSHConfig: sshConfig, SSHWaitTimeout: b.config.sshWaitTimeout, + NoPty: b.config.SSHSkipRequestPty, }, &stepUploadTools{}, &common.StepProvision{}, diff --git a/common/step_connect_ssh.go b/common/step_connect_ssh.go index b30969852..7d5c699ea 100644 --- a/common/step_connect_ssh.go +++ b/common/step_connect_ssh.go @@ -34,6 +34,9 @@ type StepConnectSSH struct { // SSHWaitTimeout is the total timeout to wait for SSH to become available. SSHWaitTimeout time.Duration + // NoPty, if true, will not request a Pty from the remote end. + NoPty bool + comm packer.Communicator } @@ -128,6 +131,7 @@ func (s *StepConnectSSH) waitForSSH(state map[string]interface{}, cancel <-chan config := &ssh.Config{ Connection: connFunc, SSHConfig: sshConfig, + NoPty: s.NoPty, } log.Println("Attempting SSH connection...") diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index 35ff8f0ca..5b8450365 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -29,6 +29,9 @@ type Config struct { // in use will be closed as part of the Close method, or in the // case an error occurs. Connection func() (net.Conn, error) + + // NoPty, if true, will not request a pty from the remote end. + NoPty bool } // Creates a new packer.Communicator implementation over SSH. This takes @@ -58,15 +61,17 @@ func (c *comm) Start(cmd *packer.RemoteCmd) (err error) { session.Stdout = cmd.Stdout session.Stderr = cmd.Stderr - // Request a PTY - termModes := ssh.TerminalModes{ - ssh.ECHO: 0, // do not echo - ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud - ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud - } + if !c.config.NoPty { + // Request a PTY + termModes := ssh.TerminalModes{ + ssh.ECHO: 0, // do not echo + ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud + ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud + } - if err = session.RequestPty("xterm", 80, 40, termModes); err != nil { - return + if err = session.RequestPty("xterm", 80, 40, termModes); err != nil { + return + } } log.Printf("starting remote command: %s", cmd.Command) diff --git a/website/source/docs/builders/vmware.html.markdown b/website/source/docs/builders/vmware.html.markdown index 98a74e1c9..aad32fefe 100644 --- a/website/source/docs/builders/vmware.html.markdown +++ b/website/source/docs/builders/vmware.html.markdown @@ -154,6 +154,10 @@ Optional: * `ssh_port` (int) - The port that SSH will listen on within the virtual machine. By default this is 22. +* `ssh_skip_request_pty` (bool) - If true, a pty will not be requested as + part of the SSH connection. By default, this is "false", so a pty + _will_ be requested. + * `ssh_wait_timeout` (string) - The duration to wait for SSH to become available. By default this is "20m", or 20 minutes. Note that this should be quite long since the timer begins as soon as the virtual machine is booted.