(R)?ex Deployment & Configuration Management

Search

News

2014-07-13
(R)?ex 0.49.1 released. This release adds support for FreeBSD 10 and pkgng.
2014-07-09
(R)?ex 0.48.0 released. This release adds support for CentOS 7 and RHEL 7.
2014-07-07
(R)?ex 0.47.0 released. This release comes with KVM support for Rex::Test and lots of small enhancements and bugfixes. Read the release notes for more information.
2014-07-02
For the website and build.rexify.org we are now using SSL certificates signed by CACert.org.
2014-05-31
Read the new howto to setup OpenLDAP and SSSD with Rex.
2014-04-03
Talk from Ferenc Erki at Free Software Conference of Szeged uploaded to slideshare

Conferences

2014-05-08 - 2014-05-10

Visit us at the LinuxTag in Berlin. There will be also a Rex hands-on workshop on Friday (2014-05-09).

LinuxTag is Europe's leading exhibition and conference for Linux, Free Software and Open Source.

Need Help?

Rex is a pure open source project, you can find community support in the following places:

Professional support is also available.

Howto start using (R)?ex

This is a small howto showing the first steps with (R)?ex.

Basic Architecture

(R)?ex is a server orchestration tool that doesn't need an agent on the hosts you want to manage. In fact it uses ssh to execute the given commands.

To use (R)?ex you don't need Perl knowledge at first. (R)?ex uses a simple DSL to describe your servers. Indeed, it is also possible to use (R)?ex from within your shell scripts without using perl at all.

In fact, if you know a little bit perl it won't hurt you.

The starting point of every (R)?ex project is the so called Rexfile. You can think of this file like a Makefile. You can define tasks in this file.

A task is a bunch of related commands. For example installing a package, uploading the configuration file and starting the service. You can also call tasks from other tasks or create rollback szenarios if something went wrong during the execution.

Requirements

To run (R)?ex you don't need much.

Central Master Host

You can run (R)?ex from your workstation or on a central master host.

For your central (R)?ex machine (the master) you need at least Perl 5.8. For a better experience we recommend using Perl 5.10.1 and above.

On this host you also need some Perl modules installed. You can install those modules via your distributions repository or via our (R)?ex repository.

  • Net::SSH2
  • YAML
  • LWP
  • DBI (if you want to use Database Access)
  • JSON::XS (if you want to use the Jiffybox or OpenStack Cloud Provider)
  • XML::Simple (if you want to use FusionInventory for system inventory, for Amazon Cloud Provider and for the Virtualization Commands)
  • String::Escape (if you want to define your groups with ini files)

Managed Hosts

On the systems you want to manage you just need a Perl 5 interpreter installed and a valid SSH account. If you want to do administrative tasks you need root or sudo access.

Preparation

You can install (R)?ex on a Linux host via a simple one-liner. For other systems please read the instructions on the Get Rex page.

$ curl -L get.rexify.org | perl - --sudo -n Rex

This command will install Rex onto you system. You need libssh2 development libraries installed for this to work.

We recommend to use our packages from the repository.

Creating a Rexfile

First we need to create a new folder to store your Rexfile in it.

$ mkdir -p projects/my-first-rex-project

Now change into this directory and create a Rexfile.

user "my-user";
password "my-password";
pass_auth;

group myserver => "mywebserver", "mymailserver", "myfileserver";

desc "Get the uptime of all server";
task "uptime", group => "myserver", sub {
   my $output = run "uptime";
   say $output;
};

This Example will login as my-user with the password my-password on all the servers in the group myserver and run the command "uptime".

Change into the directory where you just created the Rexfile (in a terminal).

$ cd projects/my-first-rex-project
$ rex uptime

Adding a second task

To add a second task, just add the next lines to your Rexfile.

desc "Start Apache Service";
task "start_apache", group => "myserver", sub {
    service "apache2" => "start";
};

This task will start the service apache2 on all the servers in the myserver group.

Display all tasks in a Rexfile

If you want to display all tasks in your Rexfile use the following command.

$ rex -T
Tasks
  start_apache                   Start Apache Service
  uptime                         Get the uptime of all server

Authentication

In the previous example we showed you how you can login with a user and a password. But it is also possible to use key authentication.

To use key authentication just define your private and public key inside the Rexfile.

user "my-user";
private_key "/home/user/.ssh/id_rsa";
public_key "/home/user/.ssh/id_rsa.pub";
key_auth;

It is also possible to use your keys with a passphrase. Just add it to your Rexfile.

user "my-user";
private_key "/home/user/.ssh/id_rsa";
public_key "/home/user/.ssh/id_rsa.pub";
password "key-passphrase";
key_auth;

If you don't want to add your passphrase to the Rexfile you can also use ssh-agent. (R)?ex will automatically use it when it is running. Just remove the line key_auth;.

Managing Services

If you want to manage services you often need to upload a configuration file and to register the service to start at boot time.

In this example you will learn how to install and configure ntp. You can adapt this example to every other service easily.

# Rexfile
user "root";
private_key "/root/.ssh/id_rsa";
public_key "/root/.ssh/id_rsa.pub";

group all_servers => "srv[001..150]";

task "setup_ntp", group => "all_servers", sub {

   # first we will install the package
   install "ntpd";

   # then we will upload a configuration file.
   # the configuration file is located in a subdirectory files/etc.
   file "/etc/ntp.conf",
      source    => "files/etc/ntp.conf",
      on_change => sub {
         # we define a on_change hook, so that the ntpd server gets restarted if the file is modified.
         service ntpd => "restart";
      };

   # now we register the service to start at boot time.
   service ntpd => ensure => "started";
};

That's all.

This task will now install ntpd on your servers, upload a configuration file and start the service.

You don't need to worry about the order of your commands. (R)?ex will always executes your commands from top to bottom.

To read more about using modules and templates please read this howto.

comments powered by Disqus
Fork me on GitHub
Google Group / Twitter / GitHub / Mailinglist / irc.freenode.net #rex   -.รด.-   Disclaimer