D P
D P

Reputation: 135

ParallelSSHClient() not running command

I am trying to use the Parallel-SSH Client in Python to run commands on multiple servers. However, while testing this package out, I am running into a problem that I can't seem to solve.

Here is my code:

from pssh import ParallelSSHClient
host = '172.24.1.1'
user = 'XXXX'
password = 'XXXX'
client = ParallelSSHClient(host, user, password)
output = client.run_command('ls -l')

Everytime I try to run this code it seems to give me the errors:

pssh.exceptions.ConnectionErrorException: ("Error connecting to host '%s:%s' - %s - retry %s/%s", '1', 22, 'Network is unreachable', 3, 3)

and

OSError: [Errno 101] Network is unreachable

If I use SSHClient(), it works fine. So, I don't understand why it won't work with the ParallelSSHClient(). Can anybody help?

Upvotes: 0

Views: 1304

Answers (1)

AS Mackay
AS Mackay

Reputation: 2857

I think you're just using the wrong syntax for the ParallelSSHClient constructor, which expects a list of hosts, not a single hostname. (It's fine for the list to have just one item.)

Here's some code I ran based on the examples in the usage guide:

from pssh.pssh_client import ParallelSSHClient

host = '160.100.29.5'
myusername = 'XXXX'
mypassword = 'YYYY'

hosts = [host]   # make a list

client = ParallelSSHClient(hosts, user=myusername, password=mypassword)
output = client.run_command('ls -l')
for line in output['160.100.29.5'].stdout:
    print line

This works fine, but if I just use a single host (string) as the first parameter to the constructor, instead of a list, then I get the exact error you are getting.

Hope this is useful.

Upvotes: 3

Related Questions