Inspect and add by default ssh multiplexing options.
This commit is contained in:
parent
2dfc30e3c4
commit
215e58eb38
1 changed files with 32 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# 2010-2013 Nico Schottelius (nico-cdist at schottelius.org)
|
# 2010-2013 Nico Schottelius (nico-cdist at schottelius.org)
|
||||||
|
# 2016 Darko Poljak (darko.poljak at gmail.com)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -20,6 +21,32 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
def inspect_ssh_mux_opts():
|
||||||
|
"""Inspect whether or not ssh supports multiplexing options"""
|
||||||
|
wanted_mux_opts = {
|
||||||
|
"ControlPath":"~/.ssh/master-%l-%r@%h:%p",
|
||||||
|
"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)
|
||||||
|
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)
|
||||||
|
|
||||||
def commandline():
|
def commandline():
|
||||||
"""Parse command line"""
|
"""Parse command line"""
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -53,6 +80,11 @@ def commandline():
|
||||||
parser['banner'].set_defaults(func=cdist.banner.banner)
|
parser['banner'].set_defaults(func=cdist.banner.banner)
|
||||||
|
|
||||||
# Config
|
# 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
|
||||||
|
|
||||||
parser['config'] = parser['sub'].add_parser('config',
|
parser['config'] = parser['sub'].add_parser('config',
|
||||||
parents=[parser['loglevel']])
|
parents=[parser['loglevel']])
|
||||||
parser['config'].add_argument('host', nargs='+',
|
parser['config'].add_argument('host', nargs='+',
|
||||||
|
|
Loading…
Reference in a new issue