The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!perl -w

#
# (c) Jan Gehring <jan.gehring@gmail.com>
#
# vim: set ts=3 sw=3 tw=0:
# vim: set expandtab:

use strict;
use warnings;

use Rex::CLI;

my $rex = Rex::CLI->new;
$rex->__run__;

__END__

=pod

=head1 (R)?ex - (Remote)? Execution

Rex is a tool to ease the execution of commands on multiple remote servers. You can define small tasks, chain tasks to batches, link them with servers or server groups, and execute them easily in your terminal.

=head2 Command line options

=over 4

=item -b              Run batch

=item -e              Run the give code fragment

=item -E              Execute task on the given environment

=item -H              Execute task on these hosts

=item -G              Execute task on these group

=item -u              Username for the ssh connection

=item -p              Password for the ssh connection

=item -P              Private Keyfile for the ssh connection

=item -K              Public Keyfile for the ssh connection

=item -T              List all known tasks.

=item -f              Use this file instead of Rexfile

=item -h              Display this help

=item -M              Load Module instead of Rexfile

=item -s              Use sudo for every command

=item -S              Password for sudo

=item -v              Display (R)?ex Version

=item -F              Force. Don't regard lock file

=item -d              Debug

=item -dd             More Debug (includes Profiling Output)

=item -o <module>     Create a compatible output for the given module

=item -C              Turn cache OFF

=item -c              Turn cache ON

=back


=head2 Rexfile

If you run I<rex> it will read the file I<Rexfile> in the current working directory. A Rexfile consists 3 major parts.

=head3 Authentication and Configuration

In that part you define the user and password you want to use to log into your servers. You can even define timeouts or the paralellism of task exexecution.

=head4 Simple Authentication

B<Define the user>

 user "<user>";

B<Define the password>

 password "<password>";

B<Set password authentication>

 pass_auth;


=head4 Key Authentication

B<Define Private Key>

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

B<Define Public Key>

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

=head4 Define Logging

B<Log to a file>

 logging to_file => "rex.log";

B<Log to syslog>

 logging to_syslog => "local0";

=head4 Other Configuration parameters

B<Define ssh timeout>

 timeout 10;

B<Define parallelism>

 parallelism 2;

=head3 Group your servers

Rex gives you the possibility to B<group your servers>. One way is to do
it in code within the Rexfile. Another is to use a I<server.ini> file
in the same directory as the Rexfile.

=head4 Code in the Rexfile

Rex gives you the possibility to B<group your servers>. So you don't need to type every servername multiple times.

 group "frontends" => "frontend01", "frontend02", "frontend03", "frontend04";

You can even B<define ranges> in the servernames:

 group "frontends" => "frontend[01..04]";

=head4 Using server.ini

The same group definition can be stored in a I<server.ini> file:

 [frontends]
 frontend[01..04]

=head3 Your tasks

B<Create a task description>

 desc "This is a long description of a task";

B<Create the task>

 task "shortname", group => "frontends", sub {
     run "uptime";
 };

B<or, if you don't have groups>

 task "shortname", "frontend01", "frontend02", "frontend03", "frontend04", sub {
     run "uptime";
 };

B<and with serverranges>

 task "shortname", "frontend[01..04]", sub {
     run "uptime";
 };

=cut