Howto start using (R)?ex

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

Preparation

Creating a Rexfile

At first create a file named Rexfile in your $HOME directory (or anywhere else).

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 {

   say run "uptime";

};
            

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 /home/jan
$ rex uptime

Adding a second task

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

desc "Start Apache Service";
task "free", 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.

bash# rex -T
Tasks
  free                           Start Apache Service
  uptime                         Get the uptime of all server
Batches 

Comments



Use [code]...[/code] for a code block.
 

tobias@honacker.info - 2012-05-03 15:49:16 Comment

if your ssh service is listening for example on port 3000 use
 group myserver => "mywebserver:3000";
maybe there is another method?


Use [code]...[/code] for a code block.
 
Comment from: tobias@honacker.info - 2012-05-04 11:05:39
user "my-user";
password "my-password";
pass_auth;
port "3000";

Jan - 2011-06-21 19:32:55 Comment

If you want to use key authentication just use the following lines:
private_key "/path/to/your/private_key";
public_key "/path/to/your/public_key";
And remove the line "pass_auth;".


Use [code]...[/code] for a code block.
 
Fork me on GitHub