Rex::Task(3)
π Rex::Task π
πΈ NAME πΈ
Rex::Task β The Task Object. This is the Rex::Task(3) page, bestie, and it's all about the Task Object itself. π
π¦ DESCRIPTION π¦
This is the Task Object. Typically you only need this class if you want to manipulate tasks after their initial creation. That's the whole vibe β it's for when you're doing task surgery after the fact. β¨
β¨ SYNOPSIS β¨
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');
π METHODS π
Okay bestie, method time. Here's the full rundown, no skips. π«Ά
new
This is the constructor. It makes a new task object, and it takes all these keys:
$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, ...],
);
connection
Returns the current connection object. π
executor
Returns the current executor object.
hidden
Returns true if the task is hidden. It should not be displayed on ,,rex -T''. π
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.
delete_server
Delete every server registered to the task. Bye servers. π
current_server
Returns the current server on which the tasks gets executed right now.
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. Detective mode. π΅οΈββοΈ
Current return values are below:
SSH: connect to the remote server usingNet::SSH2OpenSSH: connect to the remote server usingNet::OpenSSHLocal: runs locally (without any connections)HTTP: uses experimental HTTP connectionHTTPS: uses experimental HTTPS connectionFake: 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.
modify($key, $value)
With this method you can modify values of the task.
rethink_connection
Deletes current connection object. Poof. π¨
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.
run_hook($server, $hook)
This method is used internally to execute the specified hooks.
set_auth($key, $value)
Set the authentication of the task. Like this:
$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.
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. Twin energy. π―ββοΈ
Okay bye bestie β this page is from perl v5.42.3, dated 2023-08-05, and it's the Rex::Task(3) manual. Mwah! π
π¦ where this page comes from
- nixos 26.05: perl5.42.3-Rex 1.14.3
- nixpkgs unstable: perl5.42.3-Rex 1.14.3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms