Question - Bulk SSH hosts - Loop?

Greetings,

I am sure some others already tried and already did the trick on how to use a node to do a loop for bulk SSH for multiple hosts that read from a list (Google Spreadsheet)

I am trying to automate a flow where I can enter the first column from a public Google spreadsheet, a list of IP addresses of Linux machines, all the Linux machines are using the same username and password.

The part I am stuck with is how to create the loop for the SSH node to go over the list and run the command on each Linux machine.

Here is the flow I am trying to do:

Screen Shot 2022-08-04 at 7.32.11 PM

As you can see, I can read the column from Google Sheet of the IP addresses, but not sure what to do to have the SSH reads one by one to run the command on each.

Thanks!

I am trying to automate a flow where I can enter the first column from a public Google spreadsheet, a list of IP addresses of Linux machines, all the Linux machines are using the same username and password.

You can reference the host in the credentials using expressions, and for the loop, just connect the output of the SSH node to the split batches node, like in the example below. Be aware that you only need split batches node to create a loop because you are referencing a value (using expressions) in the credentials, else this would not be needed a n8n will do the looping for you.

Thanks @RicardoE105 for the quick response.

Just to make sure I get it right, you used the function in your example as source input (a list of the IP addresses) and then splitthebatch has batch size of 10? Why the 10 used there? or your meant 3 since you have 3 hosts in the functions node?

and the SSH, what would be the expression for the hostname, is like this?

And then the loop will keep go over the SSH host by another to run the command?

Thanks again for the help!

Yes, just to mockup the data you are using as an example.

10 is the default I believe, but itn your case, you need to set it to 1

That depends on the node and the input property where the host is. In your case you need to reference the output of the Google Sheets node. The expression editor figures that out for you, just select the google sheet node and then the property where the host/ip is.

I see. Thanks for the confirmation.

What would be the host expression in SSH node in your example when you used the function?

return [
  {
    ip: '192.168.1.1'
  },
  {
    ip: '192.168.1.2'
  },
    {
    ip: '192.168.1.3'
  }
]

{{$node["Function"].json["ip"]}}

Thanks again.

That is the function node expression I selected.

The good thing that the loop runs the exact times/inputs in the function which is great.

The issue is now, that with the SSH expression, for some reason it’s running 4 times on the same IP address.

Any idea what could be missing here?

Thanks