I went crazy from perl and the installation of their modules. For some icinga checks we need to install a few base perl packages using cpanminus. It's taking a long time before the installation succeeds depending on the internet connection or server specifications.

Using a puppet exec to automate this installation is frustrating because the timeout is unpredictable and could take hours from time to time!

So I started to look for a way to package it into an rpm which I can distribute over our own yum repository.

The first software I got reviewed is cpan2rpm, it looked promising. You could give a text file containing the names of the modules to package.

That way I could use a git repo containing this file which triggers an automated jenkins job which creates the packages and uploads them to the repo.

Unfortunately it doesn't package the cpanminus module. So I had to look further.

Last week I got the solution by cpanspec, a piece of software I read about on nailingjelly 's blogpost. And yes, I achieved to package it.

Installation & configuration of the required tools:

$ sudo yum install rpmdevtools perl perl-devel perl-Test-Base
$ sudo curl -L http://cpanmin.us | perl - --sudo App::cpanminus
$ sudo /usr/local/bin/cpanm CPAN::DistnameInfo
$ sudo yum install cpanspec

$ cd ~
$ rpmdev-setuptree

Create spec file and source rpm from a cpan module:

$ cpanspec --follow --srpm CPAN::Module --packager YOURNAME

Install the source rpm to create a package from it using the new generated spec file:

$ rpm -i name-of-module.src.rpm

You should see there is a SPEC file generated in the rpmbuild tree:

$ cd ~/rpmbuild/SPECS
$ vim cpan-module-name.spec

Finally give it a shot and build a fresh rpm package:

$ rpmbuild -ba cpan-module-name.spec

The first time trying to build App::cpanminus I had to add some missing file declarations to the spec file. Spawning the error:

RPM build errors:
    Installed (but unpackaged) file(s) found:

So I added the 2 unpacked files to the %files section:

%doc Changes cpanfile LICENSE META.json README

Running the rpmbuild now resulted in a fresh rpm:

$ ls ../RPMS/noarch/

I installed the rpm on a development system and successfully installed a perl module with the cpanm command afterwards:

$ yum localinstall name-of-the-module.rpm

So from now on our servers are hooked up with those create packages distributed by our own yum repository.

And the whole initialization process of a fresh server gained in time and therefore in efficiency in our environment this way!