Difference between revisions of "Rex"
From Leaky
(Tips for using rex) |
(→Passing parameters to a rex task) |
||
Line 29: | Line 29: | ||
$ rex -q version centos-release | $ rex -q version centos-release | ||
+ | |||
+ | The preferred way is to use named parameters | ||
+ | |||
+ | task "pkgversion", sub { | ||
+ | my $param = shift; # get args from the command line --key=value | ||
+ | my $servername = connection->server; | ||
+ | say $servername . ": " . run "rpm -q " . $param->{pkg}; | ||
+ | }; | ||
+ | |||
+ | $ rex -q version --pkg=centos-release | ||
+ | |||
+ | Using named parameters also means you can call the task from another task | ||
+ | |||
+ | task "versions", sub { | ||
+ | pkgversion({pkg => "centos-release"}); | ||
+ | pkgversion({pkg => "httpd"}); | ||
+ | }; | ||
+ | |||
+ | $ rex -q versions |
Latest revision as of 11:42, 7 November 2013
Download from http://rexify.org/ - the easiest way is to create a yum repo file since this will allow it to pull in other dependencies.
cat > /etc/yum.repos.d/rex.repo <<'EOF' [rex] name=Fedora $releasever - $basearch - Rex Repository baseurl=http://rex.linux-files.org/CentOS/$releasever/rex/$basearch/ enabled=1 EOF
Defining groups
group "web" => "web[1..7]"; group "misc" => "ns1", "ns2", "dev";
Force -q always
To make it act like -q is always passed, simply add the following to the Rexfile
$::QUIET = 1;
Passing parameters to a rex task
Just use @ARGV in the same way as normal, except that $ARGV[1] is the first parameter, rather than $ARGV[0]
task "version", group => ["web", "misc"], sub { my $servername = connection->server; say $servername . ": " . run "rpm -q " . $ARGV[1]; };
$ rex -q version centos-release
The preferred way is to use named parameters
task "pkgversion", sub { my $param = shift; # get args from the command line --key=value my $servername = connection->server; say $servername . ": " . run "rpm -q " . $param->{pkg}; };
$ rex -q version --pkg=centos-release
Using named parameters also means you can call the task from another task
task "versions", sub { pkgversion({pkg => "centos-release"}); pkgversion({pkg => "httpd"}); };
$ rex -q versions