Rex-Inline
view release on metacpan or search on metacpan
0.0.7 Tue Apr 14 10:36 CST 2015
- "add log report to log file"
0.0.6 Wen Apr 8 10:01 CST 2015
- "force use SSH instead OpenSSH"
0.0.5 Thu Apr 2 18:10 CST 2015
- "update document"
0.0.4 Thu Apr 2 17:58 CST 2015
- "add <user> <password> <private_key> <public_key> Attr, Now you can set default authentication in <new>"
0.0.3 Thu Apr 2 12:45 CST 2015
- "add <add_auth> METHOD to add default authentication"
- "add <report_as_yaml> METHOD to reports as yaml"
- "add <report_as_json> METHOD to reports as json"
- "add <print_as_yaml> METHOD to print as yaml"
- "add <print_as_json> METHOD to print as json"
0.0.2 Wen Apr 1 18:00 CST 2015
- "update document"
use Rex -feature => ['1.0'];
use Rex::Inline;
my $rex_inline = Rex::Inline->new;
$rex_inline->add_task(
{
user => $user,
server => [@server],
password => $password,
# private_key => $private_key_path,
# public_key => $public_key_path,
func => sub {
# è¿éåè¦å¨ Rex 䏿§è¡çè¯å¥
}
}
);
$rex_inline->execute;
my $reports = $rex_inline->reports;
### t.pl
use Test;
use Rex::Inline;
my $rex_inline = Rex::Inline->new;
$rex_inline->add_task( Test->new(
user => $user,
server => [@server],
password => $password,
# private_key => $private_key_path,
# public_key => $public_key_path,
input => 'test', # 任使³ä¼ ç»æ¨¡åçåæ°
) );
$rex_inline->execute;
my $reports = $rex_inline->reports;
lib/Rex/Inline.pm view on Meta::CPAN
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;
lib/Rex/Inline.pm view on Meta::CPAN
=over 4
=item user
set default ssh connection user
=item password
set default ssh connection password
=item private_key
set default private_key filename
=item public_key
set default public_key filename
=cut
has [qw(user password private_key public_key)] => (is => 'ro', predicate => 1);
=item use_debug
set/get debug option (Bool)
Print or not debug level log
see B<rex -d> option
default is 0 (disabled)
lib/Rex/Inline.pm view on Meta::CPAN
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,
});
...
=cut
has task => (
is => 'ro',
isa => 'TaskType',
coerce => 1,
lib/Rex/Inline.pm view on Meta::CPAN
If all you provide authentications is failed, B<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,
});
=cut
has auth => (
is => 'ro',
isa => 'ArrayRef[HashRef]',
default => sub{[]},
traits => ['Array'],
handles => {add_auth => 'push'},
lib/Rex/Inline.pm view on Meta::CPAN
### initial task
desc $task->id;
### last param overwrite the caller module name Rex Commands line 284-286
task $task->name, group => $task->id, $task->func, { class => "Rex::CLI" };
}
### default auth
my @default_auth;
if ($self->{user}) {
@default_auth = ( user => $self->{user} );
for (qw(password public_key private_key)) {
push @default_auth, $_ => $self->{$_} if $self->{$_};
}
}
$self->add_auth({@default_auth}) if @default_auth;
### add auth fallback
auth fallback => @{ $self->auth } if $self->has_auth;
return Rex::TaskList->create;
}
lib/Rex/Inline/Base.pm view on Meta::CPAN
=cut
has server => (is => 'ro', required => 1);
=item user
username used when ssh connection
=item password
password used when ssh connection
=item private_key
private_key filename used when ssh connection
=item public_key
public_key filename used when ssh connection
=item sudo [TRUE|FALSE]
use sudo when execute commands
default is C<undef>
=cut
has user => (is => 'ro', default => '');
has [qw(password private_key public_key sudo)] => (is => 'ro');
=item input
input param for tasklist module in any format you need
=cut
has input => (is => 'rw');
=back
=cut
has name => (is => 'ro', lazy => 1, builder => 1);
has task_auth => (is => 'ro', lazy => 1, builder => 1);
sub _build_id { time ^ $$ ^ unpack "%L*", `ps axww | gzip` }
sub _build_name { join('_',grep {$_} (split(/::/, shift->meta->{package}))[qw(-2 -1)]) }
sub _build_task_auth {
my %auth;
$auth{user} = $_[0]->{user};
$auth{password} = $_[0]->{password} if $_[0]->{password};
$auth{public_key} = $_[0]->{public_key} if $_[0]->{public_key};
$auth{private_key} = $_[0]->{private_key} if $_[0]->{private_key};
$auth{sudo} = $_[0]->{sudo} if $_[0]->{sudo};
return {%auth};
}
__PACKAGE__->meta->make_immutable;
( run in 0.408 second using v1.01-cache-2.11-cpan-a5abf4f5562 )