CPAN Modules

I have my playbook for CPAN. Right now it only works for Debian. I need it to work for SLES/RHEL/UBUNTU also but I don’t know how to add them into the playbook. Can someone please help!

What I have:

cpan-modules.yaml

Please check the tasks below.

Tested on:

- Debian 9 and Debian 10
- CentOS 7
- Ubuntu Bionic (symlink /usr/bin/python3 or set ansible_python_interpreter inventory variable)
- OpenSuSE 15

Notes:

- notest is true as the @INC dot removal broke a couple of Perl modules
- additional prerequisites might be needed for XS modules, e.g.
https://wiki.linuxia.de/library/stefan-hornburg-racke-perl-tricks-en#text-amuse-label-debianprequisites
- split up the OS specific tasks into separate task files and include them

Let me know if you have any questions.

Regards
          Racke

Hi Stefan,

Thanks for the tasks! I have modified it a bit to what we use. See below:

Hi Stefan,

Thanks for the tasks! I have modified it a bit to what we use. See below:

---
- hosts: all
remote_user: root

tasks:
- name: copy MyConfig.pm to the correct directory on remote host(s)
template:
src: ../../../library/conf/debian/debian-myconfig.pm
dest: /root/.cpan/CPAN/MyConfig.pm
- name: Install cpanm on Debian
apt:
name: cpanminus
when:
ansible_distribution|lower == 'debian'
- name: Install other prerequisites (Debian)
apt:
name:
- gcc
- make
when:
ansible_distribution|lower == 'debian'
- name: Install cpanm on Ubuntu
apt:
name: cpanminus
when:
ansible_distribution|lower == 'ubuntu'
- name: Install other prerequisites (Ubuntu)
apt:
name:
- gcc
- make
when:
ansible_distribution|lower == 'ubuntu'
- name: Install cpanm on RedHat
yum:
name: perl-App-cpanminus
when:
ansible_distribution|lower == 'redhat'
- name: Install other prerequisites (RedHat)
yum:
name:
- gcc
- make
when:
ansible_distribution|lower == 'redhat'
- name: Install cpanm (SUSE Linux)
zypper:
name: perl-App-cpanminus
when:
ansible_distribution|lower == 'sles'
- name: Install other prerequisites (SUSE Linux)
yum:
name:
- gcc
- make
when:
ansible_distribution|lower == 'sles'
- name: Install some CPAN modules
cpanm:
name: "{{ item }}"
notest: true
with_items:
- "HTTP::DAV"
- "Log::Log4perl"
- "SOAP::Lite"
- "Digest::SHA1"
- "AnyData"
- "Log::Dispatch::FileRotate"
- "Term::Shell"
- "Crypt::RC4"
environment:
PERL_CPANM_OPT: "--mirror http://hCPAN2.sde.rdlabs.hpecorp.net/"
...

When I run this I get:

