(R)?ex Deployment & Configuration Management




Work with (R)?ex at adjust! Check out their job posting for details, or contact our fellow core developer, FErki.


(R)?ex 1.4.1 released, fixing many bugs. See the release notes for more details.


(R)?ex 1.4.0 released, containing lots of goodies. See the release notes for more details.


(R)?ex 1.3.3 released, fixing a bunch of bugs. See the release notes for more details.


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.


(R)?ex 1.3.1 released, fixing Rex::Commands::DB related tests.


Read the second part of "Rex in practice" series about Test-driven infrastructure.


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.


(R)?ex 1.2.0 released. See the release notes for more details.


View the slides of the talk An introduction to Rex from Andy Beverley.




Need Help?

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

Professional support is also available.

» Home » Docs » Rex Book (work in progress) » The Rex DSL » Grouping servers

Grouping servers

Rex offers you a powerfull way to group your servers. The simplest way to use groups is to just define a group name and add all your desired servers to this group.

group frontends => "frontend01", "frontend02", "frontend03";
group backends => "backend01", "backend02";

Rex offers also a simple notation to define server ranges, so that you don't need to type so much.

group frontends => "frontend[01..03]";
group backends => "backend[01..02]";

This notation will just expand to frontend01, frontend02 and frontend03 for the frontends group and to backend01 and backend02 for the backends group.

Custom parameters for servers are possible with a slightly enhanced syntax since version 0.47:

group frontends =>
   "frontend01" => { user => "bob" },
   "frontend02" => { user => "alice" },

Because the Rexfile is a Perl script you can just use more advanced things like querying a database, ldap or your dns.

To add your groups to the tasks you have to use the group option within the task generation.

task "mytask", group => "mygroup", sub {
   # do something

If you need to define multiple groups for a task, you can just use an array.

task "mytask", group => ["mygroup", "mygroup2"], sub {
   # do something

Using an INI file to define server groups

Rex offers a simple way to query ini files for group creation. To use ini files you have to use the Rex::Group::Lookup::INI module.

use Rex -feature => ['1.0'];
use Rex::Group::Lookup::INI;

groups_file "/path/to/your/file.ini";

Rex expects the following format inside your INI file.



Rex also offers a little bit advanced functions for the ini file. You can define custom parameters for each server or include groups inside groups.

frontend02 user=root password=f00bar auth_type=pass maintenance=1



These additional options (in this example maintenance can be queried with the option method from the connection object.

task "prepare", group => "frontends", sub {
   if(connection->server->option("maintenance")) {
      say "This server is in maintenance mode, so i'm going to stop all services";
      service ["apache2", "postfix"] => "stop";

Quering a database to define server groups

If you want to get your server groups right out of an existing database you can use DBI to connect to your database server. In this example you will learn how to connect to a MySQL database and to get the hosts out of a table.

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

my $username = "dbuser";
my $password = "dbpassword";
my $database = "hostdb";
my $hostname = "mysql.intern.lan";
my $port     = 3306;
my $dsn      = "DBI:mysql:database=$database;host=$hostname;port=$port";
my $dbh      = DBI->connect($username, $password);

my $sth      = $dbh->prepare("SELECT * FROM hostlist WHERE enabled=1");

my %server_group = ();
while(my $row = $sth->fetchrow_hashref) {
   my $group_name  = $row->{server_group};
   my $server_name = $row->{server_name};
   push @{ $server_group{ $group_name } }, $server_name;

map {
   group $_ => @{ $server_group{$_} };
} keys %server_group;

This example expects the following column names:

Creating custom groups

If there is no built-in function that fits your needs for group creation, you can do it all by yourself. Because the Rexfile is just a plain perl script and the group command is just a perl function that expects the group name as first parameter, and uses all other parameters for the servers, you can create your own function.

my @list = ("some", "list", "entries");
group mygroup => grep { /list/ } @list;
group myserver => map {"s$_.domain.com"} qw(1 3 7);



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