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: HTTP and HTTPS are 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