2013-08-07 17:54:53 +02:00
|
|
|
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import base64
|
|
|
|
import socket
|
2013-08-11 07:41:18 +02:00
|
|
|
import struct
|
2013-08-29 02:27:18 +02:00
|
|
|
import time
|
2013-09-30 21:08:07 +02:00
|
|
|
from ansible.callbacks import vvv, vvvv
|
2014-03-19 18:59:06 +01:00
|
|
|
from ansible.errors import AnsibleError, AnsibleFileNotFound
|
2013-08-11 07:41:18 +02:00
|
|
|
from ansible.runner.connection_plugins.ssh import Connection as SSHConnection
|
2013-09-04 22:50:53 +02:00
|
|
|
from ansible.runner.connection_plugins.paramiko_ssh import Connection as ParamikoConnection
|
2013-08-07 17:54:53 +02:00
|
|
|
from ansible import utils
|
|
|
|
from ansible import constants
|
|
|
|
|
2013-08-28 17:05:52 +02:00
|
|
|
# the chunk size to read and send, assuming mtu 1500 and
|
|
|
|
# leaving room for base64 (+33%) encoding and header (8 bytes)
|
|
|
|
# ((1400-8)/4)*3) = 1044
|
|
|
|
# which leaves room for the TCP/IP header. We set this to a
|
|
|
|
# multiple of the value to speed up file reads.
|
|
|
|
CHUNK_SIZE=1044*20
|
|
|
|
|
2013-08-07 17:54:53 +02:00
|
|
|
class Connection(object):
|
|
|
|
''' raw socket accelerated connection '''
|
|
|
|
|
2013-08-11 07:41:18 +02:00
|
|
|
def __init__(self, runner, host, port, user, password, private_key_file, *args, **kwargs):
|
|
|
|
|
2013-08-07 17:54:53 +02:00
|
|
|
self.runner = runner
|
2013-08-11 07:41:18 +02:00
|
|
|
self.host = host
|
|
|
|
self.context = None
|
|
|
|
self.conn = None
|
2013-08-27 22:25:54 +02:00
|
|
|
self.user = user
|
2013-08-11 07:41:18 +02:00
|
|
|
self.key = utils.key_for_hostname(host)
|
2013-08-27 22:25:54 +02:00
|
|
|
self.port = port[0]
|
2013-09-04 22:29:46 +02:00
|
|
|
self.accport = port[1]
|
2013-08-11 07:41:18 +02:00
|
|
|
self.is_connected = False
|
2013-12-11 10:55:56 +01:00
|
|
|
self.has_pipelining = False
|
2014-11-24 22:36:31 +01:00
|
|
|
self.become_methods_supported=['sudo']
|
2013-08-07 17:54:53 +02:00
|
|
|
|
2013-09-05 16:52:10 +02:00
|
|
|
if not self.port:
|
|
|
|
self.port = constants.DEFAULT_REMOTE_PORT
|
|
|
|
elif not isinstance(self.port, int):
|
|
|
|
self.port = int(self.port)
|
|
|
|
|
|
|
|
if not self.accport:
|
|
|
|
self.accport = constants.ACCELERATE_PORT
|
|
|
|
elif not isinstance(self.accport, int):
|
|
|
|
self.accport = int(self.accport)
|
|
|
|
|
2013-09-04 22:50:53 +02:00
|
|
|
if self.runner.original_transport == "paramiko":
|
|
|
|
self.ssh = ParamikoConnection(
|
|
|
|
runner=self.runner,
|
|
|
|
host=self.host,
|
|
|
|
port=self.port,
|
|
|
|
user=self.user,
|
|
|
|
password=password,
|
|
|
|
private_key_file=private_key_file
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
self.ssh = SSHConnection(
|
|
|
|
runner=self.runner,
|
|
|
|
host=self.host,
|
|
|
|
port=self.port,
|
|
|
|
user=self.user,
|
|
|
|
password=password,
|
|
|
|
private_key_file=private_key_file
|
|
|
|
)
|
2013-08-27 22:25:54 +02:00
|
|
|
|
2014-08-28 15:21:09 +02:00
|
|
|
if not getattr(self.ssh, 'shell', None):
|
|
|
|
self.ssh.shell = utils.plugins.shell_loader.get('sh')
|
|
|
|
|
2013-08-07 17:54:53 +02:00
|
|
|
# attempt to work around shared-memory funness
|
|
|
|
if getattr(self.runner, 'aes_keys', None):
|
|
|
|
utils.AES_KEYS = self.runner.aes_keys
|
|
|
|
|
2013-09-04 22:29:46 +02:00
|
|
|
def _execute_accelerate_module(self):
|
2014-03-23 20:45:05 +01:00
|
|
|
args = "password=%s port=%s minutes=%d debug=%d ipv6=%s" % (
|
|
|
|
base64.b64encode(self.key.__str__()),
|
|
|
|
str(self.accport),
|
|
|
|
constants.ACCELERATE_DAEMON_TIMEOUT,
|
|
|
|
int(utils.VERBOSITY),
|
|
|
|
self.runner.accelerate_ipv6,
|
|
|
|
)
|
2014-03-19 18:59:06 +01:00
|
|
|
if constants.ACCELERATE_MULTI_KEY:
|
|
|
|
args += " multi_key=yes"
|
2013-09-04 22:29:46 +02:00
|
|
|
inject = dict(password=self.key)
|
2013-11-27 22:58:11 +01:00
|
|
|
if getattr(self.runner, 'accelerate_inventory_host', False):
|
2013-09-25 15:54:54 +02:00
|
|
|
inject = utils.combine_vars(inject, self.runner.inventory.get_variables(self.runner.accelerate_inventory_host))
|
|
|
|
else:
|
|
|
|
inject = utils.combine_vars(inject, self.runner.inventory.get_variables(self.host))
|
2013-09-30 21:08:07 +02:00
|
|
|
vvvv("attempting to start up the accelerate daemon...")
|
2013-08-11 07:41:18 +02:00
|
|
|
self.ssh.connect()
|
2013-08-13 05:57:41 +02:00
|
|
|
tmp_path = self.runner._make_tmp_path(self.ssh)
|
2013-09-04 22:29:46 +02:00
|
|
|
return self.runner._execute_module(self.ssh, tmp_path, 'accelerate', args, inject=inject)
|
2013-08-07 17:54:53 +02:00
|
|
|
|
2013-08-11 07:41:18 +02:00
|
|
|
def connect(self, allow_ssh=True):
|
2013-08-07 17:54:53 +02:00
|
|
|
''' activates the connection object '''
|
|
|
|
|
2013-08-11 07:41:18 +02:00
|
|
|
try:
|
2013-08-27 20:12:35 +02:00
|
|
|
if not self.is_connected:
|
2014-01-30 21:39:52 +01:00
|
|
|
wrong_user = False
|
2013-09-03 19:27:58 +02:00
|
|
|
tries = 3
|
2013-08-27 20:12:35 +02:00
|
|
|
self.conn = socket.socket()
|
2013-09-19 21:11:36 +02:00
|
|
|
self.conn.settimeout(constants.ACCELERATE_CONNECT_TIMEOUT)
|
2013-09-30 21:08:07 +02:00
|
|
|
vvvv("attempting connection to %s via the accelerated port %d" % (self.host,self.accport))
|
2013-08-27 20:12:35 +02:00
|
|
|
while tries > 0:
|
|
|
|
try:
|
2013-09-04 22:29:46 +02:00
|
|
|
self.conn.connect((self.host,self.accport))
|
2013-08-27 20:12:35 +02:00
|
|
|
break
|
2014-03-19 18:59:06 +01:00
|
|
|
except socket.error:
|
|
|
|
vvvv("connection to %s failed, retrying..." % self.host)
|
2013-08-27 20:12:35 +02:00
|
|
|
time.sleep(0.1)
|
|
|
|
tries -= 1
|
|
|
|
if tries == 0:
|
2013-08-30 20:24:24 +02:00
|
|
|
vvv("Could not connect via the accelerated connection, exceeded # of tries")
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("FAILED")
|
2014-01-30 21:39:52 +01:00
|
|
|
elif wrong_user:
|
|
|
|
vvv("Restarting daemon with a different remote_user")
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("WRONG_USER")
|
|
|
|
|
2013-10-01 22:33:18 +02:00
|
|
|
self.conn.settimeout(constants.ACCELERATE_TIMEOUT)
|
2014-03-19 18:59:06 +01:00
|
|
|
if not self.validate_user():
|
|
|
|
# the accelerated daemon was started with a
|
|
|
|
# different remote_user. The above command
|
|
|
|
# should have caused the accelerate daemon to
|
|
|
|
# shutdown, so we'll reconnect.
|
|
|
|
wrong_user = True
|
|
|
|
|
|
|
|
except AnsibleError, e:
|
2013-08-11 07:41:18 +02:00
|
|
|
if allow_ssh:
|
2014-03-19 18:59:06 +01:00
|
|
|
if "WRONG_USER" in e:
|
|
|
|
vvv("Switching users, waiting for the daemon on %s to shutdown completely..." % self.host)
|
|
|
|
time.sleep(5)
|
2013-08-27 20:12:35 +02:00
|
|
|
vvv("Falling back to ssh to startup accelerated mode")
|
2013-09-04 22:29:46 +02:00
|
|
|
res = self._execute_accelerate_module()
|
2013-09-03 19:27:58 +02:00
|
|
|
if not res.is_successful():
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("Failed to launch the accelerated daemon on %s (reason: %s)" % (self.host,res.result.get('msg')))
|
2013-08-11 07:41:18 +02:00
|
|
|
return self.connect(allow_ssh=False)
|
|
|
|
else:
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("Failed to connect to %s:%s" % (self.host,self.accport))
|
2013-08-11 07:41:18 +02:00
|
|
|
self.is_connected = True
|
2013-08-07 17:54:53 +02:00
|
|
|
return self
|
|
|
|
|
2013-08-11 07:41:18 +02:00
|
|
|
def send_data(self, data):
|
2013-10-02 22:36:37 +02:00
|
|
|
packed_len = struct.pack('!Q',len(data))
|
2013-08-11 07:41:18 +02:00
|
|
|
return self.conn.sendall(packed_len + data)
|
|
|
|
|
|
|
|
def recv_data(self):
|
|
|
|
header_len = 8 # size of a packed unsigned long long
|
|
|
|
data = b""
|
2013-08-27 20:12:35 +02:00
|
|
|
try:
|
2013-09-30 21:08:07 +02:00
|
|
|
vvvv("%s: in recv_data(), waiting for the header" % self.host)
|
2013-08-27 20:12:35 +02:00
|
|
|
while len(data) < header_len:
|
2013-10-01 23:50:32 +02:00
|
|
|
d = self.conn.recv(header_len - len(data))
|
2013-08-27 20:12:35 +02:00
|
|
|
if not d:
|
2013-09-30 21:08:07 +02:00
|
|
|
vvvv("%s: received nothing, bailing out" % self.host)
|
2013-08-27 20:12:35 +02:00
|
|
|
return None
|
|
|
|
data += d
|
2013-09-30 21:08:07 +02:00
|
|
|
vvvv("%s: got the header, unpacking" % self.host)
|
2013-10-02 22:36:37 +02:00
|
|
|
data_len = struct.unpack('!Q',data[:header_len])[0]
|
2013-08-27 20:12:35 +02:00
|
|
|
data = data[header_len:]
|
2013-09-30 21:08:07 +02:00
|
|
|
vvvv("%s: data received so far (expecting %d): %d" % (self.host,data_len,len(data)))
|
2013-08-27 20:12:35 +02:00
|
|
|
while len(data) < data_len:
|
2013-10-01 23:50:32 +02:00
|
|
|
d = self.conn.recv(data_len - len(data))
|
2013-08-27 20:12:35 +02:00
|
|
|
if not d:
|
2013-09-30 21:08:07 +02:00
|
|
|
vvvv("%s: received nothing, bailing out" % self.host)
|
2013-08-27 20:12:35 +02:00
|
|
|
return None
|
2014-03-19 18:59:06 +01:00
|
|
|
vvvv("%s: received %d bytes" % (self.host, len(d)))
|
2013-08-27 20:12:35 +02:00
|
|
|
data += d
|
2013-09-30 21:08:07 +02:00
|
|
|
vvvv("%s: received all of the data, returning" % self.host)
|
2013-08-27 20:12:35 +02:00
|
|
|
return data
|
|
|
|
except socket.timeout:
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("timed out while waiting to receive data")
|
2013-08-11 07:41:18 +02:00
|
|
|
|
2014-01-30 21:39:52 +01:00
|
|
|
def validate_user(self):
|
|
|
|
'''
|
|
|
|
Checks the remote uid of the accelerated daemon vs. the
|
|
|
|
one specified for this play and will cause the accel
|
|
|
|
daemon to exit if they don't match
|
|
|
|
'''
|
|
|
|
|
2014-03-19 18:59:06 +01:00
|
|
|
vvvv("%s: sending request for validate_user" % self.host)
|
2014-01-30 21:39:52 +01:00
|
|
|
data = dict(
|
|
|
|
mode='validate_user',
|
|
|
|
username=self.user,
|
|
|
|
)
|
|
|
|
data = utils.jsonify(data)
|
|
|
|
data = utils.encrypt(self.key, data)
|
|
|
|
if self.send_data(data):
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("Failed to send command to %s" % self.host)
|
2014-01-30 21:39:52 +01:00
|
|
|
|
2014-03-19 18:59:06 +01:00
|
|
|
vvvv("%s: waiting for validate_user response" % self.host)
|
2014-01-30 21:39:52 +01:00
|
|
|
while True:
|
|
|
|
# we loop here while waiting for the response, because a
|
|
|
|
# long running command may cause us to receive keepalive packets
|
|
|
|
# ({"pong":"true"}) rather than the response we want.
|
|
|
|
response = self.recv_data()
|
|
|
|
if not response:
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("Failed to get a response from %s" % self.host)
|
2014-01-30 21:39:52 +01:00
|
|
|
response = utils.decrypt(self.key, response)
|
|
|
|
response = utils.parse_json(response)
|
|
|
|
if "pong" in response:
|
|
|
|
# it's a keepalive, go back to waiting
|
|
|
|
vvvv("%s: received a keepalive packet" % self.host)
|
|
|
|
continue
|
|
|
|
else:
|
2014-03-19 18:59:06 +01:00
|
|
|
vvvv("%s: received the validate_user response: %s" % (self.host, response))
|
2014-01-30 21:39:52 +01:00
|
|
|
break
|
|
|
|
|
|
|
|
if response.get('failed'):
|
2014-03-19 18:59:06 +01:00
|
|
|
return False
|
2014-01-30 21:39:52 +01:00
|
|
|
else:
|
|
|
|
return response.get('rc') == 0
|
|
|
|
|
2014-11-24 22:36:31 +01:00
|
|
|
def exec_command(self, cmd, tmp_path, become_user=None, sudoable=False, executable='/bin/sh', in_data=None):
|
2013-08-07 17:54:53 +02:00
|
|
|
''' run a command on the remote host '''
|
|
|
|
|
2014-11-24 22:36:31 +01:00
|
|
|
if sudoable and self.runner.become and self.runner.become_method not in self.become_methods_supported:
|
|
|
|
raise errors.AnsibleError("Internal Error: this module does not support running commands via %s" % self.runner.become_method)
|
2014-01-21 02:19:03 +01:00
|
|
|
|
2013-12-11 10:55:56 +01:00
|
|
|
if in_data:
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("Internal Error: this module does not support optimized module pipelining")
|
2013-12-11 10:55:56 +01:00
|
|
|
|
2013-09-05 22:11:26 +02:00
|
|
|
if executable == "":
|
|
|
|
executable = constants.DEFAULT_EXECUTABLE
|
|
|
|
|
2014-11-24 22:36:31 +01:00
|
|
|
if self.runner.become and sudoable:
|
|
|
|
cmd, prompt, success_key = utils.make_become_cmd(cmd, become_user, executable, self.runner.become_method, '', self.runner.become_exe)
|
2013-08-27 20:12:35 +02:00
|
|
|
|
2013-08-07 17:54:53 +02:00
|
|
|
vvv("EXEC COMMAND %s" % cmd)
|
|
|
|
|
|
|
|
data = dict(
|
|
|
|
mode='command',
|
|
|
|
cmd=cmd,
|
|
|
|
tmp_path=tmp_path,
|
|
|
|
executable=executable,
|
|
|
|
)
|
|
|
|
data = utils.jsonify(data)
|
2013-08-11 07:41:18 +02:00
|
|
|
data = utils.encrypt(self.key, data)
|
|
|
|
if self.send_data(data):
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("Failed to send command to %s" % self.host)
|
2013-08-07 17:54:53 +02:00
|
|
|
|
2013-10-01 22:19:21 +02:00
|
|
|
while True:
|
|
|
|
# we loop here while waiting for the response, because a
|
|
|
|
# long running command may cause us to receive keepalive packets
|
|
|
|
# ({"pong":"true"}) rather than the response we want.
|
|
|
|
response = self.recv_data()
|
|
|
|
if not response:
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("Failed to get a response from %s" % self.host)
|
2013-10-01 22:19:21 +02:00
|
|
|
response = utils.decrypt(self.key, response)
|
|
|
|
response = utils.parse_json(response)
|
|
|
|
if "pong" in response:
|
|
|
|
# it's a keepalive, go back to waiting
|
2013-10-01 22:34:58 +02:00
|
|
|
vvvv("%s: received a keepalive packet" % self.host)
|
2013-10-01 22:19:21 +02:00
|
|
|
continue
|
|
|
|
else:
|
2013-10-01 22:34:58 +02:00
|
|
|
vvvv("%s: received the response" % self.host)
|
2013-10-01 22:19:21 +02:00
|
|
|
break
|
2013-08-07 17:54:53 +02:00
|
|
|
|
|
|
|
return (response.get('rc',None), '', response.get('stdout',''), response.get('stderr',''))
|
|
|
|
|
|
|
|
def put_file(self, in_path, out_path):
|
|
|
|
|
|
|
|
''' transfer a file from local to remote '''
|
|
|
|
vvv("PUT %s TO %s" % (in_path, out_path), host=self.host)
|
|
|
|
|
|
|
|
if not os.path.exists(in_path):
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleFileNotFound("file or module does not exist: %s" % in_path)
|
2013-08-07 17:54:53 +02:00
|
|
|
|
2013-08-28 17:05:52 +02:00
|
|
|
fd = file(in_path, 'rb')
|
|
|
|
fstat = os.stat(in_path)
|
|
|
|
try:
|
|
|
|
vvv("PUT file is %d bytes" % fstat.st_size)
|
2013-10-23 21:09:36 +02:00
|
|
|
last = False
|
|
|
|
while fd.tell() <= fstat.st_size and not last:
|
|
|
|
vvvv("file position currently %ld, file size is %ld" % (fd.tell(), fstat.st_size))
|
2013-08-28 17:05:52 +02:00
|
|
|
data = fd.read(CHUNK_SIZE)
|
|
|
|
if fd.tell() >= fstat.st_size:
|
|
|
|
last = True
|
|
|
|
data = dict(mode='put', data=base64.b64encode(data), out_path=out_path, last=last)
|
2014-11-24 22:36:31 +01:00
|
|
|
if self.runner.become:
|
|
|
|
data['user'] = self.runner.become_user
|
2013-08-28 17:05:52 +02:00
|
|
|
data = utils.jsonify(data)
|
|
|
|
data = utils.encrypt(self.key, data)
|
|
|
|
|
|
|
|
if self.send_data(data):
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("failed to send the file to %s" % self.host)
|
2013-08-28 17:05:52 +02:00
|
|
|
|
|
|
|
response = self.recv_data()
|
|
|
|
if not response:
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("Failed to get a response from %s" % self.host)
|
2013-08-28 17:05:52 +02:00
|
|
|
response = utils.decrypt(self.key, response)
|
|
|
|
response = utils.parse_json(response)
|
|
|
|
|
|
|
|
if response.get('failed',False):
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("failed to put the file in the requested location")
|
2013-08-28 17:05:52 +02:00
|
|
|
finally:
|
|
|
|
fd.close()
|
2013-10-23 21:09:36 +02:00
|
|
|
vvvv("waiting for final response after PUT")
|
2013-08-28 17:05:52 +02:00
|
|
|
response = self.recv_data()
|
|
|
|
if not response:
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("Failed to get a response from %s" % self.host)
|
2013-08-28 17:05:52 +02:00
|
|
|
response = utils.decrypt(self.key, response)
|
|
|
|
response = utils.parse_json(response)
|
|
|
|
|
|
|
|
if response.get('failed',False):
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("failed to put the file in the requested location")
|
2013-08-07 17:54:53 +02:00
|
|
|
|
|
|
|
def fetch_file(self, in_path, out_path):
|
|
|
|
''' save a remote file to the specified path '''
|
|
|
|
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
|
|
|
|
|
|
|
|
data = dict(mode='fetch', in_path=in_path)
|
|
|
|
data = utils.jsonify(data)
|
2013-08-11 07:41:18 +02:00
|
|
|
data = utils.encrypt(self.key, data)
|
|
|
|
if self.send_data(data):
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("failed to initiate the file fetch with %s" % self.host)
|
2013-08-07 17:54:53 +02:00
|
|
|
|
|
|
|
fh = open(out_path, "w")
|
2013-08-28 17:05:52 +02:00
|
|
|
try:
|
|
|
|
bytes = 0
|
|
|
|
while True:
|
|
|
|
response = self.recv_data()
|
|
|
|
if not response:
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("Failed to get a response from %s" % self.host)
|
2013-08-28 17:05:52 +02:00
|
|
|
response = utils.decrypt(self.key, response)
|
|
|
|
response = utils.parse_json(response)
|
|
|
|
if response.get('failed', False):
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("Error during file fetch, aborting")
|
2013-08-28 17:05:52 +02:00
|
|
|
out = base64.b64decode(response['data'])
|
|
|
|
fh.write(out)
|
|
|
|
bytes += len(out)
|
|
|
|
# send an empty response back to signify we
|
|
|
|
# received the last chunk without errors
|
|
|
|
data = utils.jsonify(dict())
|
|
|
|
data = utils.encrypt(self.key, data)
|
|
|
|
if self.send_data(data):
|
2014-03-19 18:59:06 +01:00
|
|
|
raise AnsibleError("failed to send ack during file fetch")
|
2013-08-28 17:05:52 +02:00
|
|
|
if response.get('last', False):
|
|
|
|
break
|
|
|
|
finally:
|
|
|
|
# we don't currently care about this final response,
|
|
|
|
# we just receive it and drop it. It may be used at some
|
|
|
|
# point in the future or we may just have the put/fetch
|
|
|
|
# operations not send back a final response at all
|
|
|
|
response = self.recv_data()
|
|
|
|
vvv("FETCH wrote %d bytes to %s" % (bytes, out_path))
|
|
|
|
fh.close()
|
2013-08-07 17:54:53 +02:00
|
|
|
|
|
|
|
def close(self):
|
|
|
|
''' terminate the connection '''
|
|
|
|
# Be a good citizen
|
|
|
|
try:
|
|
|
|
self.conn.close()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|