REX(1)

πŸ“¦
version 1.16.1 Β· 3 versions
, in fedora 43

πŸ’– 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