G
G
Gleb Altshifter2021-03-26 11:43:13
SSH
Gleb Altshifter, 2021-03-26 11:43:13

How to automate mass connection via ssh?

I'm tired of doing monkey work, and I would like to devote time to work on more interesting tasks. I want to automate everything and enjoy. I understand that knowledge of tools and all kinds of programming languages ​​will help in everything, but I want to learn something that will really help you in doing your job. This question is not for finding a specific answer (which of course would also be cool and great), but for helping the way, how to do it and where to dig.

From time to time, you need to connect to ~300+ pieces of hardware via ssh and enter the same command for all, but there are nuances that are difficult to bypass by Google (especially if you don’t know the basic tools like ansible, etc.).

  • 1 - own shell on the hardware, you need to give only certain commands
  • 2 - commands must be given from privileged mode, for example, in this particular case, enter the "enableup" command and enter the administrator password to work in privileged mode
  • 3 - connection by password, no keys ((
  • 4 - it is desirable to work all this on windows

Now I have full sessions in mremoteng and the connection with the initial authorization is automated, so to speak, but if you need to do all this in bulk, this is clicking for hours.
I read that fabric in python can help with this, but I don’t know for sure.
How can this be done?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
I
iddqda, 2021-03-26
@altshifter

ansible is well suited for server configuration tasks where the task code is downloaded to the client and executed there.
for stupid tasks like logging in via ssh and executing a couple of commands, it’s not good
for this, it’s overcomplicated, cumbersome and clumsy,
and it’s also famous for its backward incompatibility,
every major release will have to rewrite scripts,
I would use scrapli + nornir for such a task,
only both of them don’t work with windows

L
Leonid Nikolaev, 2021-03-26
@nikonor

what is the problem with ansible? It seems that he was created exactly for this?

K
ky0, 2021-03-26
@ky0

Expect is perfectly able to touch such stupid pieces of iron, which are written about in your paragraphs. 1-3. It is quite possible to confuse all this within the framework of some Ansible, etc.

U
unseriously, 2021-03-26
@unseriously

You can use a script on the bash.
On Windows there is a chic MobaXterm program, in the free version it has restrictions on the number of sessions, the paid version bites the price, but perhaps it will help you with something.

V
Vitaly Karasik, 2021-03-26
@vitaly_il1

Look at https://gist.github.com/mbbx6spp/c16b5438270be6096... if you are too lazy to learn Ansible

A
Alexey Dmitriev, 2021-03-26
@SignFinder

Since there is a Windows tag, then the script is in Powershell. He knows how to ssh out of the box and in foreach you can iterate through the list of machines.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question