Skip to content
klp2 edited this page Sep 30, 2012 · 4 revisions

If you want to provide some parameter for your task, you can easily do it this way.

desc "Add a new user";
task "useradd", "server1", "server2", sub {
   my ($params) = @_;
   run "useradd -m " . $params->{'username'};
   run "echo " . $params->{'username'} . ":" . $params->{'password'} ." |chpasswd"; 
}; 

And call it:

rex useradd --username=user1 --password=securepw

Note: Passing parameters cannot be done to a batch command. If you wish to do this bundle tasks in the following fashion and then call that task as above.

use Data::Dumper;

task "task1", sub {
  print Dumper(\@_);
};

task "task2", sub {
  print Dumper(\@_);
};

task "task1and2", sub {
  #List of tasks start and end /task1...n/
  do_task [qw/task1 task2/];                                                                                                          
};
Clone this wiki locally