NAME

Rex::Inline - write Rex in perl

DESCRIPTION

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.

GETTING HELP

SYNOPSIS

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;

ATTRIBUTES

user

set default ssh connection user

password

set default ssh connection password

private_key

set default private_key filename

public_key

set default public_key filename

use_debug

set/get debug option (Bool)

Print or not debug level log

see rex -d option

default is 0 (disabled)

use_cache

set/get use_cache option (Bool)

Use or not rex -c option

default is 1 (enable)

use_report

set/get use_report option (Bool)

show rex report result

default is 1 (enable)

use_report_log

set/get use_report_log option (Bool)

report to log

default is 0 (false)

log_dir

set/get log dir (String)

default is "./rexlogs/"

parallelism

set/get parallelism nums (Int)

see rex -t option

default is 5

log_paths

get log paths (ArrayRef)

format is

[{task_id => log_path}, ...]

readonly

reports

get rex process reports (ArrayRef)

format is:

[{report => $report_ref, task_id => $task_id, date => $date, hostname => $hostname}, ...]

readonly

METHODS

add_task

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_auth

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

Execute all loaded Task in parallel

$rex_inline->execute;
report_as_yaml
my $yaml_report = $rex_inline->report_as_yaml;
report_as_json
my $json_report = $rex_inline->report_as_json;
$rex_inline->print_as_yaml;
$rex_inline->print_as_json;