failed: [ubuntu12ex6401] (item=HTTP::DAV) => {"ansible_loop_var": "item", "changed": false, "cmd": "/usr/bin/cpanm
HTTP::DAV -n", "item": "HTTP::DAV", "msg": "! Finding HTTP::DAV on cpanmetadb failed.\n! Finding HTTP::DAV on
search.cpan.org failed.\n--> Working on HTTP::DAV\nFetching
http://hCPAN2.sde.rdlabs.hpecorp.net/authors/id/C/CO/COSIMO/HTTP-DAV-0.49.tar.gz ... OK\nConfiguring HTTP-DAV-0.49 ...
OK\n==> Found dependencies: XML::DOM\n! Finding XML::DOM on cpanmetadb failed.\n! Finding XML::DOM on search.cpan.org
failed.\n--> Working on XML::DOM\nFetching
http://hCPAN2.sde.rdlabs.hpecorp.net/authors/id/T/TJ/TJMATHER/XML-DOM-1.46.tar.gz ... OK\nConfiguring XML-DOM-1.46 ...
OK\n==> Found dependencies: XML::Parser::PerlSAX, XML::Parser\n! Finding XML::Parser::PerlSAX on cpanmetadb failed.\n!
Finding XML::Parser::PerlSAX on search.cpan.org failed.\n--> Working on XML::Parser::PerlSAX\nFetching
http://hCPAN2.sde.rdlabs.hpecorp.net/authors/id/K/KM/KMACLEOD/libxml-perl-0.08.tar.gz ... OK\nConfiguring
libxml-perl-0.08 ... OK\n==> Found dependencies: XML::Parser\n! Finding XML::Parser on cpanmetadb failed.\n! Finding
XML::Parser on search.cpan.org failed.\n--> Working on XML::Parser\nFetching
http://hCPAN2.sde.rdlabs.hpecorp.net/authors/id/T/TO/TODDR/XML-Parser-2.44.tar.gz ... OK\nConfiguring XML-Parser-2.44
... OK\nBuilding XML-Parser-2.44 ... FAIL\n! Installing XML::Parser failed. See /root/.cpanm/build.log for details.\n!
Bailing out the installation for libxml-perl-0.08. Retry with --prompt or --force.\n! Bailing out the installation for
XML-DOM-1.46. Retry with --prompt or --force.\n! Bailing out the installation for HTTP-DAV-0.49. Retry with --prompt or
--force.\n"}

failed: [ubuntu12ex6401] (item=SOAP::Lite) => {"ansible_loop_var": "item", "changed": false, "cmd": "/usr/bin/cpanm
SOAP::Lite -n", "item": "SOAP::Lite", "msg": "! Finding SOAP::Lite on cpanmetadb failed.\n! Finding SOAP::Lite on
search.cpan.org failed.\n--> Working on SOAP::Lite\nFetching
http://hCPAN2.sde.rdlabs.hpecorp.net/authors/id/P/PH/PHRED/SOAP-Lite-1.27.tar.gz ... OK\nConfiguring SOAP-Lite-1.27 ...
OK\n==> Found dependencies: IO::Socket::SSL, LWP::Protocol::https, XML::Parser\n! Finding IO::Socket::SSL on cpanmetadb
failed.\n! Finding IO::Socket::SSL on search.cpan.org failed.\n--> Working on IO::Socket::SSL\nFetching
http://hCPAN2.sde.rdlabs.hpecorp.net/authors/id/S/SU/SULLR/IO-Socket-SSL-2.066.tar.gz ... OK\n==> Found dependencies:
Net::SSLeay\n! Finding Net::SSLeay on cpanmetadb failed.\n! Finding Net::SSLeay on search.cpan.org failed.\n--> Working
on Net::SSLeay\nFetching http://hCPAN2.sde.rdlabs.hpecorp.net/authors/id/C/CH/CHRISN/Net-SSLeay-1.88.tar.gz ...
OK\nConfiguring Net-SSLeay-1.88 ... OK\nBuilding Net-SSLeay-1.88 ... FAIL\n! Installing Net::SSLeay failed. See
/root/.cpanm/build.log for details.\n! Bailing out the installation for IO-Socket-SSL-2.066. Retry with --prompt or
--force.\n! Finding LWP::Protocol::https on cpanmetadb failed.\n! Finding LWP::Protocol::https on search.cpan.org
failed.\n--> Working on LWP::Protocol::https\nFetching
http://hCPAN2.sde.rdlabs.hpecorp.net/authors/id/O/OA/OALDERS/LWP-Protocol-https-6.07.tar.gz ... OK\nConfiguring
LWP-Protocol-https-6.07 ... OK\n==> Found dependencies: IO::Socket::SSL\nBuilding LWP-Protocol-https-6.07 ...
OK\nSuccessfully installed LWP-Protocol-https-6.07\n! Finding XML::Parser on cpanmetadb failed.\n! Finding XML::Parser
on search.cpan.org failed.\n--> Working on XML::Parser\nFetching
http://hCPAN2.sde.rdlabs.hpecorp.net/authors/id/T/TO/TODDR/XML-Parser-2.44.tar.gz ... OK\nConfiguring XML-Parser-2.44
... OK\nBuilding XML-Parser-2.44 ... FAIL\n! Installing XML::Parser failed. See /root/.cpanm/build.log for details.\n!
Bailing out the installation for SOAP-Lite-1.27. Retry with --prompt or --force.\n1 distribution installed\n"}

Could you help me with this failure?

Hello Keith,

you need to install the following library development packages:

Debian / Ubuntu :

   - libexpat1-dev # XML::Parser
   - libssl-dev # SOAP::Lite
   - zlib1g-dev # SOAP::Lite

RedHat:

    - expat-devel # XML::Parser

Regards
         Racke

Hi Stefan,

I’ve installed:

Debian/Ubuntu

  • libexpat1-dev
  • libssl-dev
  • zlib1g-dev

RedHat

  • expat-devel

I tweaked the tasks again:

Hi Stefan,

I've installed:

Debian/Ubuntu
- libexpat1-dev
- libssl-dev
- zlib1g-dev

RedHat
- expat-devel

I tweaked the tasks again:

---
- hosts: all
remote_user: root

tasks:
- name: copy MyConfig.pm to the correct directory on remote host(s)
template:
src: ../../../library/conf/debian/debian-myconfig.pm
dest: /root/.cpan/CPAN/MyConfig.pm
- name: Install cpanm on Debian/Ubuntu
apt:
name: cpanminus
when:
ansible_os_family|lower == 'debian'
- name: Install cpanm on RedHat
yum:
name: perl-App-cpanminus
when:
ansible_distribution|lower == 'redhat'
- name: Install cpanm (SUSE Linux)
zypper:
name: perl-App-cpanminus
when:
ansible_distribution|lower == 'sles'
- name: Install some CPAN modules
cpanm:
name: "{{ item }}"
notest: true
with_items:
- "HTTP::DAV"
- "Log::Log4perl"
- "SOAP::Lite"
- "Digest::SHA1"
- "AnyData"
- "Log::Dispatch::FileRotate"
- "Term::Shell"
- "Crypt::RC4"
environment:
PERL_CPANM_OPT: "--mirror http://hCPAN2.sde.rdlabs.hpecorp.net/"
...

Error:

failed: [ubuntu12ex6401] (item=HTTP::DAV) => {"ansible_loop_var": "item", "changed": false, "cmd": "/usr/bin/cpanm
HTTP::DAV -n", "item": "HTTP::DAV", "msg": "! Finding HTTP::DAV on cpanmetadb failed.\n! Finding HTTP::DAV on
search.cpan.org failed.\n! cannot open file '/root/.cpanm/sources/sde_cpan_mirror/02packages.details.txt.gz': No such
file or directory opening compressed index\n! Couldn't find module or a distribution HTTP::DAV ()\n"}

failed: [ubuntu12ex6401] (item=SOAP::Lite) => {"ansible_loop_var": "item", "changed": false, "cmd": "/usr/bin/cpanm
SOAP::Lite -n", "item": "SOAP::Lite", "msg": "! Finding SOAP::Lite on cpanmetadb failed.\n! Finding SOAP::Lite on
search.cpan.org failed.\n! cannot open file '/root/.cpanm/sources/sde_cpan_mirror/02packages.details.txt.gz': No such
file or directory opening compressed index\n! Couldn't find module or a distribution SOAP::Lite ()\n"}

Hello Keith,

looks like the target host cannot reach the CPAN mirror.

Regards
         Racke

Thanks Stefan!

Question: I need to use ansible_distribution in myconfig.pm, how do I go about doing that?

Do you know how I would use ansible_distribution in myconfig.pm

Hi Stefan,

I figured it out. Thank you for all of your help!