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

pull/43175/head
Jordan Borean 6 years ago committed by GitHub
parent 04431216e7
commit d5d29f4cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1102,7 +1102,19 @@ class Connection(ConnectionBase):
# 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)
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)
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()

Loading…
Cancel
Save