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 fe2eb2ae4a.

* 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.
pull/20467/merge
piotrsmolinski 7 years ago committed by Brian Coca
parent c13b1a718a
commit c3ffc49914

@ -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()

Loading…
Cancel
Save