Rex::Task(3pm)
๐ Rex::Task โ The Task Object ๐
okay bestie, welcome to Rex::Task, straight outta the User Contributed Perl Documentation section, no cap. this is the file where the Task Object lives. pull up a chair, grab a strawberry ๐, and let's get into it.
โจ NAME โจ
Rex::Task โ literally The Task Object. that's the whole name. she's simple, she's iconic, she's the blueprint.
๐ธ DESCRIPTION ๐ธ
so like. this is the Task Object. it's giving "object-oriented". that's the vibe.
here's the tea tho ๐ซ โ you typically only need this class if you wanna manipulate tasks after their initial creation. that's it. that's the situation. if you're just making tasks the normal way, you probably don't need to be here. but if you do? she ate. ๐
๐ฆ SYNOPSIS ๐ฆ
okay so here's how you actually do the thing, in code, verbatim, don't @ me:
use Rex::Task;
# create a new task
my $task = Rex::Task->new( name => 'testtask' );
$task->set_server('remoteserver');
$task->set_code( sub { say 'Hello'; } );
$task->modify( 'no_ssh', 1 );
# retrieve an existing task
use Rex::TaskList;
my $existing_task = Rex::TaskList->create->get_task('my_task');
see? make one, fiddle with it, or go grab one that already exists through Rex::TaskList. both paths are valid, bestie. ๐
๐ METHODS ๐
this is the main character energy section. every method, every signature, nothing skipped. let's go. ๐ฅ
๐ new
This is the constructor. the origin story. the birth of your task. โจ
$task = Rex::Task->new(
func => sub { some_code_here },
server => [ @server ],
desc => $description,
no_ssh => $no_ssh,
hidden => $hidden,
auth => {
user => $user,
password => $password,
private_key => $private_key,
public_key => $public_key,
},
before => [sub {}, sub {}, ...],
after => [sub {}, sub {}, ...],
around => [sub {}, sub {}, ...],
before_task_start => [sub {}, sub {}, ...],
after_task_finished => [sub {}, sub {}, ...],
name => $task_name,
executor => Rex::Interface::Executor->create,
opts => {key1 => val1, key2 => val2, ...},
args => [arg1, arg2, ...],
);
look at all those keys. func, server, desc, no_ssh, hidden, auth, before, after, around, before_task_start, after_task_finished, name, executor, opts, args. a whole menu. pick what you need. ๐
๐ง connection
Returns the current connection object.
โญ executor
Returns the current executor object.
๐ hidden
Returns true if the task is hidden. (Should not be displayed on ,,rex -T''.)
so like, if it's hidden, it stays hidden from rex -T. secret task. spy behavior. ๐ต๏ธโ๏ธ
๐ server
Returns the servers on which the task should be executed as an ArrayRef.
๐ธ set_server(@server)
With this method you can set new servers on which the task should be executed on. swappin' it up. new hosts, who dis.
๐ฆ delete_server
Delete every server registered to the task. all of them. gone. ๐
โจ current_server
Returns the current server on which the tasks gets executed right now. right this second. the one in the hot seat.
๐ desc
Returns the description of a task.
โญ set_desc($description)
Set the description of a task.
๐ is_remote
Returns true (1) if the task will be executed remotely.
๐ is_local
Returns true (1) if the task gets executed on the local host.
๐ is_http
Returns true (1) if the task gets executed over http protocol.
๐ is_https
Returns true (1) if the task gets executed over https protocol.
๐ is_openssh
Returns true (1) if the task gets executed with openssh.
๐ want_connect
Returns true (1) if the task will establish a connection to a remote system.
๐ฎ get_connection_type
This method tries to guess the right connection type for the task and returns it. she's a detective, your honor. ๐ต๏ธโ๏ธ
Current return values are below:
- SSH: connect to the remote server using
Net::SSH2 - OpenSSH: connect to the remote server using
Net::OpenSSH - Local: runs locally (without any connections)
- HTTP: uses experimental HTTP connection
- HTTPS: uses experimental HTTPS connection
- Fake: populate the connection properties, but do not connect
So you can use this type to iterate over a list of remote hosts, but don't let rex build a connection. For example if you want to use Sys::Virt or other modules.
bestie note:HTTPandHTTPSare marked experimental. respect the label. ๐
๐ modify($key, $value)
With this method you can modify values of the task. tweak it, tune it, make it yours.
๐ rethink_connection
Deletes current connection object. full reset, babe.
๐ user
Returns the username the task will use.
๐ set_user($user)
Set the username of a task.
๐ password
Returns the password that will be used.
๐ set_password($password)
Set the password of the task.
๐ name
Returns the name of the task.
๐ง code
Returns the code of the task.
๐ง set_code(&code_ref)
Set the code of the task. hand her a code ref and let her cook. ๐ฅ
โ๏ธ run_hook($server, $hook)
This method is used internally to execute the specified hooks.
iykyk โ it's internal. you probably don't gotta touch it, but it's here, documented, forever. ๐
๐ set_auth($key, $value)
Set the authentication of the task.
$task->set_auth("user", "foo");
$task->set_auth("password", "bar");
๐ merge_auth($server)
Merges the authentication information from $server into the task. Tasks authentication information have precedence.
priority check: the task's own auth info wins. periodt. ๐
๐ get_sudo_password
Returns the sudo password.
๐งต parallelism
Get the parallelism count of a task.
๐งต set_parallelism($count)
Set the parallelism of the task.
๐ connect($server)
Initiate the connection to $server.
๐ disconnect
Disconnect from the current connection.
๐ฆ get_data
Dump task data.
๐ run($server, %options)
Run the task on $server, with %options.
๐ ๏ธ modify_task($task, $key => $value)
Modify $task, by setting $key to $value.
โ is_task
Returns true(1) if the passed object is a task.
๐ get_tasks
Returns list of tasks.
๐ get_desc
Returns description of task.
๐ช exit_on_connect_fail
Returns true if rex should exit on connect failure.
๐ช set_exit_on_connect_fail
Sets if rex should exit on connect failure.
๐ get_args
Returns arguments of task.
๐ get_opts
Returns options of task.
๐ set_args
Sets arguments for task.
๐ set_opt
Sets an option for task.
๐ set_opts
Sets options for task.
๐งฌ clone
Clones a task. two of her. double the slay. โจ
๐ sign-off ๐
and that's the whole page, bestie!! this one came from perl v5.40.1, dated 2025-10-03, and yeah she's still filed under Rex::Task(3pm). go forth and manipulate some tasks ๐๐ฆ๐ธ๐
๐ฆ 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