1Rex::Task(3) User Contributed Perl Documentation Rex::Task(3)
2
3
4
6 Rex::Task - The Task Object
7
9 The Task Object. Typically you only need this class if you want to
10 manipulate tasks after their initial creation.
11
13 use Rex::Task;
14
15 # create a new task
16 my $task = Rex::Task->new(name => "testtask");
17 $task->set_server("remoteserver");
18 $task->set_code(sub { say "Hello"; });
19 $task->modify("no_ssh", 1);
20
21 # retrieve an existing task
22 use Rex::TaskList;
23
24 my $existing_task = Rex::TaskList->get_task('my_task');
25
27 new
28 This is the constructor.
29
30 $task = Rex::Task->new(
31 func => sub { some_code_here },
32 server => [ @server ],
33 desc => $description,
34 no_ssh => $no_ssh,
35 hidden => $hidden,
36 auth => {
37 user => $user,
38 password => $password,
39 private_key => $private_key,
40 public_key => $public_key,
41 },
42 before => [sub {}, sub {}, ...],
43 after => [sub {}, sub {}, ...],
44 around => [sub {}, sub {}, ...],
45 before_task_start => [sub {}, sub {}, ...],
46 after_task_finished => [sub {}, sub {}, ...],
47 name => $task_name,
48 executor => Rex::Interface::Executor->create,
49 opts => {key1 => val1, key2 => val2, ...},
50 args => [arg1, arg2, ...],
51 );
52
53 connection
54 Returns the current connection object.
55
56 executor
57 Returns the current executor object.
58
59 hidden
60 Returns true if the task is hidden. (Should not be displayed on ,,rex
61 -T''.)
62
63 server
64 Returns the servers on which the task should be executed as an
65 ArrayRef.
66
67 set_server(@server)
68 With this method you can set new servers on which the task should be
69 executed on.
70
71 delete_server
72 Delete every server registered to the task.
73
74 current_server
75 Returns the current server on which the tasks gets executed right now.
76
77 desc
78 Returns the description of a task.
79
80 set_desc($description)
81 Set the description of a task.
82
83 is_remote
84 Returns true (1) if the task will be executed remotely.
85
86 is_local
87 Returns true (1) if the task gets executed on the local host.
88
89 is_http
90 Returns true (1) if the task gets executed over http protocol.
91
92 is_https
93 Returns true (1) if the task gets executed over https protocol.
94
95 is_openssh
96 Returns true (1) if the task gets executed with openssh.
97
98 want_connect
99 Returns true (1) if the task will establish a connection to a remote
100 system.
101
102 get_connection_type
103 This method tries to guess the right connection type for the task and
104 returns it.
105
106 Current return values are below:
107
108 · SSH: connect to the remote server using Net::SSH2
109
110 · OpenSSH: connect to the remote server using Net::OpenSSH
111
112 · Local: runs locally (without any connections)
113
114 · HTTP: uses experimental HTTP connection
115
116 · HTTPS: uses experimental HTTPS connection
117
118 · Fake: populate the connection properties, but do not connect
119
120 So you can use this type to iterate over a list of remote hosts,
121 but don't let rex build a connection. For example if you want to
122 use Sys::Virt or other modules.
123
124 modify($key, $value)
125 With this method you can modify values of the task.
126
127 rethink_connection
128 Deletes current connection object.
129
130 user
131 Returns the username the task will use.
132
133 set_user($user)
134 Set the username of a task.
135
136 password
137 Returns the password that will be used.
138
139 set_password($password)
140 Set the password of the task.
141
142 name
143 Returns the name of the task.
144
145 code
146 Returns the code of the task.
147
148 set_code(\&code_ref)
149 Set the code of the task.
150
151 run_hook($server, $hook)
152 This method is used internally to execute the specified hooks.
153
154 set_auth($key, $value)
155 Set the authentication of the task.
156
157 $task->set_auth("user", "foo");
158 $task->set_auth("password", "bar");
159
160 merge_auth($server)
161 Merges the authentication information from $server into the task.
162 Tasks authentication information have precedence.
163
164 get_sudo_password
165 Returns the sudo password.
166
167 parallelism
168 Get the parallelism count of a task.
169
170 set_parallelism($count)
171 Set the parallelism of the task.
172
173 connect($server)
174 Initiate the connection to $server.
175
176 disconnect
177 Disconnect from the current connection.
178
179 get_data
180 Dump task data.
181
182 run($server, %options)
183 Run the task on $server, with %options.
184
185 modify_task($task, $key => $value)
186 Modify $task, by setting $key to $value.
187
188 is_task
189 Returns true(1) if the passed object is a task.
190
191 get_tasks
192 Returns list of tasks.
193
194 get_desc
195 Returns description of task.
196
197 exit_on_connect_fail
198 Returns true if rex should exit on connect failure.
199
200 set_exit_on_connect_fail
201 Sets if rex should exit on connect failure.
202
203 get_args
204 Returns arguments of task.
205
206 get_opts
207 Returns options of task.
208
209 set_args
210 Sets arguments for task.
211
212 set_opt
213 Sets an option for task.
214
215 set_opts
216 Sets options for task.
217
218 clone
219 Clones a task.
220
221
222
223perl v5.32.1 2021-03-06 Rex::Task(3)