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::
|
CDIST_ORDER_DEPENDENCY::
|
||||||
Create dependencies based on the execution order (see cdist-manifest(7))
|
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
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
- cdist(1)
|
- cdist(1)
|
||||||
|
|
|
@ -138,6 +138,11 @@ CDIST_LOCAL_SHELL::
|
||||||
CDIST_REMOTE_SHELL::
|
CDIST_REMOTE_SHELL::
|
||||||
Selects shell for remote scirpt execution, defaults to /bin/sh
|
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
|
EXIT STATUS
|
||||||
-----------
|
-----------
|
||||||
|
|
|
@ -21,33 +21,27 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
def inspect_ssh_mux_opts():
|
def inspect_ssh_mux_opts(control_path_dir="~/.ssh/"):
|
||||||
import subprocess
|
|
||||||
|
|
||||||
"""Inspect whether or not ssh supports multiplexing options"""
|
"""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 = {
|
wanted_mux_opts = {
|
||||||
"ControlPath":"~/.ssh/master-%l-%r@%h:%p",
|
"ControlPath": control_path,
|
||||||
"ControlMaster": "auto",
|
"ControlMaster": "auto",
|
||||||
"ControlPersist": "125",
|
"ControlPersist": "125",
|
||||||
}
|
}
|
||||||
# if checked key option is present then this assumes
|
mux_opts = " ".join([" -o {}={}".format(x,
|
||||||
# all options in value are present
|
wanted_mux_opts[x]) for x in wanted_mux_opts])
|
||||||
check = {
|
|
||||||
"ControlMaster": ("ControlMaster", "ControlPath"),
|
|
||||||
"ControlPersist": ("ControlPersist",),
|
|
||||||
}
|
|
||||||
mux_opts = {}
|
|
||||||
for x in check:
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_output("ssh -o {}".format(x),
|
subprocess.check_output("ssh {}".format(mux_opts),
|
||||||
stderr=subprocess.STDOUT, shell=True)
|
stderr=subprocess.STDOUT, shell=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
foo = e.output.decode().lower()
|
subproc_output = e.output.decode().lower()
|
||||||
if not "bad configuration option" in foo:
|
if "bad configuration option" in subproc_output:
|
||||||
for o in check[x]:
|
return ""
|
||||||
mux_opts[o] = wanted_mux_opts[o]
|
return mux_opts
|
||||||
foo = [" -o {}={}".format(x, mux_opts[x]) for x in mux_opts]
|
|
||||||
return " ".join(foo)
|
|
||||||
|
|
||||||
def commandline():
|
def commandline():
|
||||||
"""Parse command line"""
|
"""Parse command line"""
|
||||||
|
@ -56,6 +50,9 @@ def commandline():
|
||||||
import cdist.banner
|
import cdist.banner
|
||||||
import cdist.config
|
import cdist.config
|
||||||
import cdist.shell
|
import cdist.shell
|
||||||
|
import tempfile
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
|
||||||
# Construct parser others can reuse
|
# Construct parser others can reuse
|
||||||
parser = {}
|
parser = {}
|
||||||
|
@ -83,8 +80,17 @@ def commandline():
|
||||||
|
|
||||||
# Config
|
# Config
|
||||||
# inspect multiplexing options for default remote copy/exec scp/ssh
|
# inspect multiplexing options for default remote copy/exec scp/ssh
|
||||||
MUX_OPTS = inspect_ssh_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
|
cdist.REMOTE_EXEC += MUX_OPTS
|
||||||
|
if not has_env_remote_copy:
|
||||||
cdist.REMOTE_COPY += MUX_OPTS
|
cdist.REMOTE_COPY += MUX_OPTS
|
||||||
|
|
||||||
parser['config'] = parser['sub'].add_parser('config',
|
parser['config'] = parser['sub'].add_parser('config',
|
||||||
|
|
Loading…
Reference in a new issue