Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow requesting a PTY #121

Merged
merged 1 commit into from
Jul 1, 2016
Merged

Allow requesting a PTY #121

merged 1 commit into from
Jul 1, 2016

Conversation

srenatus
Copy link
Contributor

@srenatus srenatus commented Jul 1, 2016

This change allows the user to request a pseudo-tty:

require 'train'
t = Train.create('ssh', host: '127.0.0.1', port: '2200', user: 'vagrant', password: 'vagrant', sudo: true, pty: true);
puts t.connection.run_command("ls /")

While this allows passing the requiretty sudoer defaults of certain
RedHat-ish distributions, it comes at the cost of having stderr and
stdout merged together. The change includes a warning for this.

The command above, for example, outputs:

<struct Train::Extras::CommandResult stdout="/etc/profile.d/lang.sh: line 19: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory\r\nbin dev  home  lib64\tmnt  proc  run\t shared  sys  usr      var\r\nboot  etc  lib\t media\topt  root  sbin  srv\t tmp  vagrant\r\n", stderr="", exit_status=0>

For comparison, this is the output without the PTY:

<struct Train::Extras::CommandResult stdout="bin\nboot\ndev\netc\nhome\nlib\nlib64\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nshared\nsrv\nsys\ntmp\nusr\nvagrant\nvar\n", stderr="/etc/profile.d/lang.sh: line 19: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory\n", exit_status=0>

Note how ls behaves differently -- in the presence of a PTY, it will
prettify its output.


Fixes #60.

This is still not a fix for InSpec failing with the requiretty issue, since the merging of std{err,out} will probably break most profiles and resources relying on the distinction. However, for users using train for remote execution, that do not that strongly depend on it, it's a necessary feature.

This change allows the user to request a pseudo-tty:

```
require 'train'
t = Train.create('ssh', host: '127.0.0.1', port: '2200', user: 'vagrant', password: 'vagrant', sudo: true, pty: true);
puts t.connection.run_command("ls /")
```

While this allows passing the `requiretty` sudoer defaults of certain
RedHat-ish distributions, it comes at the cost of having stderr and
stdout merged together. The change includes a warning for this.

The command above, for example, outputs:

```
<struct Train::Extras::CommandResult stdout="/etc/profile.d/lang.sh: line 19: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory\r\nbin dev  home  lib64\tmnt  proc  run\t shared  sys  usr      var\r\nboot  etc  lib\t media\topt  root  sbin  srv\t tmp  vagrant\r\n", stderr="", exit_status=0>
```

For comparison, this is the output _without_ the PTY:

```
<struct Train::Extras::CommandResult stdout="bin\nboot\ndev\netc\nhome\nlib\nlib64\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nshared\nsrv\nsys\ntmp\nusr\nvagrant\nvar\n", stderr="/etc/profile.d/lang.sh: line 19: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory\n", exit_status=0>
```

Note how `ls` behaves differently -- in the presence of a PTY, it will
prettify its output.
@srenatus srenatus force-pushed the BP-202/allow_requiring_a_pty branch from f7cff6d to 3d67a43 Compare July 1, 2016 09:41
@arlimus
Copy link
Contributor

arlimus commented Jul 1, 2016

👍

@arlimus arlimus merged commit 7e1442a into master Jul 1, 2016
@arlimus arlimus deleted the BP-202/allow_requiring_a_pty branch July 1, 2016 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

have net-ssh request a pty
3 participants