REX(1)

NAME
(R)?ex - (Remote)? Execution

DESCRIPTION
Rex is a command line tool which executes commands on remote servers. Define tasks in Perl and execute them on remote servers or groups of servers.

Rex can be used to:

- Deploy web applications to servers sequentially or in parallel.
- Automate common tasks.
- Provision servers using Rex's builtin tools.

SYNOPSIS
    bash# rex -h                      # Show usage
    bash# rex -T                      # List tasks
    bash# rex uname                   # Run the 'uname' task
    bash# rex -H server[01..10] uname # Run the 'uname' task on all the specified hosts
    bash# rex -G production uname     # Run 'uname' on hosts on the 'production' hostgroup
    bash# rex deploy --gracefully     # Pass '--gracefully' to the 'deploy' task

USAGE
    rex [<options>] [-H <host>] [-G <group>] <task> [<task-options>]
    rex -T[m|y|v] [<string>]

    -b     Run batch
    -e     Run the given code fragment
    -E     Execute a task on the given environment
    -G|-g  Execute a task on the given server groups
    -H     Execute a task on the given hosts (space delimited)
    -z     Execute a task on hosts from this command's output

    -K     Public key file for the ssh connection
    -P     Private key file for the ssh connection
    -p     Password for the ssh connection
    -u     Username for the ssh connection

    -d     Show debug output
    -ddd   Show more debug output (includes profiling output)
    -m     Monochrome output: no colors
    -o     Output format
    -q     Quiet mode: no log output
    -qw    Quiet mode: only output warnings and errors
    -Q     Really quiet: output nothing

    -T     List tasks
    -Tm    List tasks in machine-readable format
    -Tv    List tasks verbosely
    -Ty    List tasks in YAML format

    -c     Turn cache ON
    -C     Turn cache OFF
    -f     Use this file instead of Rexfile
    -F     Force: disregard lock file
    -h     Display this help message
    -M     Load this module instead of Rexfile
    -O     Pass additional options, like CMDB path
    -s     Use sudo for every command
    -S     Password for sudo
    -t     Number of threads to use (aka 'parallelism' param)
    -v     Display (R)?ex version

Rexfile
When you run "rex" it reads the file "Rexfile" in the current working directory. A Rexfile consists of 2 major parts: Configuration and Task Definitions.

  Configuration
Simple Authentication

    user "bruce";
    password "batman";
    pass_auth;

Key Authentication

    private_key "/path/to/your/private/key.file";
    public_key "/path/to/your/public/key.file";

Define Logging

    logging to_file => "rex.log";
    logging to_syslog => "local0";

Group your servers

Rex gives you the ability to define groups of servers. Groups can be defined the Rexfile:

    group "frontends" => "frontend01", "frontend02", "frontend03", "frontend04", "frontend[05..09]";

Groups can also be defined in a server.ini file:

    [frontends]
    frontend[01..04]

  Other Configuration
    timeout 10;    # ssh timeout
    parallelism 2; # execute tasks in parallel

  Defining tasks
A basic task looks like this:

    # task description
    desc "This task tells you how long since the server was rebooted";

    # task definition
    task "shortname", sub {
        say run "uptime";
    };

You can also set a default server group:

    desc "This is a long description of a task";
    task "shortname", group => "frontends", sub {
        say run "uptime";
    };