(R)?ex Deployment & Configuration Management



adjust GmbH is sponsoring the (R)?ex project with a new build server. Thank you for your support!
(R)?ex 1.3.2 released, fixing issues related to file manipulation when run on BSDs. See the release notes for more details.
Read the second part of "Rex in practice" series about Test-driven infrastructure.
(R)?ex 1.3.1 released, fixing Rex::Commands::DB related tests.
repositor.io 1.1.0 released. repositor.io is a repository management tool for apt, yum, yast and docker. This is a bugfix release with fixes for ubuntu and centos7 installation media mirroring.
View the slides of the talk An introduction to Rex from Andy Beverley.


Talk Infrastructure as Code (ger) at German Perl Workshop.


2015-11-30/2015-12-01 (Karlsruhe)

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 scenarios if something went wrong during the execution.


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.


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 on your 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 file called Rexfile with the following contents:

use Rex -feature => ['1.0'];

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

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

desc "Get the uptime of all servers";
task "uptime", group => "myservers", 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 myservers and run the command "uptime".

The special first line use Rex -feature => ['1.0']; enables all features that are available for version 1.0. If you want to know more about feature flags, please read this page.

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 => "myservers", sub {
    service "apache2" => "start";

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

Display all tasks in a Rexfile

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

$ rex -T
  start_apache                   Start Apache Service
  uptime                         Get the uptime of all servers
Server Groups
  myservers                       mywebserver, mymailserver, myfileserver


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";

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";

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
use Rex -feature => ['1.0'];

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
   pkg "ntpd",
     ensure => "present";

   # 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