怎么给任务传递参数?
task 'mytask', group => "myservers", sub {
my $parameters = shift;
my $parameter1_value = $parameters->{parameter1};
my $parameter2_value = $parameters->{parameter2};
print "$parameter1_value=$parameter1_value
";
print "$parameter2_value=$parameter2_value
";
};
task 'mytask', group => "myservers", sub {
my $parameters = shift;
my $parameter1_value = $parameters->{parameter1};
my $parameter2_value = $parameters->{parameter2};
print "$parameter1_value=$parameter1_value
";
print "$parameter2_value=$parameter2_value
";
};
[root@node01 my-first-rex-project]# rex mytask --parameter1=aaaaa --parameter2=bbbb
[2017-04-29 10:41:54] INFO - Running task mytask on 192.168.137.3
$parameter1_value=aaaaa
$parameter2_value=bbbb
[2017-04-29 10:42:05] INFO - All tasks successful on all hosts
desc "Start Mysql Service";
task "start_mysql", group => "myservers", sub {
service "mysql" => "start";
};
task 'mytask', group => "myservers", sub {
my $parameters = shift;
my $parameter1_value = $parameters->{parameter1};
my $parameter2_value = $parameters->{parameter2};
print "$parameter1_value=$parameter1_value
";
print "$parameter2_value=$parameter2_value
";
my $output = run "ps -ef | grep $parameter1_value | grep $parameter2_value";
say $output;
};
[root@node01 my-first-rex-project]# rex mytask --parameter1=a1.sh --parameter2=mqm
[2017-04-29 10:44:34] INFO - Running task mytask on 192.168.137.3
$parameter1_value=a1.sh
$parameter2_value=mqm
mqm 24297 24272 0 01:46 pts/0 00:00:00 vim a1.sh
root 24380 24298 0 01:46 ? 00:00:00 bash -c LC_ALL=C ; export LC_ALL; PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/pkg/bin:/usr/pkg/sbin; export PATH; ps -ef | grep a1.sh | grep mqm
[2017-04-29 10:44:45] INFO - All tasks successful on all hosts
[root@node01 my-first-rex-project]#