diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 5509bb2d94..4b2d7abe27 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -161,12 +161,12 @@ class ActionBase: if result['rc'] == 5: output = 'Authentication failure.' elif result['rc'] == 255 and self._connection.transport in ('ssh',): - # FIXME: more utils.VERBOSITY - #if utils.VERBOSITY > 3: - # output = 'SSH encountered an unknown error. The output was:\n%s' % (result['stdout']+result['stderr']) - #else: - # output = 'SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue' - output = 'SSH encountered an unknown error. The output was:\n%s' % (result['stdout']+result['stderr']) + + if self._connection_info.verbosity > 3: + output = 'SSH encountered an unknown error. The output was:\n%s' % (result['stdout']+result['stderr']) + else: + output = 'SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue' + elif 'No space left on device' in result['stderr']: output = result['stderr'] else: @@ -462,7 +462,7 @@ class ActionBase: err = stderr debug("done with _low_level_execute_command() (%s)" % (cmd,)) - if rc is not None: - return dict(rc=rc, stdout=out, stderr=err) - else: - return dict(stdout=out, stderr=err) + if rc is None: + rc = 0 + + return dict(rc=rc, stdout=out, stderr=err) diff --git a/lib/ansible/plugins/connections/ssh.py b/lib/ansible/plugins/connections/ssh.py index e2251ca5b0..4a3ea4f5a2 100644 --- a/lib/ansible/plugins/connections/ssh.py +++ b/lib/ansible/plugins/connections/ssh.py @@ -398,14 +398,14 @@ class Connection(ConnectionBase): super(Connection, self).put_file(in_path, out_path) - self._display.vvv("PUT {0} TO {1}".format(in_path, out_path), host=self._connection_info.remote_addr) + # FIXME: make a function, used in all 3 methods EXEC/PUT/FETCH + host = self._connection_info.remote_addr + + self._display.vvv("PUT {0} TO {1}".format(in_path, out_path), host=host) if not os.path.exists(in_path): raise AnsibleFileNotFound("file or module does not exist: {0}".format(in_path)) cmd = self._password_cmd() - # FIXME: make a function, used in all 3 methods EXEC/PUT/FETCH - host = self._connection_info.remote_addr - # FIXME: ipv6 stuff needs to be figured out. It's in the connection info, however # not sure if it's all working yet so this remains commented out #if self._ipv6: @@ -436,12 +436,13 @@ class Connection(ConnectionBase): super(Connection, self).fetch_file(in_path, out_path) - self._display.vvv("FETCH {0} TO {1}".format(in_path, out_path), host=self._connection_info.remote_addr) - cmd = self._password_cmd() - # FIXME: make a function, used in all 3 methods EXEC/PUT/FETCH host = self._connection_info.remote_addr + self._display.vvv("FETCH {0} TO {1}".format(in_path, out_path), host=host) + cmd = self._password_cmd() + + # FIXME: ipv6 stuff needs to be figured out. It's in the connection info, however # not sure if it's all working yet so this remains commented out #if self._ipv6: @@ -467,5 +468,14 @@ class Connection(ConnectionBase): def close(self): ''' not applicable since we're executing openssh binaries ''' + + if 'ControlMaster' in self._common_args: + cmd = ['ssh','-O','stop'] + cmd.extend(self._common_args) + cmd.append(self._connection_info.remote_addr) + + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + self._connected = False