Automation with Rex

With (R)?ex you can manage all your boxes from a central point through the complete process of configuration management and software deployment. (R)?ex uses SSH as its default transport layer. So there is no need to install anything on your servers. You just need a ssh enabled account.

Install Rex server

Since Rex is using SSH as its transport layer, we only have to install Rex on one central instance, called rex server. We do not need to install anything on all the other servers, except OpenSSH, of course. At the beginning we configure basic security (SSH) and setup a user for Rex.

Setup the Rex user

Now add a user for Rex:

sudo adduser rex  
sudo adduser rex sudo  

Go back to your client, and copy your public key into rex user:

ssh-copy-id [email protected]  

Login to the rex user on the rex server

ssh [email protected]  

The rex user will need a private/public keypair, in order to login into the servers without password authentication. For that reason, we generate this keys on the rex server, without passphrase, just accept the defaults!

ssh-keygen -t rsa  

I'm using the rex user, created above, to login to the all the servers. First login as rex user at the rex server, and copy its public key to the root user, or a user with all the sudo rights, on all the servers you are going to manage by rex: ssh-copy-id [email protected].

Now test the SSH login with your keypair and make sure it works because we're going to disable any other login method. Make sure this user can use sudo too.

ssh [email protected]  
sudo su  

When this works on all the server, ...

Basic SSH setup

Since the rex server will have access to all your servers, pay more attention to its security config: disable root login as well as disable login with passwords. Change in /etc/ssh/sshd_config.

nano /etc/ssh/sshd_config  
PermitRootLogin no  
PasswordAuthentication no  

or permit only key authentication for root login, not via password, like PermitRootLogin without-password.

Restart the ssh daemon by service ssh restart.

Install Rex via APT repository

It is the most simple way, just prepare the Rex repository and simple install rex via apt-get. On Ubuntu Precise (12.04) LTS:

sudo su  
echo 'deb precise rex' >> /etc/apt/sources.list.d/rex.list  
wget -O - | apt-key add -  
apt-get update  
apt-get install rex  

Lots of Perl libraries will be installed, next to Rex binaries, see the perl modules i.e. at /usr/share/perl5/Rex

Install Rex from source code on Github

You find the repository of Rex here. Install a particular version (i.e. 0.40) is easy, since each version is a git branch. First we need to install the tools we need to compile the source code to binaries, as well as Git:

sudo apt-get install build-essential  
sudo apt-get install git  

Then we need few libraries, on which Rex depends, using Ubuntu Precise (12.04) LTS:

sudo apt-get install libdbi-perl libexpect-perl libdigest-hmac-perl libhttp-date-perl libjson-xs-perl libyaml-perl libxml-simple-perl libnet-ssh2-perl  

Now we download the latest source code from into a directory in /usr/local/src.

sudo su  
cd /usr/local/src  
git clone RexHead  

If you want to have a particular Rex version, use this, for example to get Rex 0.40: git clone -b 0.40 Rex040.

Next step is to build binaries from source, still as root, switch into the Rex source directory and compile the binaries. Do not forget to do it as root:

cd RexHead  
perl Makefile.PL make  
make test  
make install  

The code will be installed into few directories in /usr/local:

  • /usr/local/bin: the two executables of Rex (rex and rexify)
  • /usr/local/lib: the package list (see /usr/local/lib/perl/5.14.2/auto/Rex)
  • /usr/local/share: the perl modules (see in /usr/local/share/perl/5.14.2) and the man pages (/usr/local/share/man)

If you want to install another Rex version, delete these files from /usr/local, clone the source code in an other version from Github, and compile again. To delete previous Rex version from /usr/local/bin and /usr/local/share/perl/5.14.2 use:

sudo rm /usr/local/bin/rex  
sudo rm /usr/local/bin/rexify  
sudo rm -rf /usr/local/share/perl/5.14.2  

Ready, steady, go...

First, check Rex version:

rex -v  

gives something like (R)?ex 0.40.4

To start, go to your home and switch back to your user, and type rexify myFirstProject

Rex generates for you the first templates to start the journey.

rex -T rex blabla