📜 ⬆️ ⬇️

Automation of work * nix system administrator

About ssh and system administrators:

For a long time * nix system administrators have been using ssh to manage servers remotely.
Some of them make ready-made sets of scripts for software updates, layouts from the repository, and so on.
To a certain extent of disaster, you can bypass the car park one by one. However, sooner or later, the fleet of cars will grow to quite a solid size and then the simplest layout for the frontend of new scripts becomes a headache for several hours.

This is where the most interesting begins:
Some system administrators run their scripts in several threads, others think of how to get rid of some of the machines.


SSH robot:

For a long time I used it only for my needs at mail.ru, then for a long time I didn’t have a large zoo of machines and now I need it again. This version has been completely rewritten over the last 3 weeks from scratch:
')
Latest stable version:
http://myau.su/robot-0.2.5.tgz

The latest stable version from the repository:
svn co svn://myau.su/robot/tags/robot-0.2.5 robot

Trunk:
svn co svn://myau.su/robot/trunk robot

A list of what is required for the assembly and how to build can be found in the doc folder.

At the exit, get 2 binary:
passfile - to generate an encrypted password file
robot - the robot itself

A little bit about what the robot has already been trained:

1) Asynchronously execute scripts on machines
2) Upload / download files via ssh (sftp)
3) Check exit code
4) Wait for the specified string after the command
5) Group machines and execute different scripts for different groups.
6) Display progress and output from machines
7) Use encrypted password file

Automate:


We will now look at a few simple examples without using an encrypted password file. Full documentation on the syntax of the macro files is in the doc folder in the same place and everything else.

1) Update web-scripts with Apache restarting:

The first thing we need is to describe what machines we have and how to connect with them:

@host {
@user = user_zero #
@pass = password_zero #

192.168.0.1
192.168.0.2
user_2@192.168.0.3 #
user_2:pass2@192.168.0.4 #
192.168.0.5
192.168.0.6
}


Simply laconic and beautiful)
Now let's describe 2 different groups, because the path to the directory with scripts is different there:

@group path_1 {
192.168.0.1
192.168.0.2
192.168.0.3
}

@group path_2 {
192.168.0.4
192.168.0.5
192.168.0.6
}


Please note that the login and password are not written here only the host name.

And now the scripts themselves:

@script path_1 {
command su #
expect Password #
command MegArOooOtPas$ #
exitcode 0 #
command cd /path_to_www1/ #
exitcode 0 #
command svn up #
exitcode 0 #
command /etc/init.d/apache restart #
exitcode 0 #
}

@script path_2 {
command su
expect Password
command MegArOooOtPas$
exitcode 0
command cd /path_to_www2/ #
exitcode 0
command svn up
exitcode 0
command /etc/init.d/apache restart
exitcode 0
}


So here: first, group 1 will be updated, then group 2.

2) downloading files and updating crypts with restarting Apache:

Take a set of groups and hosts from the last example and write to them a new script:

@script path_1 {
command su #
expect Password #
command MegArOooOtPas$ #
exitcode 0 #
upload local_code.tgz /tmp/remote.tgz
command cd /path_to_www1/ #
exitcode 0 #
command tar xzpf /tmp/remote.tgz #
exitcode 0 #
command /etc/init.d/apache restart #
exitcode 0 #
}

@script path_2 {
command su
expect Password
command MegArOooOtPas$
exitcode 0
upload local_code.tgz /tmp/remote.tgz
command cd /path_to_www2/ #
exitcode 0
command tar xzpf /tmp/remote.tgz
exitcode 0
command /etc/init.d/apache restart
exitcode 0
}


this is how you can quickly and easily solve voluminous tasks in a short time,
By the way, try to do the same thing at your leisure with a mouse on 10 win machines.

From the author ( catdog ):

There is no program site yet and I hardly have time for it, however, bug fixes and improvements will be uploaded to the repository as they arise. Also, if you have comments and suggestions, please write me a profile soap. I don't have enough karma to publish, so look for updates here:

svn.myau.su/listing.php?repname=robot

The tags are stable versions of the trunk unstable.

Source: https://habr.com/ru/post/66307/


All Articles