Skip to content

Commit 4774b54

Browse files
authored
Add support for SSH config file option in remote-run
1 parent e8dd6b1 commit 4774b54

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

utils/remote-run

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,19 @@ class CommandRunner(object):
9494
sys.exit(sftp_proc.returncode)
9595

9696
class RemoteCommandRunner(CommandRunner):
97-
def __init__(self, host, identity_path, ssh_options):
97+
def __init__(self, host, identity_path, ssh_options, config_file):
9898
if ':' in host:
9999
(self.remote_host, self.port) = host.rsplit(':', 1)
100100
else:
101101
self.remote_host = host
102102
self.port = None
103103
self.identity_path = identity_path
104104
self.ssh_options = ssh_options
105+
self.config_file = config_file
105106

106107
def common_options(self, port_flag):
107108
port_option = [port_flag, self.port] if self.port else []
109+
config_option = ['-F', self.config_file] if self.config_file else []
108110
identity_option = (
109111
['-i', self.identity_path] if self.identity_path else [])
110112
# Interleave '-o' with each custom option.
@@ -113,7 +115,7 @@ class RemoteCommandRunner(CommandRunner):
113115
# https://spapas.github.io/2016/04/27/python-nested-list-comprehensions/
114116
extra_options = [arg for option in self.ssh_options
115117
for arg in ["-o", option]]
116-
return port_option + identity_option + extra_options
118+
return port_option + identity_option + config_option + extra_options
117119

118120
def remote_invocation(self, command):
119121
return (['/usr/bin/ssh', '-n'] +
@@ -172,6 +174,8 @@ def main():
172174

173175
parser.add_argument('-i', '--identity', dest='identity', metavar='FILE',
174176
help='an SSH identity file (private key) to use')
177+
parser.add_argument('-F', '--config-file', dest='config_file', metavar='FILE',
178+
help='an SSH configuration file')
175179
parser.add_argument('-o', '--ssh-option', action='append', default=[],
176180
dest='ssh_options', metavar='OPTION',
177181
help='extra SSH config options (man ssh_config)')
@@ -192,7 +196,10 @@ def main():
192196
args.command.insert(0, args.host)
193197
del args.host
194198
else:
195-
runner = RemoteCommandRunner(args.host, args.identity, args.ssh_options)
199+
runner = RemoteCommandRunner(args.host,
200+
args.identity,
201+
args.ssh_options,
202+
args.config_file)
196203
runner.dry_run = args.dry_run
197204
runner.verbose = args.verbose or args.dry_run
198205

0 commit comments

Comments
 (0)