Rex(3pm)
β¨ NAME β¨
Rex π β the friendly automation framework. This is the Rex(3pm) page, bestie, and yes it's giving main character energy in your terminal right now.
πΈ DESCRIPTION πΈ
Rex is an automation framework that is friendly to any combination of local and remote execution, push and pull style of management, or imperative and declarative approach. Like, she does not care how you like to do things, she's just happy to be there. π«Ά
That flexibility makes her a great fit for sooo many different use cases, but most commonly Rex gets used to automate application deployment and data center infrastructure management tasks. Periodt.
If you want a starting point for what commands she ships with built-in, go peek at Rex::Commands. π
And if you wanna know how to use rex on the command line, there's more info at https://metacpan.org/pod/distribution/Rex/bin/rex.
π SYNOPSIS π
# In a Rexfile:
use Rex -feature => [qw/1.4/];
user "root";
password "ch4ngem3";
desc "Show system information";
task "sysinfo", sub {
say run "uname -a";
};
1;
# On the command line:
$ rex -H server[01..10] sysinfo
π CLASS METHODS π
π¦ get_current_connection
Ok so heads up: this function is deprecated since 0.28! π Go look at Rex::Commands::connection instead, bestie.
It returns the current connection as a hashRef, and that hashRef has:
serverβ the server namesshβ1if it's a ssh connection,0if not
π¦ is_ssh
Returns 1 if the current connection is a ssh connection. 0 if not. Simple as that, slay. β¨
π¦ is_local
Returns 1 if the current connection is local. Otherwise 0.
π¦ is_sudo
Returns 1 if the current operation is executed within sudo. π
π¦ get_sftp
Returns the sftp object for the current ssh connection. π
π¦ connect
Use this function to create a connection if you're using Rex as a library. It's giving "I brought my own setup".
use Rex;
use Rex::Commands::Run;
use Rex::Commands::Fs;
Rex::connect(
server => "remotehost",
user => "root",
password => "f00b4r",
private_key => "/path/to/private/key/file",
public_key => "/path/to/public/key/file",
);
if(is_file("/foo/bar")) {
print "Do something...\n";
}
my $output = run("uptime");
π FEATURE FLAGS π
Everyone knows the pain when something gets deprecated and you have to port your old (and stable, and beloved, and honestly? perfect) code over to a new version of a library or framework. Like, there is enough work to do in this world without fixing your code to work with newer versions. π
So there is one promise new versions of Rex has to fulfill: they must be backward compatible. No cap.
The author knows this might be impossible in one way or another, but to minimize that danger there's a thing called feature flags. If there's ever a need to break backward compatibility in favor of a new feature, there will be a feature flag for that change. And only if that feature flag gets enabled in the Rexfile will it break compatibility.
So the default is always, always: stay compatible. π«Ά
If you have a problem that occurs after an update, it counts as a bug. Please report that bug in the issue tracker.
Also go read the backwards compatibility section of the CONTRIBUTING guide: https://metacpan.org/release/Rex/source/CONTRIBUTING.md#backwardscompatibility
π How to enable feature flags
You can enable feature flags in your Rexfile with this code:
use Rex -feature => ['1.4'];
or even multiple ones at once, like this, because you contain multitudes:
use Rex -feature => [qw(1.4 exec_autodie)];
π List of feature flags
1.4β Enable per-task argument parsing (task_chaining_cmdline_args). Furthermore, all features from earlier versions are activated. Available since version 1.4. β¨no_task_chaining_cmdline_argsβ Disable per-task argument parsing. Available since version 1.4.task_chaining_cmdline_argsβ Enable per-task argument parsing:rex --rex --args task1 --task1arg=value task2 --task2argsotask1only getstask1argandtask2only getstask2arg. Available since version 1.4. π₯1.3β Activating the new template engine by default. Furthermore, all features from earlier versions are activated. Available since version 1.3.no_template_ngβ Disabling the new template engine. Available since version 1.3.1.0β Disabling usage of a tty. This increases compatibility for remote execution. Furthermore, all features from earlier versions are activated. Available since version 1.0.no_autodieβ Will disable autodie feature. Available since version 1.0.ttyβ Enable pty usage for ssh connections. Available since version 1.0.template_ngβ Enabling the new template engine (better error reporting, etc.). Available since version 0.56. πΈ0.56β Will activate autodie feature. Furthermore, all features from earlier versions are activated. Available since version 0.56.autodieβ Will enable autodie feature: die on all failed filesystem commands (https://metacpan.org/pod/Rex::Commands::Fs). Available since version 1.13.1.0.55β Will activate using Net::OpenSSH by default if present. Furthermore, all features from earlier versions are activated. Available since version 0.55.0.54β Will activate checking services for existence before trying to manipulate them, andset()will overwrite already existing values (instead of concatenating). Furthermore, all features from earlier versions are activated. Available since version 0.54.0.53β Will activateregister_cmdb_top_scope. And all things 0.51 and down activated. Available since version 0.53.register_cmdb_top_scopeβ Will register all cmdb top scope variables automatically in the templates. Available since version 0.53.0.51β Will loadRex::Constantsand the CMDB by default. And all things 0.47 and down activated. Available since version 0.51.disable_taskname_warningβ Disable warning about invalid task names (they should match/^[a-zA-Z_][a-zA-Z0-9_]*$/). Available since version 0.47.verbose_runβ Explicitly outputSuccessfully executedorError executingmessages forrun()commands. Available since version 0.47.no_cacheβ Disable caching (like discovery results of remote OS, hardware, shell, etc.). Available since version 0.46.no_path_cleanupβ Controls whether Rex should use the default or explicitly configuredPATHsettings when executing commands or not. See also thepathcommand and theset_pathconfiguration option. Available since version 0.44.source_profileβ Source$HOME/.profilebefore running a command. Available since version 0.44.source_global_profileβ Source/etc/profilebefore running a command. Available since version 0.44.exec_autodieβ If you execute a command withrun()Rex willdie()if the command returns aRETVAL != 0. Available since version 0.44.exec_and_sleepβ Sometimes some commands that fork away didn't keep running. With this flag rex will wait a few ms before exiting the shell. Available since version 0.43.disable_strict_host_key_checkingβ Disabling strict host key checking for openssh connection mode. Available since version 0.43.reportingβ Enable reporting. Available since version 0.43.empty_groupsβ Enable usage of empty groups. Available since version 0.42.use_server_authβ Enable the usage of special authentication options for servers. Available since version 0.42.no_ttyβ Disable pty usage for ssh connections. Available since version 0.41.no_local_template_varsβ Use global variables in templates. Available since version 0.40.sudo_without_shβ Run sudo commands directly without the use ofsh. This might break things. Available since version 0.40. πsudo_without_localesβ Run sudo commands without locales. This will break things if you don't use English locales. Available since version 0.40.exit_statusβ This option tells Rex to return a non zero value on exit if a task fails. Available since version 0.39.0.35β This option enables the features of 0.31 and the possibility to call tasks as a functions without the need to use a hash reference for the parameters. Available since version 0.35.0.31β To enable special authentication options for a server group. This will overwrite the default authentication options for a task. Available since version 0.31.
π§ CONTRIBUTORS π§
Many thanks to the contributors for their work β genuinely obsessed with them, they ate and left no crumbs. π Please see the CONTRIBUTORS file for a complete list: https://metacpan.org/release/Rex/source/CONTRIBUTORS
π LICENSE π
Rex is a free software, licensed under: The Apache License, Version 2.0, January 2004
Aaand that's the whole page, bestie! π This one wasperl v5.40.1, dated2025-10-03, and it lives in yourRex(3pm)β now go automate something gorgeous. πβ¨π
π¦ 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