blib/lib/Rex.pm

filter: Statementstmt 61.5% 277 / 450 Branchbran 55.8% 95 / 170 Conditioncond 60.7% 48 / 79 MC/DCmcdc 31.2% 15 / 48 Subroutinesub 80.9% 34 / 42 Podpod 27.2% 6 / 22 totaltotal 58.5% 475 / 811 CC 119 SCAR 52.6
CC
119
Cov
60%
import
411.5
connect
42.0
deprecated
20.0
CRAP 192.3
« lib/Rex/User/FreeBSD.pm ↑ Summary lib/Rex/Commands/Cron.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 =encoding UTF-8
6  
7 =head1 NAME
8  
9 Rex - the friendly automation framework
10  
11 =head1 DESCRIPTION
12  
13 Rex is an automation framework that is friendly to any combinations of local
14 and remote execution, push and pull style of management, or imperative and
15 declarative approach.
16  
17 Its flexibility makes it a great fit for many different use cases, but most
18 commonly Rex is used to automate application deployment and data center
19 infrastructure management tasks.
20  
21 See L<Rex::Commands> for a starting point of available built-in commands.
22  
23 See L<rex|https://metacpan.org/pod/distribution/Rex/bin/rex> for more information about how to use rex on the command line.
24  
25 =head1 SYNOPSIS
26  
27 # In a Rexfile:
28 use Rex -feature => [qw/1.4/];
29  
30 user "root";
31 password "ch4ngem3";
32  
33 desc "Show system information";
34 task "sysinfo", sub {
35 say run "uname -a";
36 };
37  
38 1;
39  
40 # On the command line:
41 $ rex -H server[01..10] sysinfo
42  
43 =head1 CLASS METHODS
44  
45 =cut
46  
47 package Rex;
48  
49 105 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 105 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 105 our $VERSION = '1.16.1'; # VERSION
53  
54 105 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
55 105 ▶ use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 105 ▶ use Rex::Interface::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 105 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 105 ▶ use Rex::Interface::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 105 ▶ use Cwd qw(getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
60 105 ▶ use Rex::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 105 ▶ use Rex::Helper::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 105 ▶ use Rex::Report;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 105 ▶ use Rex::Notify;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 105 ▶ use Rex::Require;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 105 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 105 ▶ use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 105 eval { Net::SSH2->require; };
68 }
69  
70 105 our ( @EXPORT, @CONNECTION_STACK, $GLOBAL_SUDO, $MODULE_PATHS,
71 $WITH_EXIT_STATUS, @FEATURE_FLAGS );
72  
73 105 $WITH_EXIT_STATUS = 1; # since 0.50 activated by default
74 105 @FEATURE_FLAGS = ();
75  
76 105 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.2
77  
78 113 ▶ sub generate_inc {
Subroutine generate_inc: called CC=3 SCAR=11.0
Pod undocumented
79 113 my @additional = @_;
80  
81 113 my @rex_inc = ();
82  
83 # this must be the first, special handling for rex modules which uses Module.pm and not
84 # __module__.pm as their initial file. (rex pre 0.40 or something)
85 10134 ▶ push @rex_inc, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
86 10134 my $mod_to_load = $_[1];
87 10134 return search_module_path( $mod_to_load, 1 );
88 113 };
89  
90 # this adds the current directory to the lib search path.
91 # this must come before all other paths, because custom libraries can be project dependant
92 # see: #1108
93 113 push @rex_inc, add_cwd_to_inc();
94 113 push @rex_inc, add_libstruct_to_inc($_) for @additional;
95  
96 # we have to add the Rexfile's path to @INC FIX: #1170
97 113 push @rex_inc, @additional;
98  
99 # add home directory/.rex/recipes to the search path, so that recipes can be managed
100 # at a central location.
101 113 my $home_dir = _home_dir();
102 113 ▶ if ( -d "$home_dir/.rex/recipes" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "$home_dir/.rex/recipes") 0 113 113
103 0 push( @INC, "$home_dir/.rex/recipes" );
104 }
105  
106 # add the default search locations
107 113 push @rex_inc, @INC;
108  
109 # this must be the last entry, special handling to load rex modules.
110 push(
111 @rex_inc,
112 392 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
113 392 my $mod_to_load = $_[1];
114 392 return search_module_path( $mod_to_load, 0 );
115 }
116 113 );
117  
118 113 return @rex_inc;
119 }
120  
121 121 ▶ sub add_libstruct_to_inc {
Subroutine add_libstruct_to_inc: called CC=5 SCAR=19.0
Pod undocumented
122 121 my ($path) = @_;
123 121 my @ret = ();
124  
125 121 ▶ if ( -d File::Spec->catdir( $path, "lib" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "File::Spec"->catdir($path, "lib")) 113 8 121
126 113 push( @ret, File::Spec->catdir( $path, "lib" ) );
127 113 push( @ret, File::Spec->catdir( $path, "lib", "perl", "lib", "perl5" ) );
128 113 ▶ if ( $^O eq "linux" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "linux") 113 0 113
129 113 push(
130 @ret,
131 File::Spec->catdir(
132 $path, "lib", "perl", "lib", "perl5", "x86_64-linux"
133 )
134 );
135 }
136 113 ▶ if ( $^O =~ m/^MSWin/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /^MSWin/u) 0 113 113
137 0 my ($special_win_path) = grep { m/\/MSWin32\-/ } @INC;
138 0 ▶ if ( defined $special_win_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $special_win_path) 0 0 0
139 0 my $mswin32_path = basename $special_win_path;
140 0 push(
141 @ret,
142 File::Spec->catdir(
143 $path, "lib", "perl", "lib", "perl5", $mswin32_path
144 )
145 );
146 }
147 }
148 }
149  
150 121 return @ret;
151 }
152  
153 113 ▶ sub add_cwd_to_inc {
Subroutine add_cwd_to_inc: called CC=1 SCAR=0.0
Pod undocumented
154 113 my $path = getcwd;
155 113 return add_libstruct_to_inc($path);
156 }
157  
158 113 ▶ sub _home_dir {
Subroutine _home_dir: called CC=3 SCAR=13.1
159 113 ▶ if ( $^O =~ m/^MSWin/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /^MSWin/u) 0 113 113
160 0 return $ENV{'USERPROFILE'};
161 }
162  
163 113 ▶ return $ENV{'HOME'} || "";
Condition50%1/2
$ENV{'HOME'} || ''
l!l
1130
MC/DC0%0/1
$ENV{'HOME'} || ''
$ENV{'HOME'}
Truth table50%1/2
A
A= $ENV{'HOME'}
Aresult
11
00
164 }
165  
166 105 my @new_inc = generate_inc();
167 105 @INC = @new_inc;
168  
169 }
170  
171 105 ▶my $home = $ENV{'HOME'} || "/tmp";
Condition50%1/2
$ENV{'HOME'} || '/tmp'
l!l
1050
MC/DC0%0/1
$ENV{'HOME'} || '/tmp'
$ENV{'HOME'}
Truth table50%1/2
A
A= $ENV{'HOME'}
Aresult
11
00
172 105 ▶if ( $^O =~ m/^MSWin/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /^MSWin/u) 0 105 105
173 0 $home = $ENV{'USERPROFILE'};
174 }
175  
176 105 push( @INC, "$home/.rex/recipes" );
177  
178 10526 ▶sub search_module_path {
Subroutine search_module_path: called CC=9 SCAR=23.0
Pod undocumented
179 10526 my ( $mod_to_load, $pre ) = @_;
180  
181 10526 $mod_to_load =~ s/\.pm//g;
182  
183 10526 my @search_in;
184 10526 ▶ if ($pre) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre) { } 10134 392 10526
185 91658 @search_in = map { ("$_/$mod_to_load.pm") }
186 10134 grep { -d } @INC;
187  
188 }
189 else {
190 @search_in =
191 3537 map { ( "$_/$mod_to_load/__module__.pm", "$_/$mod_to_load/Module.pm" ) }
192 392 grep { -d } @INC;
193 }
194  
195 10526 for my $file (@search_in) {
196 47523 my $o = -f $file;
197 47523 my $fh_t;
198 47523 ▶ if ( $^O =~ m/^MSWin/i && !$o ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /^MSWin/iu and not $o) 0 47523 47523
Condition33%1/3
$^O =~ /^MSWin/iu and not $o
!ll&&!rl&&r
4752300
MC/DC0%0/2
$^O =~ /^MSWin/iu and not $o
$^O =~ /^MSWin/iu not $o
Truth table33%1/3
A and not(B)
A= $^O =~ /^MSWin/iuB= not $o
ABresult
0X0
100
111
199  
200 # this is a windows workaround for if(-f ) on symlinks
201 0 $o = open( my $fh_t, "<", $file );
202 }
203  
204 47523 ▶ if ($o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o) 9742 37781 47523
205 9742 ▶ close $fh_t if $fh_t;
Branch: 1 branch
BranchTrueFalseTotal
if $fh_t 0 9742 9742
206 9742 my ($path) = ( $file =~ m/^(.*)\/.+?$/ );
207 9742 ▶ if ( $path !~ m/\// ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ m[/]u) 0 9742 9742
208 0 $path = getcwd() . "/$path";
209 }
210  
211 # module found, register path
212 9742 $MODULE_PATHS->{$mod_to_load} = { path => $path };
213 9742 my $mod_package_name = $mod_to_load;
214 9742 $mod_package_name =~ s/\//::/g;
215 9742 $MODULE_PATHS->{$mod_package_name} = { path => $path };
216  
217 9742 ▶ if ($pre) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pre) 9742 0 9742
218 9742 return;
219 }
220  
221 0 open( my $fh, "<", $file );
222 0 return $fh;
223 }
224 }
225 }
226  
227 6 ▶sub get_module_path {
Subroutine get_module_path: called CC=2 SCAR=8.1
Pod undocumented
228 6 my ($module) = @_;
229 6 ▶ if ( exists $MODULE_PATHS->{$module} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Rex::MODULE_PATHS->{$module}) 0 6 6
230 0 return $MODULE_PATHS->{$module}->{path};
231 }
232 }
233  
234 105 ▶sub push_connection {
Subroutine push_connection: called CC=2 SCAR=6.9
Pod undocumented
235 105 ▶ if ( !ref $_[0]->{server} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_[0]{"server"}) 65 40 105
236 65 $_[0]->{server} = Rex::Group::Entry::Server->new( name => $_[0]->{server} );
237 }
238  
239 105 push @CONNECTION_STACK, $_[0];
240 105 return $_[0];
241 }
242  
243 32 ▶sub pop_connection {
Subroutine pop_connection: called CC=1 SCAR=0.0
Pod undocumented
244 32 pop @CONNECTION_STACK;
245 32 Rex::Logger::debug( "Connections in queue: " . scalar(@CONNECTION_STACK) );
246 }
247  
248 107 ▶sub reconnect_lost_connections {
Subroutine reconnect_lost_connections: called CC=3 SCAR=11.0
Pod undocumented
249 107 ▶ if ( @CONNECTION_STACK > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@Rex::CONNECTION_STACK > 0) 1 106 107
250 1 Rex::Logger::debug("Need to reinitialize connections.");
251 1 for (@CONNECTION_STACK) {
252 2 $_->{conn}->reconnect;
253 }
254 }
255 }
256  
257 # ... no words
258 105 my @__modif_caller;
259  
260 0 ▶sub unset_modified_caller {
Subroutine unset_modified_caller: not called CC=1 SCAR=6.9
Pod undocumented
261 0 @__modif_caller = ();
262 }
263  
264 0 ▶sub modified_caller {
Subroutine modified_caller: not called CC=2 SCAR=17.9
Pod undocumented
265 0 my (@caller) = @_;
266 0 ▶ if (@caller) {
Branch: 1 branch
BranchTrueFalseTotal
if (@caller) { } 0 0 0
267 0 @__modif_caller = @caller;
268 }
269 else {
270 0 return @__modif_caller;
271 }
272 }
273  
274 =head2 get_current_connection
275  
276 This function is deprecated since 0.28! See Rex::Commands::connection.
277  
278 Returns the current connection as a hashRef.
279  
280 =over 4
281  
282 =item server
283  
284 The server name
285  
286 =item ssh
287  
288 1 if it is a ssh connection, 0 if not.
289  
290 =back
291  
292 =cut
293  
294 7668 ▶sub get_current_connection {
Subroutine get_current_connection: called CC=2 SCAR=6.9
Pod documented
295  
296 # if no connection available, use local connect
297 7668 ▶ unless (@CONNECTION_STACK) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@Rex::CONNECTION_STACK) 65 7603 7668
298 65 my $conn = Rex::Interface::Connection->create("Local");
299  
300 65 Rex::push_connection(
301 {
302 conn => $conn,
303 ssh => $conn->get_connection_object,
304 cache => Rex::Interface::Cache->create(),
305 reporter => Rex::Report->create(),
306 notify => Rex::Notify->new(),
307 }
308 );
309 }
310  
311 7668 $CONNECTION_STACK[-1];
312 }
313  
314 0 ▶sub get_current_connection_object {
Subroutine get_current_connection_object: not called CC=1 SCAR=6.9
Pod undocumented
315 0 return Rex::get_current_connection()->{conn};
316 }
317  
318 =head2 is_ssh
319  
320 Returns 1 if the current connection is a ssh connection. 0 if not.
321  
322 =cut
323  
324 1263 ▶sub is_ssh {
Subroutine is_ssh: called CC=3 SCAR=11.3
Pod documented
325 1263 ▶ if ( $CONNECTION_STACK[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Rex::CONNECTION_STACK[-1]) 1257 6 1263
326 1257 my $ref = ref( $CONNECTION_STACK[-1]->{"conn"} );
327 1257 ▶ if ( $ref =~ m/SSH/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref =~ /SSH/u) 0 1257 1257
328 0 return $CONNECTION_STACK[-1]->{"conn"}->get_connection_object();
329 }
330 }
331  
332 1263 return 0;
333 }
334  
335 =head2 is_local
336  
337 Returns 1 if the current connection is local. Otherwise 0.
338  
339 =cut
340  
341 115 ▶sub is_local {
Subroutine is_local: called CC=3 SCAR=12.0
Pod documented
342 115 ▶ if ( $CONNECTION_STACK[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Rex::CONNECTION_STACK[-1]) 115 0 115
343 115 my $ref = ref( $CONNECTION_STACK[-1]->{"conn"} );
344 115 ▶ if ( $ref =~ m/Local/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref =~ /Local/u) 115 0 115
345 115 return $CONNECTION_STACK[-1]->{"conn"}->get_connection_object();
346 }
347 }
348  
349 0 return 0;
350 }
351  
352 =head2 is_sudo
353  
354 Returns 1 if the current operation is executed within sudo.
355  
356 =cut
357  
358 3797 ▶sub is_sudo {
Subroutine is_sudo: called CC=7 SCAR=27.0
Pod documented
359  
360 3797 ▶ if ( exists $CONNECTION_STACK[-1]->{server}->{auth}->{sudo}
Branch: 2 branches
BranchTrueFalseTotal
if (exists $Rex::CONNECTION_STACK[-1]{'server'}{'auth'}{'sudo'} and $Rex::CONNECTION_STACK[-1]{'server'}{'auth'}{'sudo'} == 1) { } 0 3797 3797
elsif (exists $Rex::CONNECTION_STACK[-1]{'server'}{'auth'}{'sudo'} and $Rex::CONNECTION_STACK[-1]{'server'}{'auth'}{'sudo'} == 0) { } 0 7594 7594
Condition33%1/3
exists $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} and $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} == 1
!ll&&!rl&&r
379700
MC/DC0%0/2
exists $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} and $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} == 1
exists $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} == 1
Truth table33%1/3
A and B
A= exists $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"}B= $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} == 1
ABresult
0X0
100
111
361 && $CONNECTION_STACK[-1]->{server}->{auth}->{sudo} == 1 )
362 {
363 0 return 1;
364 }
365 ▶ elsif ( exists $CONNECTION_STACK[-1]->{server}->{auth}->{sudo}
Condition33%1/3
exists $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} and $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} == 0
!ll&&!rl&&r
379700
MC/DC0%0/2
exists $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} and $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} == 0
exists $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} == 0
Truth table33%1/3
A and B
A= exists $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"}B= $Rex::CONNECTION_STACK[-1]{"server"}{"auth"}{"sudo"} == 0
ABresult
0X0
100
111
366 && $CONNECTION_STACK[-1]->{server}->{auth}->{sudo} == 0 )
367 {
368 0 return 0;
369 }
370  
371 0 ▶ if ($GLOBAL_SUDO) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($Rex::GLOBAL_SUDO) 0 3797 3797
372  
373 3797 ▶ if ( $CONNECTION_STACK[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Rex::CONNECTION_STACK[-1]) 3797 0 3797
374 3797 return $CONNECTION_STACK[-1]->{conn}->get_current_use_sudo;
375 }
376  
377 0 return 0;
378 }
379  
380 0 ▶sub global_sudo {
Subroutine global_sudo: not called CC=1 SCAR=6.9
Pod undocumented
381 0 my ($on) = @_;
382 0 $GLOBAL_SUDO = $on;
383  
384 # turn cache on
385 0 Rex::Config->set_use_cache(1);
386 }
387  
388 =head2 get_sftp
389  
390 Returns the sftp object for the current ssh connection.
391  
392 =cut
393  
394 0 ▶sub get_sftp {
Subroutine get_sftp: not called CC=2 SCAR=17.9
Pod documented
395 0 ▶ if ( $CONNECTION_STACK[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Rex::CONNECTION_STACK[-1]) 0 0 0
396 0 return $CONNECTION_STACK[-1]->{"conn"}->get_fs_connection_object();
397 }
398  
399 0 return 0;
400 }
401  
402 1962 ▶sub get_cache {
Subroutine get_cache: called CC=2 SCAR=6.9
Pod undocumented
403 1962 ▶ if ( $CONNECTION_STACK[-1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Rex::CONNECTION_STACK[-1]) 1952 10 1962
404 1952 return $CONNECTION_STACK[-1]->{"cache"};
405 }
406  
407 10 return Rex::Interface::Cache->create();
408 }
409  
410 =head2 connect
411  
412 Use this function to create a connection if you use Rex as a library.
413  
414 use Rex;
415 use Rex::Commands::Run;
416 use Rex::Commands::Fs;
417  
418 Rex::connect(
419 server => "remotehost",
420 user => "root",
421 password => "f00b4r",
422 private_key => "/path/to/private/key/file",
423 public_key => "/path/to/public/key/file",
424 );
425  
426 if(is_file("/foo/bar")) {
427 print "Do something...\n";
428 }
429  
430 my $output = run("uptime");
431  
432 =cut
433  
434 0 ▶sub connect {
Subroutine connect: not called CC=6 SCAR=37.4
Pod documented
435  
436 0 my ($param) = {@_};
437  
438 0 my $server = $param->{server};
439 0 ▶ my $port = $param->{port} || 22;
Condition0%0/2
$param->{'port'} || 22
l!l
00
MC/DC0%0/1
$param->{'port'} || 22
$param->{'port'}
Truth table0%0/2
A
A= $param->{'port'}
Aresult
11
00
440 0 ▶ my $timeout = $param->{timeout} || 5;
Condition0%0/2
$param->{'timeout'} || 5
l!l
00
MC/DC0%0/1
$param->{'timeout'} || 5
$param->{'timeout'}
Truth table0%0/2
A
A= $param->{'timeout'}
Aresult
11
00
441 0 my $user = $param->{"user"};
442 0 my $pass = $param->{"password"};
443 0 my $cached_conn = $param->{"cached_connection"};
444  
445 0 ▶ if ( !$cached_conn ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $cached_conn) { } 0 0 0
446 0 my $conn =
447 Rex::Interface::Connection->create(Rex::Config::get_connection_type);
448  
449 $conn->connect(
450 user => $user,
451 password => $pass,
452 server => $server,
453 port => $port,
454 timeout => $timeout,
455 0 %{$param},
456 );
457  
458 0 ▶ unless ( $conn->is_connected ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conn->is_connected) 0 0 0
459 0 die("Connection error or refused.");
460 }
461  
462 # push a remote connection
463 0 my $rex_conn = Rex::push_connection(
464 {
465 conn => $conn,
466 ssh => $conn->get_connection_object,
467 server => $server,
468 cache => Rex::Interface::Cache->create(),
469 reporter => Rex::Report->create( Rex::Config->get_report_type ),
470 notify => Rex::Notify->new(),
471 }
472 );
473  
474 # auth unsuccessfull
475 0 ▶ unless ( $conn->is_authenticated ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conn->is_authenticated) 0 0 0
476 0 Rex::Logger::info( "Wrong username or password. Or wrong key.", "warn" );
477  
478 # after jobs
479  
480 0 die("Wrong username or password. Or wrong key.");
481 }
482  
483 0 return $rex_conn;
484 }
485 else {
486 0 Rex::push_connection($cached_conn);
487 0 return $cached_conn;
488 }
489  
490 }
491  
492 0 ▶sub deprecated {
Subroutine deprecated: not called CC=4 SCAR=30.0
Pod undocumented
493 0 my ( $func, $version, @msg ) = @_;
494  
495 0 ▶ if ($func) {
Branch: 1 branch
BranchTrueFalseTotal
if ($func) 0 0 0
496 0 Rex::Logger::info("The call to $func is deprecated.");
497 }
498  
499 0 ▶ if (@msg) {
Branch: 1 branch
BranchTrueFalseTotal
if (@msg) 0 0 0
500 0 for (@msg) {
501 0 Rex::Logger::info($_);
502 }
503 }
504  
505 0 Rex::Logger::info("");
506  
507 0 Rex::Logger::info(
508 "Please rewrite your code. This function will disappear in (R)?ex version $version."
509 );
510 0 Rex::Logger::info(
511 "If you need assistance, get in touch via one of our support channels!");
512  
513 }
514  
515 1 ▶sub has_feature_version {
Subroutine has_feature_version: called CC=3 SCAR=15.1
Pod undocumented
516 1 my ($version) = @_;
517  
518 0 my @version_flags = grep { m/^\d+\./ } @FEATURE_FLAGS;
519 1 for my $v (@version_flags) {
520 0 ▶ if ( $version <= $v ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version <= $v) 0 0 0
521 0 return 1;
522 }
523 }
524  
525 1 return 0;
526 }
527  
528 0 ▶sub has_feature_version_lower {
Subroutine has_feature_version_lower: not called CC=3 SCAR=24.8
Pod undocumented
529 0 my ($version) = @_;
530  
531 0 my @version_flags = grep { m/^\d+\./ } @FEATURE_FLAGS;
532 0 for my $v (@version_flags) {
533 0 ▶ if ( $version > $v ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version > $v) 0 0 0
534 0 return 1;
535 }
536 }
537  
538 0 return 0;
539 }
540  
541 703 ▶sub import {
Subroutine import: called CC=73 SCAR=60.2
542 703 my ( $class, $what, $addition1 ) = @_;
543  
544 703 srand();
545  
546 703 ▶ if ( $addition1 && ref $addition1 eq "ARRAY" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($addition1 and ref $addition1 eq 'ARRAY') { } 0 703 703
elsif ($addition1) { } 4 699 703
Condition66%2/3
$addition1 and ref $addition1 eq "ARRAY"
!ll&&!rl&&r
69940
MC/DC0%0/2
$addition1 and ref $addition1 eq "ARRAY"
$addition1 ref $addition1 eq "ARRAY"
Truth table66%2/3
A and B
A= $addition1B= ref $addition1 eq "ARRAY"
ABresult
0X0
100
111
547 0 push @FEATURE_FLAGS, $what, @{$addition1};
548 }
549 elsif ($addition1) {
550 4 push @FEATURE_FLAGS, $what, $addition1;
551 }
552  
553 703 ▶ $what ||= "";
Condition100%2/2
$what ||= ""
l!l
84619
MC/DC100%1/1
$what ||= ""
$what
Truth table100%2/2
A
A= $what
Aresult
11
00
554  
555 703 my ( $register_to, $file, $line ) = caller;
556  
557 # use Net::OpenSSH if present (default without feature flag)
558 703 Rex::Config->set_use_net_openssh_if_present(1);
559  
560 703 ▶ if ( $what eq "-minimal" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "-minimal") 36 667 703
561 36 require Rex::Commands;
562 36 Rex::Commands->import( register_in => $register_to );
563  
564 36 require Rex::Helper::Rexfile::ParamLookup;
565 36 Rex::Helper::Rexfile::ParamLookup->import( register_in => $register_to );
566 }
567  
568 703 ▶ if ( $what eq "-base" || $what eq "base" || $what eq "-feature" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "-base" or $what eq "base" or $what eq "-feature") 48 655 703
Condition83%5/6
$what eq "-base" or $what eq "base" or $what eq "-feature"
l!l&&r!l&&!r
444655
$what eq "-base" or $what eq "base"
l!l&&r!l&&!r
440659
MC/DC66%2/3
$what eq "-base" or $what eq "base" or $what eq "-feature"
$what eq "-base" $what eq "base" $what eq "-feature"
Truth table75%3/4
A or B or C
A= $what eq "-base"B= $what eq "base"C= $what eq "-feature"
ABCresult
1XX1
01X1
0011
0000
569 48 require Rex::Commands;
570 48 Rex::Commands->import( register_in => $register_to );
571  
572 48 require Rex::Commands::Run;
573 48 Rex::Commands::Run->import( register_in => $register_to );
574  
575 48 require Rex::Commands::Fs;
576 48 Rex::Commands::Fs->import( register_in => $register_to );
577  
578 48 require Rex::Commands::File;
579 48 Rex::Commands::File->import( register_in => $register_to );
580  
581 48 require Rex::Commands::Cron;
582 48 Rex::Commands::Cron->import( register_in => $register_to );
583  
584 48 require Rex::Commands::Host;
585 48 Rex::Commands::Host->import( register_in => $register_to );
586  
587 48 require Rex::Commands::Download;
588 48 Rex::Commands::Download->import( register_in => $register_to );
589  
590 48 require Rex::Commands::Upload;
591 48 Rex::Commands::Upload->import( register_in => $register_to );
592  
593 48 require Rex::Commands::Gather;
594 48 Rex::Commands::Gather->import( register_in => $register_to );
595  
596 48 require Rex::Commands::Kernel;
597 48 Rex::Commands::Kernel->import( register_in => $register_to );
598  
599 48 require Rex::Commands::Pkg;
600 48 Rex::Commands::Pkg->import( register_in => $register_to );
601  
602 48 require Rex::Commands::Service;
603 48 Rex::Commands::Service->import( register_in => $register_to );
604  
605 48 require Rex::Commands::Sysctl;
606 48 Rex::Commands::Sysctl->import( register_in => $register_to );
607  
608 48 require Rex::Commands::Tail;
609 48 Rex::Commands::Tail->import( register_in => $register_to );
610  
611 48 require Rex::Commands::Process;
612 48 Rex::Commands::Process->import( register_in => $register_to );
613  
614 48 require Rex::Commands::Sync;
615 48 Rex::Commands::Sync->import( register_in => $register_to );
616  
617 48 require Rex::Commands::Notify;
618 48 Rex::Commands::Notify->import( register_in => $register_to );
619  
620 48 require Rex::Commands::User;
621 48 Rex::Commands::User->import( register_in => $register_to );
622  
623 48 require Rex::Helper::Rexfile::ParamLookup;
624 48 Rex::Helper::Rexfile::ParamLookup->import( register_in => $register_to );
625  
626 48 require Rex::Resource::firewall;
627 48 Rex::Resource::firewall->import( register_in => $register_to );
628 }
629  
630 703 ▶ if ( $what eq "-feature" || $what eq "feature" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($what eq "-feature" or $what eq "feature") 4 699 703
Condition66%2/3
$what eq "-feature" or $what eq "feature"
l!l&&r!l&&!r
40699
MC/DC50%1/2
$what eq "-feature" or $what eq "feature"
$what eq "-feature" $what eq "feature"
Truth table66%2/3
A or B
A= $what eq "-feature"B= $what eq "feature"
ABresult
1X1
011
000
631  
632 4 ▶ if ( !ref($addition1) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $addition1) 4 0 4
633 4 $addition1 = [$addition1];
634 }
635 4 for my $add ( @{$addition1} ) {
636  
637 4 my $found_feature = 0;
638  
639 4 ▶ if ( $add =~ m/^(\d+\.\d+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^(\d+\.\d+)$/u) 3 1 4
640 3 my $vers = $1;
641 3 my ( $major, $minor, $patch, $dev_release ) =
642 $Rex::VERSION =~ m/^(\d+)\.(\d+)\.(\d+)[_.]?(\d+)?$/;
643  
644 3 my ( $c_major, $c_minor ) = split( /\./, $vers );
645  
646 3 ▶ if ( defined $dev_release && $c_major == $major && $c_minor > $minor ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $dev_release and $c_major == $major and $c_minor > $minor) { } 0 3 3
elsif ($c_major > $major or $c_major >= $major and $c_minor > $minor) { } 0 6 6
Condition33%2/6
defined $dev_release and $c_major == $major and $c_minor > $minor
!ll&&!rl&&r
300
defined $dev_release and $c_major == $major
!ll&&!rl&&r
300
MC/DC0%0/3
defined $dev_release and $c_major == $major and $c_minor > $minor
defined $dev_release $c_major == $major $c_minor > $minor
Truth table25%1/4
A and B and C
A= defined $dev_releaseB= $c_major == $majorC= $c_minor > $minor
ABCresult
0XX0
10X0
1100
1111
647 0 Rex::Logger::info(
648 "This is development release $Rex::VERSION of Rex. Enabling experimental feature flag for $vers.",
649 "warn"
650 );
651 }
652 ▶ elsif ( ( $c_major > $major )
Condition33%2/6
$c_major > $major or $c_major >= $major and $c_minor > $minor
l!l&&r!l&&!r
003
$c_major >= $major and $c_minor > $minor
!ll&&!rl&&r
300
MC/DC0%0/3
$c_major > $major or $c_major >= $major and $c_minor > $minor
$c_major > $major $c_major >= $major $c_minor > $minor
Truth table25%1/4
A or B and C
A= $c_major > $majorB= $c_major >= $majorC= $c_minor > $minor
ABCresult
1XX1
0111
00X0
0100
653 || ( $c_major >= $major && $c_minor > $minor ) )
654 {
655 0 Rex::Logger::info(
656 "This Rexfile tries to enable features that are not supported with your version. Please update.",
657 "error"
658 );
659 0 exit 1;
660 }
661 }
662  
663 4 ▶ if ( $add =~ m/^\d+\.\d+$/ && $add >= 1.4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^\d+\.\d+$/u and $add >= "1.4") 0 4 4
Condition66%2/3
$add =~ /^\d+\.\d+$/u and $add >= "1.4"
!ll&&!rl&&r
130
MC/DC0%0/2
$add =~ /^\d+\.\d+$/u and $add >= "1.4"
$add =~ /^\d+\.\d+$/u $add >= "1.4"
Truth table66%2/3
A and B
A= $add =~ /^\d+\.\d+$/uB= $add >= "1.4"
ABresult
0X0
100
111
664 0 Rex::Logger::debug("Enabling task_chaining_cmdline_args feature");
665 0 Rex::Config->set_task_chaining_cmdline_args(1);
666 0 $found_feature = 1;
667 }
668  
669 4 ▶ if ( $add =~ m/^\d+\.\d+$/ && $add >= 1.3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^\d+\.\d+$/u and $add >= "1.3") 0 4 4
Condition66%2/3
$add =~ /^\d+\.\d+$/u and $add >= "1.3"
!ll&&!rl&&r
130
MC/DC0%0/2
$add =~ /^\d+\.\d+$/u and $add >= "1.3"
$add =~ /^\d+\.\d+$/u $add >= "1.3"
Truth table66%2/3
A and B
A= $add =~ /^\d+\.\d+$/uB= $add >= "1.3"
ABresult
0X0
100
111
670 0 Rex::Logger::debug("Activating new template engine.");
671 0 Rex::Config->set_use_template_ng(1);
672 0 $found_feature = 1;
673 }
674  
675 4 ▶ if ( $add =~ m/^\d+\.\d+$/ && $add >= 1.0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^\d+\.\d+$/u and $add >= 1) 0 4 4
Condition66%2/3
$add =~ /^\d+\.\d+$/u and $add >= 1
!ll&&!rl&&r
130
MC/DC0%0/2
$add =~ /^\d+\.\d+$/u and $add >= 1
$add =~ /^\d+\.\d+$/u $add >= 1
Truth table66%2/3
A and B
A= $add =~ /^\d+\.\d+$/uB= $add >= 1
ABresult
0X0
100
111
676 0 Rex::Logger::debug("Disabling usage of a tty");
677 0 Rex::Config->set_no_tty(1);
678 0 $found_feature = 1;
679 }
680  
681 4 ▶ if ( $add =~ m/^\d+\.\d+$/ && $add >= 0.56 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^\d+\.\d+$/u and $add >= "0.56") 0 4 4
Condition66%2/3
$add =~ /^\d+\.\d+$/u and $add >= "0.56"
!ll&&!rl&&r
130
MC/DC0%0/2
$add =~ /^\d+\.\d+$/u and $add >= "0.56"
$add =~ /^\d+\.\d+$/u $add >= "0.56"
Truth table66%2/3
A and B
A= $add =~ /^\d+\.\d+$/uB= $add >= "0.56"
ABresult
0X0
100
111
682 0 Rex::Logger::debug("Activating autodie.");
683 0 Rex::Config->set_autodie(1);
684 0 $found_feature = 1;
685 }
686  
687 4 ▶ if ( $add =~ m/^\d+\.\d+$/ && $add >= 0.55 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^\d+\.\d+$/u and $add >= "0.55") 0 4 4
Condition66%2/3
$add =~ /^\d+\.\d+$/u and $add >= "0.55"
!ll&&!rl&&r
130
MC/DC0%0/2
$add =~ /^\d+\.\d+$/u and $add >= "0.55"
$add =~ /^\d+\.\d+$/u $add >= "0.55"
Truth table66%2/3
A and B
A= $add =~ /^\d+\.\d+$/uB= $add >= "0.55"
ABresult
0X0
100
111
688 0 Rex::Logger::debug("Using Net::OpenSSH if present.");
689 0 Rex::Config->set_use_net_openssh_if_present(1);
690 0 $found_feature = 1;
691 }
692  
693 4 ▶ if ( $add =~ m/^\d+\.\d+$/ && $add >= 0.54 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^\d+\.\d+$/u and $add >= "0.54") 1 3 4
Condition100%3/3
$add =~ /^\d+\.\d+$/u and $add >= "0.54"
!ll&&!rl&&r
121
MC/DC100%2/2
$add =~ /^\d+\.\d+$/u and $add >= "0.54"
$add =~ /^\d+\.\d+$/u $add >= "0.54"
Truth table100%3/3
A and B
A= $add =~ /^\d+\.\d+$/uB= $add >= "0.54"
ABresult
0X0
100
111
694 1 Rex::Logger::debug("Add service check.");
695 1 Rex::Config->set_check_service_exists(1);
696  
697 1 Rex::Logger::debug("Setting set() to not append data.");
698 1 Rex::Config->set_set_no_append(1);
699  
700 1 $found_feature = 1;
701 }
702  
703 4 ▶ if ( $add =~ m/^\d+\.\d+$/ && $add >= 0.53 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^\d+\.\d+$/u and $add >= "0.53") 1 3 4
Condition100%3/3
$add =~ /^\d+\.\d+$/u and $add >= "0.53"
!ll&&!rl&&r
121
MC/DC100%2/2
$add =~ /^\d+\.\d+$/u and $add >= "0.53"
$add =~ /^\d+\.\d+$/u $add >= "0.53"
Truth table100%3/3
A and B
A= $add =~ /^\d+\.\d+$/uB= $add >= "0.53"
ABresult
0X0
100
111
704 1 Rex::Logger::debug("Registering CMDB as template variables.");
705 1 Rex::Config->set_register_cmdb_template(1);
706 1 $found_feature = 1;
707 }
708  
709 4 ▶ if ( $add =~ m/^\d+\.\d+$/ && $add >= 0.51 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^\d+\.\d+$/u and $add >= "0.51") 1 3 4
Condition100%3/3
$add =~ /^\d+\.\d+$/u and $add >= "0.51"
!ll&&!rl&&r
121
MC/DC100%2/2
$add =~ /^\d+\.\d+$/u and $add >= "0.51"
$add =~ /^\d+\.\d+$/u $add >= "0.51"
Truth table100%3/3
A and B
A= $add =~ /^\d+\.\d+$/uB= $add >= "0.51"
ABresult
0X0
100
111
710 1 Rex::Logger::debug("activating featureset >= 0.51");
711 1 Rex::Config->set_task_call_by_method(1);
712  
713 1 require Rex::Constants;
714 1 Rex::Constants->import( register_in => $register_to );
715  
716 1 require Rex::CMDB;
717 1 Rex::CMDB->import( register_in => $register_to );
718  
719 1 Rex::Commands::set(
720 cmdb => {
721 type => "YAML",
722 path => [
723 "cmdb/{operatingsystem}/{hostname}.yml",
724 "cmdb/{operatingsystem}/default.yml",
725 "cmdb/{environment}/{hostname}.yml",
726 "cmdb/{environment}/default.yml",
727 "cmdb/{hostname}.yml",
728 "cmdb/default.yml",
729 ],
730 }
731 );
732  
733 1 $found_feature = 1;
734 }
735  
736 4 ▶ if ( $add =~ m/^\d+\.\d+$/ && $add >= 0.40 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^\d+\.\d+$/u and $add >= "0.4") 1 3 4
Condition100%3/3
$add =~ /^\d+\.\d+$/u and $add >= "0.4"
!ll&&!rl&&r
121
MC/DC100%2/2
$add =~ /^\d+\.\d+$/u and $add >= "0.4"
$add =~ /^\d+\.\d+$/u $add >= "0.4"
Truth table100%3/3
A and B
A= $add =~ /^\d+\.\d+$/uB= $add >= "0.4"
ABresult
0X0
100
111
737 1 Rex::Logger::debug("activating featureset >= 0.40");
738 1 $Rex::Template::BE_LOCAL = 1;
739 1 $Rex::WITH_EXIT_STATUS = 1;
740 1 $found_feature = 1;
741 }
742  
743 4 ▶ if ( $add =~ m/^\d+\.\d+$/ && $add >= 0.35 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^\d+\.\d+$/u and $add >= "0.35") 1 3 4
Condition100%3/3
$add =~ /^\d+\.\d+$/u and $add >= "0.35"
!ll&&!rl&&r
121
MC/DC100%2/2
$add =~ /^\d+\.\d+$/u and $add >= "0.35"
$add =~ /^\d+\.\d+$/u $add >= "0.35"
Truth table100%3/3
A and B
A= $add =~ /^\d+\.\d+$/uB= $add >= "0.35"
ABresult
0X0
100
111
744 1 Rex::Logger::debug("activating featureset >= 0.35");
745 1 $Rex::Commands::REGISTER_SUB_HASH_PARAMETER = 1;
746 1 $found_feature = 1;
747 }
748  
749 # remove default task auth
750 4 ▶ if ( $add =~ m/^\d+\.\d+$/ && $add >= 0.31 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add =~ /^\d+\.\d+$/u and $add >= "0.31") 3 1 4
Condition66%2/3
$add =~ /^\d+\.\d+$/u and $add >= "0.31"
!ll&&!rl&&r
103
MC/DC50%1/2
$add =~ /^\d+\.\d+$/u and $add >= "0.31"
$add =~ /^\d+\.\d+$/u $add >= "0.31"
Truth table66%2/3
A and B
A= $add =~ /^\d+\.\d+$/uB= $add >= "0.31"
ABresult
0X0
100
111
751 3 Rex::Logger::debug("activating featureset >= 0.31");
752 3 Rex::Config->set_default_auth(0);
753 3 $found_feature = 1;
754 }
755  
756 4 ▶ if ( $add eq 'autodie' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "autodie") 1 3 4
757 1 Rex::Logger::debug('enabling autodie');
758 1 Rex::Config->set_autodie(1);
759 1 $found_feature = 1;
760 }
761  
762 4 ▶ if ( $add eq "no_autodie" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "no_autodie") 0 4 4
763 0 Rex::Logger::debug("disabling autodie");
764 0 Rex::Config->set_autodie(0);
765 0 $found_feature = 1;
766 }
767  
768 4 ▶ if ( $add eq "rex_kvm_agent" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "rex_kvm_agent") 0 4 4
769 0 Rex::Logger::debug(
770 "Activating experimental support for rex-kvm-agent.");
771 0 Rex::Config->set_use_rex_kvm_agent(1);
772 0 $found_feature = 1;
773 }
774  
775 4 ▶ if ( $add eq "template_ng" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "template_ng") 0 4 4
776 0 Rex::Logger::debug("Activating new template engine.");
777 0 Rex::Config->set_use_template_ng(1);
778 0 $found_feature = 1;
779 }
780  
781 4 ▶ if ( $add eq "no_template_ng" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "no_template_ng") 0 4 4
782 0 Rex::Logger::debug("Deactivating new template engine.");
783 0 Rex::Config->set_use_template_ng(0);
784 0 $found_feature = 1;
785 }
786  
787 4 ▶ if ( $add eq "register_cmdb_top_scope" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "register_cmdb_top_scope") 0 4 4
788 0 Rex::Logger::debug("Registering CMDB as template variables.");
789 0 Rex::Config->set_register_cmdb_template(1);
790 0 $found_feature = 1;
791 }
792  
793 4 ▶ if ( $add eq "no_local_template_vars" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "no_local_template_vars") 0 4 4
794 0 Rex::Logger::debug("activating featureset no_local_template_vars");
795 0 $Rex::Template::BE_LOCAL = 0;
796 0 $found_feature = 1;
797 }
798  
799 4 ▶ if ( $add eq "exit_status" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "exit_status") 0 4 4
800 0 Rex::Logger::debug("activating featureset exit_status");
801 0 $Rex::WITH_EXIT_STATUS = 1;
802 0 $found_feature = 1;
803 }
804  
805 4 ▶ if ( $add eq "sudo_without_sh" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "sudo_without_sh") 0 4 4
806 0 Rex::Logger::debug(
807 "using sudo without sh. this might break some things.");
808 0 Rex::Config->set_sudo_without_sh(1);
809 0 $found_feature = 1;
810 }
811  
812 4 ▶ if ( $add eq "sudo_without_locales" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "sudo_without_locales") 0 4 4
813 0 Rex::Logger::debug(
814 "Using sudo without locales. this _will_ break things!");
815 0 Rex::Config->set_sudo_without_locales(1);
816 0 $found_feature = 1;
817 }
818  
819 4 ▶ if ( $add eq "tty" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "tty") 0 4 4
820 0 Rex::Logger::debug("Enabling pty usage for ssh");
821 0 Rex::Config->set_no_tty(0);
822 0 $found_feature = 1;
823 }
824  
825 4 ▶ if ( $add eq "no_tty" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "no_tty") 0 4 4
826 0 Rex::Logger::debug("Disabling pty usage for ssh");
827 0 Rex::Config->set_no_tty(1);
828 0 $found_feature = 1;
829 }
830  
831 4 ▶ if ( $add eq "empty_groups" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "empty_groups") 0 4 4
832 0 Rex::Logger::debug("Enabling usage of empty groups");
833 0 Rex::Config->set_allow_empty_groups(1);
834 0 $found_feature = 1;
835 }
836  
837 4 ▶ if ( $add eq "use_server_auth" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "use_server_auth") 0 4 4
838 0 Rex::Logger::debug("Enabling use_server_auth");
839 0 Rex::Config->set_use_server_auth(1);
840 0 $found_feature = 1;
841 }
842  
843 4 ▶ if ( $add eq "exec_and_sleep" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "exec_and_sleep") 0 4 4
844 0 Rex::Logger::debug("Enabling exec_and_sleep");
845 0 Rex::Config->set_sleep_hack(1);
846 0 $found_feature = 1;
847 }
848  
849 4 ▶ if ( $add eq "disable_strict_host_key_checking" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "disable_strict_host_key_checking") 0 4 4
850 0 Rex::Logger::debug("Disabling strict host key checking for openssh");
851 0 Rex::Config->set_openssh_opt( StrictHostKeyChecking => "no" );
852 0 $found_feature = 1;
853 }
854  
855 #if($add eq "reporting" || $add eq "report" || exists $ENV{REX_REPORT_TYPE}) {
856 # Rex::Logger::debug("Enabling reporting");
857 4 Rex::Config->set_do_reporting(1);
858  
859 # $found_feature = 1;
860 #}
861  
862 4 ▶ if ( $add eq "source_profile" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "source_profile") 0 4 4
863 0 Rex::Logger::debug("Enabling source_profile");
864 0 Rex::Config->set_source_profile(1);
865 0 $found_feature = 1;
866 }
867  
868 4 ▶ if ( $add eq "source_global_profile" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "source_global_profile") 0 4 4
869 0 Rex::Logger::debug("Enabling source_global_profile");
870 0 Rex::Config->set_source_global_profile(1);
871 0 $found_feature = 1;
872 }
873  
874 4 ▶ if ( $add eq "no_path_cleanup" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "no_path_cleanup") 0 4 4
875 0 Rex::Logger::debug("Enabling no_path_cleanup");
876 0 Rex::Config->set_no_path_cleanup(1);
877 0 $found_feature = 1;
878 }
879  
880 4 ▶ if ( $add eq "exec_autodie" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "exec_autodie") 0 4 4
881 0 Rex::Logger::debug("Enabling exec_autodie");
882 0 Rex::Config->set_exec_autodie(1);
883 0 $found_feature = 1;
884 }
885  
886 4 ▶ if ( $add eq "no_cache" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "no_cache") 0 4 4
887 0 Rex::Logger::debug("disable caching");
888 0 Rex::Config->set_use_cache(0);
889 0 $found_feature = 1;
890 }
891  
892 4 ▶ if ( $add eq "verbose_run" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "verbose_run") 0 4 4
893 0 Rex::Logger::debug("Enabling verbose_run feature");
894 0 Rex::Config->set_verbose_run(1);
895 0 $found_feature = 1;
896 }
897  
898 4 ▶ if ( $add eq "disable_taskname_warning" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "disable_taskname_warning") 0 4 4
899 0 Rex::Logger::debug("Enabling disable_taskname_warning feature");
900 0 Rex::Config->set_disable_taskname_warning(1);
901 0 $found_feature = 1;
902 }
903  
904 4 ▶ if ( $add eq "no_task_chaining_cmdline_args" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "no_task_chaining_cmdline_args") 0 4 4
905 0 Rex::Logger::debug("Disabling task_chaining_cmdline_args feature");
906 0 Rex::Config->set_task_chaining_cmdline_args(0);
907 0 $found_feature = 1;
908 }
909  
910 4 ▶ if ( $add eq "task_chaining_cmdline_args" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "task_chaining_cmdline_args") 0 4 4
911 0 Rex::Logger::debug("Enabling task_chaining_cmdline_args feature");
912 0 Rex::Config->set_task_chaining_cmdline_args(1);
913 0 $found_feature = 1;
914 }
915  
916 4 ▶ if ( $add eq "write_utf8_files" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "write_utf8_files") 0 4 4
917 0 Rex::Logger::debug("Enabling write_utf8_files feature");
918 0 Rex::Config->set_write_utf8_files(1);
919 0 $found_feature = 1;
920 }
921  
922 4 ▶ if ( $add eq "no_write_utf8_files" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add eq "no_write_utf8_files") 0 4 4
923 0 Rex::Logger::debug("Disabling write_utf8_files feature");
924 0 Rex::Config->set_write_utf8_files(0);
925 0 $found_feature = 1;
926 }
927  
928 4 ▶ if ( $found_feature == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found_feature == 0) 0 4 4
929 0 Rex::Logger::info(
930 "You tried to load a feature ($add) that doesn't exists in your Rex version. Please update.",
931 "warn"
932 );
933 0 exit 1;
934 }
935  
936 }
937  
938 }
939  
940 703 ▶ if ( exists $ENV{REX_REPORT_TYPE} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"REX_REPORT_TYPE"}) 0 703 703
941 0 Rex::Logger::debug("Enabling reporting");
942 0 Rex::Config->set_do_reporting(1);
943 }
944  
945 703 ▶ if ( exists $ENV{REX_SUDO} && $ENV{REX_SUDO} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"REX_SUDO"} and $ENV{"REX_SUDO"}) 0 703 703
Condition33%1/3
exists $ENV{"REX_SUDO"} and $ENV{"REX_SUDO"}
!ll&&!rl&&r
70300
MC/DC0%0/2
exists $ENV{"REX_SUDO"} and $ENV{"REX_SUDO"}
exists $ENV{"REX_SUDO"} $ENV{"REX_SUDO"}
Truth table33%1/3
A and B
A= exists $ENV{"REX_SUDO"}B= $ENV{"REX_SUDO"}
ABresult
0X0
100
111
946 0 Rex::global_sudo(1);
947 }
948  
949 # we are always strict
950 703 strict->import;
951 }
952  
953 =head1 FEATURE FLAGS
954  
955 Everyone knows the pain if something gets deprecated and one has to
956 port his old (and stable) code to a new version of a library or a
957 framework. There is enough work to do instead of fixing code to work
958 with newer versions of them.
959  
960 So there is one promise new versions of Rex has to fulfill. They must
961 be backward compatible.
962  
963 I know this might be impossible in one way or another, but to minimize
964 this danger there is a thing called feature flags. If there is the need
965 to break backward compatibility in favor of a new feature there will be
966 a feature flag for this change. And only if this feature flag gets
967 enabled in the Rexfile it will break compatibility.
968  
969 So the default is always to remain compatible.
970  
971 If you have a problem that occurs after an update, it is considered as
972 a bug. Please report this bug in our issue tracker.
973  
974 Also see the L<backwards compatibility|https://metacpan.org/release/Rex/source/CONTRIBUTING.md#backwardscompatibility>
975 section of the CONTRIBUTING guide.
976  
977 =head2 How to enable feature flags
978  
979 You can enable feature flags in your Rexfile with the following code:
980  
981 use Rex -feature => ['1.4'];
982  
983 or even multiple ones like this:
984  
985 use Rex -feature => [qw(1.4 exec_autodie)];
986  
987 =head2 List of feature flags
988  
989 =over 4
990  
991 =item 1.4
992  
993 Enable per-task argument parsing (L<task_chaining_cmdline_args|Rex#task_chaining_cmdline_args>). Furthermore, all features from earlier versions are activated. Available since version 1.4.
994  
995 =item no_task_chaining_cmdline_args
996  
997 Disable per-task argument parsing. Available since version 1.4.
998  
999 =item task_chaining_cmdline_args
1000  
1001 Enable per-task argument parsing: C<rex --rex --args task1 --task1arg=value task2 --task2arg>
1002 so task1 only gets C<task1arg> and task2 only gets C<task2arg>. Available since version 1.4.
1003  
1004 =item 1.3
1005  
1006 Activating the new template engine by default. Furthermore, all features from earlier versions are activated. Available since version 1.3.
1007  
1008 =item no_template_ng
1009  
1010 Disabling the new template engine. Available since version 1.3.
1011  
1012 =item 1.0
1013  
1014 Disabling usage of a tty. This increases compatibility for remote
1015 execution. Furthermore, all features from earlier versions are
1016 activated. Available since version 1.0.
1017  
1018 =item no_autodie
1019  
1020 Will disable autodie feature. Available since version 1.0.
1021  
1022 =item tty
1023  
1024 Enable pty usage for ssh connections. Available since version 1.0.
1025  
1026 =item template_ng
1027  
1028 Enabling the new template engine (better error reporting, etc.). Available since version 0.56.
1029  
1030 =item 0.56
1031  
1032 Will activate autodie feature. Furthermore, all features from earlier
1033 versions are activated. Available since version 0.56.
1034  
1035 =item autodie
1036  
1037 Will enable autodie feature: die on all failed L<filesystem commands|https://metacpan.org/pod/Rex::Commands::Fs>. Available since version 1.13.1.
1038  
1039 =item 0.55
1040  
1041 Will activate using L<Net::OpenSSH> by default if present. Furthermore,
1042 all features from earlier versions are activated. Available since version 0.55.
1043  
1044 =item 0.54
1045  
1046 Will activate checking services for existence before trying to
1047 manipulate them, and C<set()> will overwrite already existing values
1048 (instead of concatenating). Furthermore, all features from earlier
1049 versions are activated. Available since version 0.54.
1050  
1051 =item 0.53
1052  
1053 Will activate register_cmdb_top_scope. And all things 0.51 and down
1054 activated. Available since version 0.53.
1055  
1056 =item register_cmdb_top_scope
1057  
1058 Will register all cmdb top scope variables automatically in the
1059 templates. Available since version 0.53.
1060  
1061 =item 0.51
1062  
1063 Will load L<Rex::Constants> and the CMDB by default. And all things 0.47
1064 and down activated. Available since version 0.51.
1065  
1066 =item disable_taskname_warning
1067  
1068 Disable warning about invalid task names (they should match
1069 C</^[a-zA-Z_][a-zA-Z0-9_]*$/>). Available since version 0.47.
1070  
1071 =item verbose_run
1072  
1073 Explicitly output "Successfully executed" or "Error executing" messages
1074 for C<run()> commands. Available since version 0.47.
1075  
1076 =item no_cache
1077  
1078 Disable caching (like discovery results of remote OS, hardware, shell,
1079 etc.). Available since version 0.46.
1080  
1081 =item no_path_cleanup
1082  
1083 Controls whether Rex should use the default or explicitly configured C<PATH>
1084 settings when executing commands or not. See also the L<path|Rex::Commands#path>
1085 command and the L<set_path|Rex::Config#set_path> configuration option.
1086 Available since version 0.44.
1087  
1088 =item source_profile
1089  
1090 Source C<$HOME/.profile> before running a command. Available since version 0.44.
1091  
1092 =item source_global_profile
1093  
1094 Source C</etc/profile> before running a command. Available since version 0.44.
1095  
1096 =item exec_autodie
1097  
1098 If you execute a command with C<run()> Rex will C<die()> if the command
1099 returns a C<RETVAL != 0>. Available since version 0.44.
1100  
1101 =item exec_and_sleep
1102  
1103 Sometimes some commands that fork away didn't keep running. With this
1104 flag rex will wait a few ms before exiting the shell. Available since version 0.43.
1105  
1106 =item disable_strict_host_key_checking
1107  
1108 Disabling strict host key checking for openssh connection mode. Available since version 0.43.
1109  
1110 =item reporting
1111  
1112 Enable reporting. Available since version 0.43.
1113  
1114 =item empty_groups
1115  
1116 Enable usage of empty groups. Available since version 0.42.
1117  
1118 =item use_server_auth
1119  
1120 Enable the usage of special authentication options for servers. Available since version 0.42.
1121  
1122 =item no_tty
1123  
1124 Disable pty usage for ssh connections. Available since version 0.41.
1125  
1126 =item no_local_template_vars
1127  
1128 Use global variables in templates. Available since version 0.40.
1129  
1130 =item sudo_without_sh
1131  
1132 Run sudo commands directly without the use of 'sh'. This might break
1133 things. Available since version 0.40.
1134  
1135 =item sudo_without_locales
1136  
1137 Run sudo commands without locales. This will break things if you don't
1138 use English locales. Available since version 0.40.
1139  
1140 =item exit_status
1141  
1142 This option tells Rex to return a non zero value on exit if a task
1143 fails. Available since version 0.39.
1144  
1145 =item 0.35
1146  
1147 This option enables the features of 0.31 and the possibility to call
1148 tasks as a functions without the need to use a hash reference for the
1149 parameters. Available since version 0.35.
1150  
1151 =item 0.31
1152  
1153 To enable special authentication options for a server group. This will
1154 overwrite the default authentication options for a task. Available since version 0.31.
1155  
1156 =back
1157  
1158 =head1 CONTRIBUTORS
1159  
1160 Many thanks to the contributors for their work. Please see L<CONTRIBUTORS|https://metacpan.org/release/Rex/source/CONTRIBUTORS> file for a complete list.
1161  
1162 =head1 LICENSE
1163  
1164 Rex is a free software, licensed under:
1165 The Apache License, Version 2.0, January 2004
1166  
1167 =cut
1168  
1169 105 1;
« lib/Rex/User/FreeBSD.pm ↑ Summary lib/Rex/Commands/Cron.pm »