REX(1p)

πŸ“¦
version 1.16.1 Β· 5 versions
, in ubuntu resolute, ubuntu stonking

🌸 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