ansible/ansible — pull request #5729 by jeromew (2014-01-22 22:36:51+00:00)
Title: ssh pipelining + tty, use python -c

Here is a proposal for pipelining + tty. It works on my production playbook so I am fairly confident.

My hopes of a real pipeline in the TTY cases are pretty low after a lot of research. This is because python automatically enters the interactive shell mode when tty is activated and this slows things down. It is very slow because in order to make it work you have to send the code line by line, waiting for a ">>> " or a "... " prompt before sending another line. There seem to be limits on the size of the lines and is all very annoying.

This new version takes another approach by using the "python -c" flag : you can send the whole module as an argument of the python command. This works with TTY activated.

I added a requireTTY = True variable at the top so this could become either a configuration variable or something sent from another part of the code ; when requireTTY = false, the usual pipelining stuff takes place.

On the "cons" side :

- there is a limit regarding the size of linux command line

```
$xargs --show-limits
Your environment variables take up 2820 bytes
POSIX upper limit on argument length (this system): 2092284
POSIX smallest allowable upper limit on argument length (all systems): 4096
Maximum length of command we could actually use: 2089464
Size of command buffer we are actually using: 131072
```

so 131K is the default limit (fedora19). I guess this is pretty standard but I have no idea.

now if you take the module code, the maximum byte size is 96K for m=setup. you have to add to this the module boilerplate.

now you have to take into account that this is escaped N times (sudo, sh, sh, ssh whatever), so a single quote (one ' ) gets expanded to a sort of "'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"

that's a big hit on the 131 limit, and I have experienced a problem with : user, service, setup.

in order to solve this issue, I needed to lower the number of single quotes and increase the number of double quotes which are not escaped in this case (pipe.quotes)

This is done by a tokenize/untokenize loop at the python level because I was more confident I could make it work this way than by monkey regexing the module code.

This can be considered a hack ; but it is a working hack for the TTY case :-)

I hope you will have time to review it and maybe accept it :-)