Rex::Commands::Pkg - Install/Remove Software packages
With this module you can install packages and files.
install file => "/etc/passwd", { source => "/export/files/etc/passwd" }; install package => "perl";
The install function can install packages (for CentOS, OpenSuSE and Debian) and files.
task "prepare", "server01", sub { install package => "perl"; # or if you have to install more packages. install package => [ "perl", "ntp", "dbus", "hal", "sudo", "vim", ]; };
This is deprecated since 0.9. Please use File file instead.
task "prepare", "server01", sub { install file => "/etc/passwd", { source => "/export/files/etc/passwd", owner => "root", group => "root", mode => 644, }; };
task "prepare", "server01", sub { install file => "/etc/httpd/apache2.conf", { source => "/export/files/etc/httpd/apache2.conf", owner => "root", group => "root", mode => 644, on_change => sub { say "File was modified!"; } }; };
task "prepare", "server01", sub { install file => "/etc/httpd/apache2.tpl", { source => "/export/files/etc/httpd/apache2.conf", owner => "root", group => "root", mode => 644, on_change => sub { say "File was modified!"; }, template => { greeting => "hello", name => "Ben", }, }; };
This function supports the following hooks:
This gets executed before everything is done. The return value of this hook overwrite the original parameters of the function-call.
This gets executed right before the new package is installed. This hook is only available for package installations. If you need file hooks, you have to use the file() function.
This gets executed right after the new package was installed. This hook is only available for package installations. If you need file hooks, you have to use the file() function.
This gets executed right before the install() function returns.
This function will remove the given package from a system.
task "cleanup", "server01", sub { remove package => "vim"; };
This function do a complete system update.
For example apt-get upgrade or yum update.
task "update-system", "server1", sub { update_system; };
This function returns all installed packages and their version.
task "get-installed", "server1", sub { for my $pkg (installed_packages()) { say "name : " . $pkg->{"name"}; say " version: " . $pkg->{"version"}; } };
This function tests if $package is installed. Returns 1 if true. 0 if false.
task "isinstalled", "server01", sub { if( is_installed("rex") ) { say "Rex is installed"; } else { say "Rex is not installed"; } };
This function updates the local package database. For example, on CentOS it will execute yum makecache.
task "update-pkg-db", "server1", "server2", sub { update_package_db; install package => "apache2"; };
Add or remove a repository from the package manager.
For Debian: If you have no source repository, or if you don't want to add it, just remove the source parameter.
task "add-repo", "server1", "server2", sub { repository "add" => "repository-name", url => "http://rex.linux-files.org/debian/squeeze", distro => "squeeze", repository => "rex", source => 1; };
For ALT Linux: If repository is unsigned, just remove the sign_key parameter.
task "add-repo", "server1", "server2", sub { repository "add" => "altlinux-sisyphus", url => "ftp://ftp.altlinux.org/pub/distributions/ALTLinux/Sisyphus", sign_key => "alt", arch => "noarch, x86_64", repository => "classic"; };
For CentOS, Mageia and SuSE only the name and the url are needed.
task "add-repo", "server1", "server2", sub { repository add => "repository-name", url => 'http://rex.linux-files.org/CentOS/$releasever/rex/$basearch/'; };
To remove a repository just delete it with its name.
task "rm-repo", "server1", sub { repository remove => "repository-name"; };
You can also use one call to repository to add repositories on multiple platforms:
task "add-repo", "server1", "server2", sub { repository add => myrepo => { Ubuntu => { url => "http://foo.bar/repo", distro => "precise", repository => "foo", }, Debian => { url => "http://foo.bar/repo", distro => "squeeze", repository => "foo", }, CentOS => { url => "http://foo.bar/repo", }, }; };
To set an other package provider as the default, use this function.
user "root"; group "db" => "db[01..10]"; package_provider_for SunOS => "blastwave"; task "prepare", group => "db", sub { install package => "vim"; };
This example will install vim on every db server. If the server is a Solaris (SunOS) it will use the blastwave Repositories.
To install Rex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Rex
CPAN shell
perl -MCPAN -e shell install Rex
For more information on module installation, please visit the detailed CPAN module installation guide.