Rex::Inline - write Rex in perl
Rex::Inline is an API of Rex module write with Moose.
when you want use rex in your perl program, and do not want to use the rex command line, you can try to use this module.
Bug Tracker: https://github.com/johnnywang1991/RexInline/issues
use Rex::Inline; use Rex::Inline::Test; my $rex_inline = Rex::Inline->new( use_debug => 0 # now you can set default authentication user => $user, # optional password => $password, # optional public_key => $public_key, # optional private_key => $private_key,# optional ); # add default authentication # if you didn't provide authentication in your task, Rex::Inline will use this as default one # or if your authentication is failed, Rex::Inline will use this retry the ssh connection $rex_inline->add_auth({ user => $user, password => $password, sudo => TRUE, }); $rex_inline->add_auth({ user => $user, public_key => $public_key, private_key => $private_key, }); # data reference like this $rex_inline->add_task( { name => 'something_uniq_string', # name is required when add data_reference task func => sub { # func is required when add data_reference task ... }, user => $user, server => [@server], # if need password password => $password, # optional public_key => $public_key, private_key => $private_key, } ); # or Rex::Inline::Test is based on Rex::Inline::Base module # See Rex::Inline::Base Documents $rex_inline->add_task( Rex::Inline::Test->new( user => $user, server => [@server], # if need password password => $password, # optional public_key => $public_key, private_key => $private_key, # input param, in any format you want input => $input, ) ); $rex_inline->execute; # get rex task reports $rex_inline->reports;
set default ssh connection user
set default ssh connection password
set default private_key filename
set default public_key filename
set/get debug option (Bool)
Print or not debug level log
see rex -d option
default is 0 (disabled)
set/get use_cache option (Bool)
Use or not rex -c option
default is 1 (enable)
set/get use_report option (Bool)
show rex report result
set/get use_report_log option (Bool)
report to log
default is 0 (false)
set/get log dir (String)
default is "./rexlogs/"
"./rexlogs/"
set/get parallelism nums (Int)
see rex -t option
default is 5
get log paths (ArrayRef)
format is
[{task_id => log_path}, ...]
readonly
get rex process reports (ArrayRef)
format is:
[{report => $report_ref, task_id => $task_id, date => $date, hostname => $hostname}, ...]
add Rex::Inline::Base Object to TaskList
or Add Data reference to TaskList
my $rex_inline = Rex::Inline->new; $rex_inline->add_task({ name => 'something_uniq_string', # required when add data_reference task func => sub { # required when add data_reference task ... }, user => $user2, server => [@server2], # if need password password => $password2, # optional public_key => $public_key2, private_key => $private_key2, }); ...
Add an authentication fallback
This is the default authentication
If all you provide authentications is failed, Rex::Inline will try to use this one
$rex_inline->add_auth({ user => $user, password => $password, sudo => TRUE, }); $rex_inline->add_auth({ user => $user, public_key => $public_key, private_key => $private_key, });
Execute all loaded Task in parallel
$rex_inline->execute;
my $yaml_report = $rex_inline->report_as_yaml;
my $json_report = $rex_inline->report_as_json;
$rex_inline->print_as_yaml;
$rex_inline->print_as_json;
To install Rex::Inline, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Rex::Inline
CPAN shell
perl -MCPAN -e shell install Rex::Inline
For more information on module installation, please visit the detailed CPAN module installation guide.