# ssh\_alt & tty

**URL:** <https://forum.ansible.com/t/ssh-alt-tty/14367>\
**Category:** Ansible Developer\
**Created:** [January 17, 2014, 5:08pm UTC](https://forum.ansible.com/t/ssh-alt-tty/14367 "2014-01-17T17:08:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [January 17, 2014, 5:08pm UTC](https://forum.ansible.com/t/ssh-alt-tty/14367/1 "2014-01-17T17:08:30Z")

</div>

Hello,

I saw that ssh alt replaced ssh on devel :-)) great news + that at this stage it must be activated with pipelining = True because of a doubt on tty.

Have you seen problems related to that ?

For information, from what I tried, I think it could be possible to make ssh\_alt work with tty at one condition :  
that all modules must be python-interactive compatible (i.e. no pretty newlines breaking identation scope for instance).

it seems that when there is a TTY, python always goes to interactive mode when you pipe into it.

Jerome

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [January 17, 2014, 5:51pm UTC](https://forum.ansible.com/t/ssh-alt-tty/14367/2 "2014-01-17T17:51:51Z")

</div>

Yes, many of our default test systems were using requiretty and were seeing issues with sudoing.

I’d be very very interested in the above if you can make it happen, though I’d like to understand more.

What’s a pretty newline? (Do you perhaps mean that we’d munge the newlines out? If so, I’d be fine with that I think – care would be taken to not affect the module argument interpolation?)

---

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [January 17, 2014, 9:03pm UTC](https://forum.ansible.com/t/ssh-alt-tty/14367/3 "2014-01-17T21:03:43Z")

</div>

I just tried to rewire the code to have some result with tty enabled. I managed to find this wiring again 🙂

here is below the kind of mumbo jumbo that it spits out.

The problem is I think that

def main:  
\<=== This should be removed  
if test:

Hello  
===\> This should be added

print test

another potential issue is that python interactive mode is probably not thread safe (hangs on blocking commands). Do you know if modules are supposed to use threads ?

another option could be to change the ssh command :

but I don’t know if this can work with tty enabled either.

mumbo jumbo from pilelining with tty enabled :

IndentationError: unexpected indent

> > > if context[i] is None:  
> > > File “”, line 1  
> > > if context[i] is None:  
> > > ^  
> > > IndentationError: unexpected indent
> > > 
> > > new\_context[i] = cur\_context[i]  
> > > File “”, line 1  
> > > new\_context[i] = cur\_context[i]  
> > > ^  
> > > IndentationError: unexpected indent
> > > 
> > > if cur\_context != new\_context:  
> > > File “”, line 1  
> > > if cur\_context != new\_context:  
> > > ^  
> > > IndentationError: unexpected indent

---

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [January 19, 2014, 12:29am UTC](https://forum.ansible.com/t/ssh-alt-tty/14367/4 "2014-01-19T00:29:45Z")

</div>

Here is a proof-of-concept of pipelining+tty so that you can see what it could look like with this python-interactive thing.

I must say it was painful (and is still a prototype). This code works with “command: echo ping”. did not test with something else.

[https://github.com/jeromew/ansible/commit/b88f385b24ed3a9e04b0ce69de2441ad0d4aa67f](https://github.com/jeromew/ansible/commit/b88f385b24ed3a9e04b0ce69de2441ad0d4aa67f)

the main idea for pipelining+tty to work is that the module code must work if you copy/paste it in a python interactive shell ; that’s more easy said than done.

2 potential benefits :

- most of the ssh\_alt.py can be reverted to ssh.py by removing all the “no-tty” specific handling.
- you get some kind of streamer and could imagine sending modules on that stream without even reconnecting ;

on the downside, the need to tokenize/untokenize the code looks horrible on a maintenance level except if a python expert can put a seal on this (or on an equivalent rewrite).

The stdin.write code should be improved as well. it works now in the prototype so I leave it as is.

Tell me what you think.
