REX(1)
π REX(1) π
okay bestie, pull up a chair π«Ά you're looking at rex, the manual page for the rex command. yes that's the manual name, it's literally in the title, we love a self-titled icon π
β¨ NAME β¨
rex β execute tasks defined in a Rexfile πΈ
π DESCRIPTION π
The rex script can be used to execute tasks defined in a Rexfile from the command line. that's the whole job description and honestly? main character energy π
π SYNOPSIS π
rex -h # Show usage
rex -T # List tasks
rex uname # Run the 'uname' task
rex -H server[01..10] uname # Run the 'uname' task on all the specified hosts
rex -G production uname # Run 'uname' on hosts on the 'production' hostgroup
rex deploy --gracefully # Pass '--gracefully' to the 'deploy' task
look at her go β¨ six whole vibes and every single one is a slay.
π USAGE π
rex [<options>] [-H <host>] [-G <group>] <task> [<task-options>]
rex -T[m|y|v] [<string>]
and now the option buffet, no skipping, we're eating everything π
-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-Taβ List all tasks, including hidden-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
yes bestie, that's thirty-three of them. we counted. not one got left behind π€
π¦ 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. two parts, both essential, like you and your emotional support terminal π
π₯ Configuration π₯
See all the available commands in Rex::Commands.
π§ 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';
key_auth;
π 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 in the Rexfile:
group 'frontends' => 'frontend01', 'frontend02', 'frontend[03..09]';
Groups can also be defined in separate files, like server.ini:
# server.ini
[frontends]
frontend[01..04]
# Rexfile
use Rex::Group::Lookup::INI;
groups_file 'file.ini'
See Rex::Group::Lookup::INI for more details, and check the Rex::Group::Lookup namespace for other formats. options for days, we love a namespace with range π
π 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';
};
By default it will be targeted at the same host where rex is being executed.
You can also set a default server as the task's target:
desc 'This is a long description of a task';
task 'shortname',
'frontend01',
sub {
say run 'uptime';
};
or even a default server group:
desc 'This is a long description of a task';
task 'shortname',
group => 'frontends',
sub {
say run 'uptime';
};
The task options from the command line will be passed to the task as well:
# Rexfile
desc 'Get task options';
task 'get_task_options', sub {
my $task_options = shift;
my $option1 = $task_options->{option1};
};
# command line
rex get_task_options --option1=yes
the way that command line just hands its options straight to the task?? obsessed π
β TAB COMPLETION β
Tab completion scripts are provided for Bash and Zsh in the share directory at https://metacpan.org/release/Rex/source/share. They provide completions for the available CLI options, hosts, groups, environments and tasks. no more typing the whole thing like a peasant, we're pressing Tab and letting the machine do the labour π§β¨
and that's the whole page, bestie!! this little beauty is perl v5.42.0, dated 2025-08-09, and yes she ate and left absolutely no crumbs πππ¦ periodt.
π¦ where this page comes from
- fedora 43: Rex 1.16.1-1.fc43 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms