-
Notifications
You must be signed in to change notification settings - Fork 0
Writingmodules
This is applicable sind Rex 0.33.
If you want to share tasks between projects or with others you can write modules. Modules are in fact normal Perl Packages.
A module exists of a directory and a Module.pm file inside it.
For example:
+ Apache/ <-- Directory
+-- Module.pm <-- Module fileInside this Apache Module you can put additional files, like configuration files or templates.
+ Apache/
+--+ templates/
+-- httpd.conf.tpl
+-- Module.pmInside the Module.pm File you define the tasks you want to share.
package Apache;
use Rex -base;
task prepare => sub {
install "apache2";
install "libapache2-php5";
};
task configure => sub {
file "/etc/apache2/httpd.conf",
content => template("templates/httpd.conf.tpl"),
owner => "root";
};
1; # don't forget this last line!If you want to use your new module you have to do 2 things.
First, create a directory called lib in the same directory where your Rexfile is.
+-- Rexfile
+-- lib/After this copy your module into the lib directory.
+-- Rexfile
+--+ lib/
+--+ Apache/
+--+ templates/
+-- httpd.conf.tpl
+-- Module.pmThan you can include your Module into your Rexfile.
# Rexfile
include qw/Apache/;
user "root";
group httpds => "webserver[01..10]";
group mysqls => "db[01..04]";
task "setup_httpds", group => "httpds", sub {
Apache::prepare();
Apache::configure();
};
task "setup_mysqls", group => "mysqls", sub {
# code
};If you want to share your module you can now upload it to any version control system and share it with your colleagues or other people.