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

Remove command timeout. #303

Merged
merged 1 commit into from
May 3, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 4 additions & 12 deletions lib/ansible/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,10 @@ def connect(self):
return self

def exec_command(self, cmd, tmp_path, sudoable=False):

''' run a command on the remote host '''

bufsize = 4096
# reusing runner's TCP connect timeout as command progress timeout (correct?)
timeout_secs = self.runner.timeout
chan = self.ssh.get_transport().open_session()
chan.settimeout(timeout_secs)
stdin = chan.makefile('wb', bufsize)
stdout = chan.makefile('rb', bufsize)
stderr = chan.makefile_stderr('rb', bufsize)
chan.get_pty()
chan.set_combine_stderr(False)

if not self.runner.sudo or not sudoable:
quoted_command = '"$SHELL" -c ' + pipes.quote(cmd)
Expand All @@ -150,8 +141,9 @@ def exec_command(self, cmd, tmp_path, sudoable=False):
# tells sudo that this is the end of sudo options and the command
# follows. Passing a quoted compound command to sudo (or sudo -s)
# directly doesn't work, so we shellquote it with pipes.quote()
# and pass the quoted string to the user's shell.

# and pass the quoted string to the user's shell. We loop reading
# output until we see the randomly-generated sudo prompt set with
# the -p option.
randbits = ''.join(chr(random.randint(ord('a'), ord('z'))) for x in xrange(32))
prompt = '[sudo via ansible, key=%s] password: ' % randbits
sudocmd = 'sudo -k -p "%s" -- "$SHELL" -c %s' % (prompt, pipes.quote(cmd))
Expand All @@ -170,7 +162,7 @@ def exec_command(self, cmd, tmp_path, sudoable=False):

stdin = chan.makefile('wb', bufsize)
stdout = chan.makefile('rb', bufsize)
stderr = chan.makefile_stderr('rb', bufsize)
stderr = chan.makefile_stderr('rb', bufsize) # stderr goes to stdout when using a pty, so this will never output anything.
return stdin, stdout, stderr

def put_file(self, in_path, out_path):
Expand Down