Add ssh mux options by default if available.
This commit is contained in:
parent
b4ac23b4f8
commit
d0d0c258d6
3 changed files with 44 additions and 27 deletions
|
@ -249,6 +249,12 @@ CDIST_OVERRIDE::
|
|||
CDIST_ORDER_DEPENDENCY::
|
||||
Create dependencies based on the execution order (see cdist-manifest(7))
|
||||
|
||||
CDIST_REMOTE_EXEC::
|
||||
Use this command for remote execution (should behave like ssh)
|
||||
|
||||
CDIST_REMOTE_COPY::
|
||||
Use this command for remote copy (should behave like scp)
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
- cdist(1)
|
||||
|
|
|
@ -138,6 +138,11 @@ CDIST_LOCAL_SHELL::
|
|||
CDIST_REMOTE_SHELL::
|
||||
Selects shell for remote scirpt execution, defaults to /bin/sh
|
||||
|
||||
CDIST_REMOTE_EXEC::
|
||||
Use this command for remote execution (should behave like ssh)
|
||||
|
||||
CDIST_REMOTE_COPY::
|
||||
Use this command for remote copy (should behave like scp)
|
||||
|
||||
EXIT STATUS
|
||||
-----------
|
||||
|
|
|
@ -21,33 +21,27 @@
|
|||
#
|
||||
#
|
||||
|
||||
def inspect_ssh_mux_opts():
|
||||
import subprocess
|
||||
|
||||
def inspect_ssh_mux_opts(control_path_dir="~/.ssh/"):
|
||||
"""Inspect whether or not ssh supports multiplexing options"""
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
control_path = os.path.join(control_path_dir, "cdist.master-%l-%r@%h:%p")
|
||||
wanted_mux_opts = {
|
||||
"ControlPath":"~/.ssh/master-%l-%r@%h:%p",
|
||||
"ControlMaster":"auto",
|
||||
"ControlPersist":"125",
|
||||
"ControlPath": control_path,
|
||||
"ControlMaster": "auto",
|
||||
"ControlPersist": "125",
|
||||
}
|
||||
# if checked key option is present then this assumes
|
||||
# all options in value are present
|
||||
check = {
|
||||
"ControlMaster": ("ControlMaster", "ControlPath"),
|
||||
"ControlPersist": ("ControlPersist",),
|
||||
}
|
||||
mux_opts = {}
|
||||
for x in check:
|
||||
try:
|
||||
subprocess.check_output("ssh -o {}".format(x),
|
||||
stderr=subprocess.STDOUT, shell=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
foo = e.output.decode().lower()
|
||||
if not "bad configuration option" in foo:
|
||||
for o in check[x]:
|
||||
mux_opts[o] = wanted_mux_opts[o]
|
||||
foo = [" -o {}={}".format(x, mux_opts[x]) for x in mux_opts]
|
||||
return " ".join(foo)
|
||||
mux_opts = " ".join([" -o {}={}".format(x,
|
||||
wanted_mux_opts[x]) for x in wanted_mux_opts])
|
||||
try:
|
||||
subprocess.check_output("ssh {}".format(mux_opts),
|
||||
stderr=subprocess.STDOUT, shell=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
subproc_output = e.output.decode().lower()
|
||||
if "bad configuration option" in subproc_output:
|
||||
return ""
|
||||
return mux_opts
|
||||
|
||||
def commandline():
|
||||
"""Parse command line"""
|
||||
|
@ -56,6 +50,9 @@ def commandline():
|
|||
import cdist.banner
|
||||
import cdist.config
|
||||
import cdist.shell
|
||||
import tempfile
|
||||
import shutil
|
||||
import os
|
||||
|
||||
# Construct parser others can reuse
|
||||
parser = {}
|
||||
|
@ -83,9 +80,18 @@ def commandline():
|
|||
|
||||
# Config
|
||||
# inspect multiplexing options for default remote copy/exec scp/ssh
|
||||
MUX_OPTS = inspect_ssh_mux_opts()
|
||||
cdist.REMOTE_EXEC += MUX_OPTS
|
||||
cdist.REMOTE_COPY += MUX_OPTS
|
||||
# but not if env vars are present
|
||||
has_env_remote_exec = "CDIST_REMOTE_EXEC" in os.environ
|
||||
has_env_remote_copy = "CDIST_REMOTE_COPY" in os.environ
|
||||
if not has_env_remote_exec or not has_env_remote_copy:
|
||||
control_path_dir = tempfile.mkdtemp(prefix="cdist.control.path")
|
||||
import atexit
|
||||
atexit.register(lambda: shutil.rmtree(control_path_dir))
|
||||
MUX_OPTS = inspect_ssh_mux_opts(control_path_dir)
|
||||
if not has_env_remote_exec:
|
||||
cdist.REMOTE_EXEC += MUX_OPTS
|
||||
if not has_env_remote_copy:
|
||||
cdist.REMOTE_COPY += MUX_OPTS
|
||||
|
||||
parser['config'] = parser['sub'].add_parser('config',
|
||||
parents=[parser['loglevel']])
|
||||
|
|
Loading…
Reference in a new issue