mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Fix two bugs:
1) ssh-copy-id is a bit of a pill, fall back to try the multiple formats suppoerted by ssh-copy-id 2) Escaping the heredoc causes it to fail, we need to find a better way to only escape if it is a raw command
This commit is contained in:
parent
99dff2e3f3
commit
3c59e9f881
@ -115,7 +115,7 @@ class Shell(object):
|
|||||||
ret.append('-o {0} '.format(option))
|
ret.append('-o {0} '.format(option))
|
||||||
return ''.join(ret)
|
return ''.join(ret)
|
||||||
|
|
||||||
def _copy_id_str(self):
|
def _copy_id_str_old(self):
|
||||||
'''
|
'''
|
||||||
Return the string to execute ssh-copy-id
|
Return the string to execute ssh-copy-id
|
||||||
'''
|
'''
|
||||||
@ -130,11 +130,29 @@ class Shell(object):
|
|||||||
self.host)
|
self.host)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _copy_id_str_new(self):
|
||||||
|
'''
|
||||||
|
Since newer ssh-copy-id commands ingest option differently we need to
|
||||||
|
have two commands
|
||||||
|
'''
|
||||||
|
if self.passwd and salt.utils.which('sshpass'):
|
||||||
|
return 'sshpass -p "{0}" {1} {2} {3} -p {4} {5}@{6}'.format(
|
||||||
|
self.passwd,
|
||||||
|
'ssh-copy-id',
|
||||||
|
'-i {0}.pub'.format(self.priv),
|
||||||
|
self._passwd_opts(),
|
||||||
|
self.port,
|
||||||
|
self.user,
|
||||||
|
self.host)
|
||||||
|
return None
|
||||||
|
|
||||||
def copy_id(self):
|
def copy_id(self):
|
||||||
'''
|
'''
|
||||||
Execute ssh-copy-id to plant the id file on the target
|
Execute ssh-copy-id to plant the id file on the target
|
||||||
'''
|
'''
|
||||||
self._run_cmd(self._copy_id_str())
|
stdout, stderr = self._run_cmd(self._copy_id_str_old())
|
||||||
|
if stderr.startswith('Usage'):
|
||||||
|
self._run_cmd(self._copy_id_str_new())
|
||||||
|
|
||||||
def _cmd_str(self, cmd, ssh='ssh'):
|
def _cmd_str(self, cmd, ssh='ssh'):
|
||||||
'''
|
'''
|
||||||
@ -146,7 +164,7 @@ class Shell(object):
|
|||||||
|
|
||||||
if self.passwd and salt.utils.which('sshpass'):
|
if self.passwd and salt.utils.which('sshpass'):
|
||||||
opts = self._passwd_opts()
|
opts = self._passwd_opts()
|
||||||
return "sshpass -p '{0}' {1} {2} {3} {4} '{5}'".format(
|
return "sshpass -p '{0}' {1} {2} {3} {4} {5}".format(
|
||||||
self.passwd,
|
self.passwd,
|
||||||
ssh,
|
ssh,
|
||||||
'' if ssh == 'scp' else self.host,
|
'' if ssh == 'scp' else self.host,
|
||||||
@ -155,7 +173,7 @@ class Shell(object):
|
|||||||
cmd)
|
cmd)
|
||||||
if self.priv:
|
if self.priv:
|
||||||
opts = self._key_opts()
|
opts = self._key_opts()
|
||||||
return "{0} {1} {2} {3} '{4}'".format(
|
return "{0} {1} {2} {3} {4}".format(
|
||||||
ssh,
|
ssh,
|
||||||
'' if ssh == 'scp' else self.host,
|
'' if ssh == 'scp' else self.host,
|
||||||
'-t -t' if self.tty else '',
|
'-t -t' if self.tty else '',
|
||||||
|
Loading…
Reference in New Issue
Block a user