From c3ffc49914285774729193d1a09d9a6976369deb Mon Sep 17 00:00:00 2001 From: piotrsmolinski Date: Wed, 31 May 2017 19:40:57 +0200 Subject: [PATCH] reset_connection fixes: #23621 (#25211) * moved the logging statement moved the logging statement before the actual action * added status code check In the existing implementation when the ssh command fails the command result is silently discarded. It hides the fact that the disconnection did not go as expected. Effectively the intended action was not successful, but the play continues. * Revert "added status code check" This reverts commit fe2eb2ae4aeb4812fa2f59ccdfabc9efc677e657. * added command status code check In the existing implementation the command is checked for the success. As a result failed execution is silently discarded. The change tests for return code and fails if it did not work. --- lib/ansible/plugins/connection/ssh.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 12bdaf59e3b..1eef5acf0b0 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -894,9 +894,12 @@ class Connection(ConnectionBase): cmd = map(to_bytes, self._build_command(self._play_context.ssh_executable, '-O', 'stop', self.host)) controlpersist, controlpath = self._persistence_controls(cmd) if controlpersist: + display.vvv(u'sending stop: %s' % cmd) p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() - display.vvv(u'sending stop: %s' % cmd) + status_code = p.wait() + if status_code != 0: + raise AnsibleError("Cannot reset connection:\n%s" % stderr) self.close()