salt icon indicating copy to clipboard operation
salt copied to clipboard

The salt-ssh is OK, but the salt-ssh python api is wrong

Open zjyExcelsior opened this issue 10 years ago • 9 comments

I run this command in salt-ssh 2015.8.8 in OS X 10.11.6, return True:

sudo salt-ssh --user='root' --passwd='vagrant' --roster=scan '10.57.3.102' test.ping

the result is this:

10.57.3.102:
    True

However, I run this by the salt-ssh python api, return error:

from salt.client.ssh.client import SSHClient
client = SSHClient(c_path='/etc/salt/master')
print client.cmd(tgt='10.57.3.102', fun='test.ping', salt_user='root', salt_passwd='vagrant', roster='scan')

the error is this:

{'10.57.3.102': {'retcode': 255, 'stderr': 'Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n', 'stdout': ''}}

zjyExcelsior avatar Aug 22 '16 16:08 zjyExcelsior

Ok, it looks like the main issue is that the SSHClient is not passing all the options in, for the time being you will need to pack those options into opts:

client = SSHClient(c_path='/etc/salt/master')
client['opts']['salt_user'] = 'root'
client['opts']['salt_passwd'] = 'vagrant'
client['opts']['roster'] = 'scan'
print client.cmd(tgt='10.57.3.102', fun='test.ping')

thatch45 avatar Aug 22 '16 18:08 thatch45

Still return wrong error.

zjyExcelsior avatar Aug 23 '16 02:08 zjyExcelsior

@zjyExcelsior does this syntax work for you?

print client.cmd(tgt='10.1.45.191', fun='test.ping', ssh_user='root', ssh_passwd='passwd', roster='scan')

This syntax worked for me and I found these arguments by looking in salt/client/ssh/client.py and noticing the call to salt.client.ssh.SSH(opts) then I found these arguments in the SSH class in salt/client/ssh/init.py.

Ch3LL avatar Aug 25 '16 16:08 Ch3LL

Good job! The solution you offered is great.I missed the opts before. Thank you very much! I think I can close the issue now!

zjyExcelsior avatar Aug 25 '16 16:08 zjyExcelsior

However, I think the documents about the Python Client API should be added some details such as kwargs/args. @thatch45

zjyExcelsior avatar Aug 25 '16 17:08 zjyExcelsior

salt-ssh --user='robin' --passwd='robinhan' --roster=scan '192.168.75.176' test.ping -i image but: from salt.client.ssh.client import SSHClient

client = SSHClient(c_path='/etc/salt/master') client.cmd(tgt='192.168.75.176',fun='test.ping',ssh_user='robin',ssh_passwd='robinhan',roster='scan')

Error: /usr/bin/python /home/robin/PycharmProjects/untitled/salt-ssh.py Traceback (most recent call last): File "/home/robin/PycharmProjects/untitled/salt-ssh.py", line 7, in client.cmd(tgt='192.168.75.176',fun='test.ping',ssh_user='robin',ssh_passwd='robinhan',roster='scan') File "/usr/local/python2.7.13/lib/python2.7/site-packages/salt/client/ssh/client.py", line 110, in cmd **kwargs) File "/usr/local/python2.7.13/lib/python2.7/site-packages/salt/client/ssh/client.py", line 59, in _prep_ssh return salt.client.ssh.SSH(opts) File "/usr/local/python2.7.13/lib/python2.7/site-packages/salt/client/ssh/init.py", line 206, in init raise salt.exceptions.SaltClientError('salt-ssh could not be run because it could not generate keys.\n\nYou can probably resolve this by executing this script with increased permissions via sudo or by running as root.\nYou could also use the '-c' option to supply a configuration directory that you have permissions to read and write to.') salt.exceptions.SaltClientError: salt-ssh could not be run because it could not generate keys.

You can probably resolve this by executing this script with increased permissions via sudo or by running as root. You could also use the '-c' option to supply a configuration directory that you have permissions to read and write to.

@Ch3LL need help me!

teliduxing008 avatar Jan 24 '18 09:01 teliduxing008

@teliduxing004 are you running with root? also can you add this to a new issue with more details since this issue is closed so we can ensure the issues are handled separately.

Ch3LL avatar Jan 26 '18 18:01 Ch3LL

@Ch3LL yes,ok,thanks。

teliduxing008 avatar Jan 27 '18 00:01 teliduxing008

thanks solved my problem.

htaoji1988 avatar Apr 17 '18 06:04 htaoji1988