« Previous 1 2
First steps in IT automation by Rex
Automation Tool
How to Edit config Files
Sar is now installed, but it can't gather any data yet. First of all, you have to change the entry ENABLED=
from false
to true
in /etc/default/sysstat
file. You can use Rex either to overwrite the whole sysstat
file or to update the file with the necessary change. Use a script like the snippet in Listing 5 to change only the relevant word.
Listing 5
Editing the Configuration
01 task "enable_sar", group => "server", sub { 02 run qq(sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat); 03 service "sysstat" => "restart"; 04 };
Rex actually has a special command for replacing text in a file:
task searchreplace => sub { sed qr{search}, "replace", "/directory/file.txt"; };
Related commands allow you to delete lines that match a search pattern, to overwrite whole files, or to append lines. After changing a configuration file, you'll need to restart the service you are updating. As Listing 5 shows, Rex will again work with an abstraction. The restart
command is translated into a command with the same name under Ubuntu or to an equivalent svcadm
call under Solaris.
User Management and Other Tasks
Rex offers numerous commands for typical tasks that occur regularly on the admin's agenda. For example, you can use Rex to create and delete groups, start and stop processes, manage cron jobs, manipulate Iptables rules, load kernel modules, download files with scp
, or edit system parameters with sysctl
.
Rex also provides detailed information about the client systems. This information goes from a simple query of the operating system (get_operating_system()
) to a long list with all kinds of details (as shown in Listing 6).
Listing 6
dump_system_information()
01 root@hercules:/home/jcb/Rex/test# rex sysinfo 02 [2014-04-25 10:49:34] INFO - Running task sysinfo on sugar 03 [2014-04-25 10:49:34] INFO - Connecting to sugar:22 (root) 04 [2014-04-25 10:49:34] INFO - Connected to sugar, trying to authenticate. 05 [2014-04-25 10:49:35] INFO - Successfully authenticated on sugar. 06 $memory_cached = '89' 07 $Kernel = { 08 kernelversion => '#25~precise1-Ubuntu SMP Thu Jan 30 17:42:40 UTC 2014' 09 architecture => 'i686' 10 kernel => 'Linux' 11 kernelrelease => '3.11.0-15-generic' 12 } 13 $hostname = 'sugar' 14 $operating_system = 'Ubuntu' 15 $operatingsystem = 'Ubuntu' 16 $operating_system_release = '12.04' 17 $eth0_mac = '08:00:27:c4:a1:d8' 18 $VirtInfo = { 19 virtualization_role => 'guest' 20 virtualization_type => 'virtualbox' 21 } 22 $memory_shared = '0' 23 $Network = { 24 networkdevices => [ 25 'lo' 26 'eth0' 27 ] 28 networkconfiguration => { 29 lo => { 30 broadcast => '' 31 ip => '127.0.0.1' 32 netmask => '255.0.0.0' 33 mac => '' 34 } 35 eth0 => { 36 broadcast => '192.168.111.255' 37 ip => '192.168.111.188' 38 netmask => '255.255.255.0' 39 mac => '08:00:27:c4:a1:d8' 40 } 41 } 42 } 43 $Swap = { 44 free => '509' 45 used => '0' 46 total => '509' 47 } 48 $eth0_ip = '192.168.111.188' 49 $swap_used = '0' 50 $Host = { 51 kernelname => 'Linux' 52 operating_system => 'Ubuntu' 53 hostname => 'sugar' 54 operatingsystemrelease => '12.04' 55 operatingsystem => 'Ubuntu' 56 domain => '' 57 operating_system_release => '12.04' 58 manufacturer => 'innotek GmbH' 59 } 60 $kernelversion = '#25~precise1-Ubuntu SMP Thu Jan 30 17:42:40 UTC 2014' 61 $memory_total = '494' 62 $kernelrelease = '3.11.0-15-generic' 63 $operatingsystemrelease = '12.04' 64 $architecture = 'i686' 65 $domain = '' 66 $swap_free = '509' 67 $lo_broadcast = '' 68 $kernel = 'Linux' 69 $memory_used = '178' 70 $kernelname = 'Linux' 71 $swap_total = '509' 72 $memory_buffers = '12' 73 $lo_netmask = '255.0.0.0' 74 $lo_ip = '127.0.0.1' 75 $lo_mac = '' 76 $memory_free = '316' 77 $manufacturer = 'innotek GmbH' 78 $Memory = { 79 shared => '0' 80 buffers => '12' 81 free => '316' 82 used => '178' 83 total => '494' 84 cached => '89' 85 } 86 $ETH0_broadcast = '192.168.111.255' 87 $ETH0_netmask = '255.255.255.0'
Rex can also report details about hypervisors, and it can create, configure, start, stop, and destroy virtual machines with VirtualBox, KVM, and Xen. You can even use Rex to monitor a system running in Amazon's Elastic Compute Cloud (EC2).
Summary
The most impressive thing about Rex is its ease of use. An experienced admin only needs a short amount of time to learn the ropes. The requirements for the central Rex host and its clients are minimal, which means it won't take you long to start benefiting from the automation of the Rex environment. Rex helps you avoid typos and gives you access to a useful collection of well-documented system-management commands, but perhaps the biggest benefit is the time you'll save with parallel execution of common tasks on all clients.
One weakness of Rex is the lack of documentation. An online book about Rex isn't much more than an index of contents and a FAQ consists with only of a handful questions. At least the documentation of the API functions seems complete. The error message documentation might help a Perl developer who can study the Perl sources, but it is not very helpful for the ordinary user.
Infos
- Rex Repositories: http://www.rexify.org/get/index.html
- CPAN Archive: http://search.cpan.org
- Performance Co-Pilot: http://oss.sgi.com/projects/pcp
- Sysstat Homepage: http://sebastien.godard.pagesperso-orange.fr
« Previous 1 2
Buy this article as PDF
(incl. VAT)