[root@yyjk rex]# cat Rexfile
use Rex -feature => ['1.0'];
use Rex::Misc::ShellBlock;
use Rex::Misc::PerlBlock;
no strict;
user "root";
private_key "/root/.ssh/id_rsa";
public_key "/root/.ssh/id_rsa.pub";
key_auth;
group linuxservers => "10.3.172.15","10.2.247.80";
group aixservers => "10.3.234.5";
task 'mytask1', group => "linuxservers", sub {
my $parameters = shift;
my $parameter1_value = $parameters->{parameter1};
#my $parameter2_value = $parameters->{parameter2};
file "/tmp/getpp.sh",
source => "script/getpp.sh",
mode => 755;
my $current_server = connection->server;
say $current_server;
my $output = run "/tmp/getpp.sh $current_server";
say $output;
};
task 'mytask2', group => "aixservers", sub {
my $parameters = shift;
my $parameter1_value = $parameters->{parameter1};
#my $parameter2_value = $parameters->{parameter2};
file "/tmp/getpp.sh",
source => "script/getpp.sh",
mode => 755;
my $current_server = connection->server;
say $current_server;
my $output = run "/tmp/getpp.sh $current_server";
say $output;
};
[root@yyjk rex]# rex mytask2
[2017-05-16 18:28:54] INFO - Running task mytask2 on 10.3.234.5
10.3.234.5
[2017-05-16 18:28:57] INFO - All tasks successful on all hosts