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.
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.
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.
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?
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.