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': ''}}
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')
Still return wrong error.
@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.
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!
However, I think the documents about the Python Client API
should be added some details such as kwargs
/args
. @thatch45
salt-ssh --user='robin' --passwd='robinhan' --roster=scan '192.168.75.176' test.ping -i
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.nnYou 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!
@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 yes,ok,thanks。
thanks solved my problem.
Most helpful comment
@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 tosalt.client.ssh.SSH(opts)
then I found these arguments in the SSH class in salt/client/ssh/init.py.