Access multiple Host in SSH node

I am trying to access multiple servers and run some commands using the SSH nodes.
Created a table that contains a list of servers’ IPs and their respective action and used expression in connecting host field.
But ssh node is able to access first records only.
Printing private IP only.
Output:
[

{

“code”: 0,

“signal”: null,

“stdout”: “10.20.07.79”,

“stderr”: “”

},

{

“code”: 0,

“signal”: null,

“stdout”: “10.20.07.79”,

“stderr”: “”

}

]
How can I achieve this?

You’ll need to use a Split in Batches node otherwise all items will use the same host/ip in credentials.

See Loop through hostnames and ssh each one - #5 by pemontto

2 Likes

I just tried this one, but the problem persist.
SSH into the first hostname all the times.
I have a list of 34 and I have 34 results from the command only executed on the first hostname.

Welcome to the community @gabrielpc1190 !

You would have to:

  1. Change “Batch Size” on the SplitInBatches node to 1
  2. Connect the output of “Google Sheets 1” node with the input of the SplitInBatches node to create a loop
1 Like

Nice! Thank you!
It worked perfectly fine!

@gabrielpc1190 can you share please the workflow of the google sheet and split in batch + SSH nodes on how to use multiple SSH machines to push a script? Thanks!

Welcome to the community @ansred

1 Like

The key is combining split in batches with expressions in your SSH credentials. Take this workflow, the MyServers node could just as well be a spreadsheet node, it returns a host, port, and user.

Those variables are used in the SSH credentials:

Just make sure you flick them over to expressions with this toggle:

If you’re using docker you can generate some test servers (myserver1 - myserver5) with this snippet:

for i in {1..5}; do
    docker run -d --name=myserver$i \
        -e PASSWORD_ACCESS=true \
        -e USER_PASSWORD=password \
        -e USER_NAME=test \
        -p 222$i:2222 \
        lscr.io/linuxserver/openssh-server:latest
done
3 Likes

@pemontto I would first thank you very much on your response as this is one of the best detailed answers I would ever get :smiley:
That worked as expected!

1 Like