ssh - skip connection reset if controlpath does not exist (#43062)

This commit is contained in:
Jordan Borean 2018-07-24 08:20:54 +10:00 committed by GitHub
parent 04431216e7
commit d5d29f4cfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1102,7 +1102,19 @@ class Connection(ConnectionBase):
# If we have a persistent ssh connection (ControlPersist), we can ask it to stop listening. # If we have a persistent ssh connection (ControlPersist), we can ask it to stop listening.
cmd = self._build_command(self._play_context.ssh_executable, '-O', 'stop', self.host) cmd = self._build_command(self._play_context.ssh_executable, '-O', 'stop', self.host)
controlpersist, controlpath = self._persistence_controls(cmd) controlpersist, controlpath = self._persistence_controls(cmd)
if controlpersist: cp_arg = [a for a in cmd if a.startswith(b"ControlPath=")]
# only run the reset if the ControlPath already exists or if it isn't
# configured and ControlPersist is set
run_reset = False
if controlpersist and len(cp_arg) > 0:
cp_path = cp_arg[0].split(b"=", 1)[-1]
if os.path.exists(cp_path):
run_reset = True
elif controlpersist:
run_reset = True
if run_reset:
display.vvv(u'sending stop: %s' % cmd) display.vvv(u'sending stop: %s' % cmd)
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()