REX(1p)
πΈ REX(1p) β ok bestie, let's talk about rex πΈ
User Contributed Perl Documentation energy, but make it a group chat. This is the manual page for rex, the lil command-line icon that runs the tasks you wrote in your Rexfile. Sit down, hydrate, we're doing infra. π
β¨ NAME β¨
rex β execute tasks defined in a Rexfile. That's it, that's the whole vibe. π
π DESCRIPTION π
So the rex script is literally your command-line bestie: it lets you execute tasks that you defined in a Rexfile, straight from the terminal. No GUI, no drama, just tasks. Slay. β¨
π¦ 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. Six whole lines and she can do all of that. π
π USAGE π
rex [<options>] [-H <host>] [-G <group>] <task> [<task-options>]
rex -T[m|y|v] [<string>]
π«Ά the options, one by one, no skipping (iykyk)
π₯ the "who am I running this on" options
-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.
π the ssh options
-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.
π£οΈ the "how much do you wanna hear from me" options
-dβ Show debug output.-dddβ Show more debug output (includes profiling output).-mβ Monochrome output: no colors. (π a sad day but okay)-oβ Output format.-qβ Quiet mode: no log output.-qwβ Quiet mode: only output warnings and errors.-Qβ Really quiet: output nothing. not a single peep.
π the task-listing options
-Tβ List tasks.-Taβ List all tasks, including hidden. (the hidden ones?? π)-Tmβ List tasks in machine-readable format.-Tvβ List tasks verbosely.-Tyβ List tasks in YAML format.
βοΈ the rest of the lineup (all iconic, all required)
-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 is made of 2 major parts: configuration and task definitions. Two parts. That's the whole structure. Periodt. π
πΈ 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 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. there are options, bestie, explore.
β±οΈ 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. Yes, she stays local until you tell her otherwise.
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 the command line just hands your task its options?? 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.
ngl, tab completion is the main character here. You press <TAB> and she just knows your hosts, your groups, your environments and your tasks. ate. π
okay that's the whole page, you made it, I'm so proud of you π«Άβ¨
This was brought to you by perl v5.40.1, dated 2025-10-03 β that's the version and the date, bestie, write them down, they're part of the lore. πππ¦
π¦ where this page comes from
- ubuntu resolute: rex 1.16.1-1 Β· Apache-2.0
- ubuntu stonking: rex 1.16.1-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms