# CPAN Modules

**URL:** <https://forum.ansible.com/t/cpan-modules/30862>\
**Category:** Ansible Project\
**Tags:** rhel, ubuntu\
**Created:** [July 24, 2019, 8:17pm UTC](https://forum.ansible.com/t/cpan-modules/30862 "2019-07-24T20:17:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keith\_Mills](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@Keith\_Mills](https://forum.ansible.com/u/Keith_Mills)\
**Post date:** [July 24, 2019, 8:17pm UTC](https://forum.ansible.com/t/cpan-modules/30862/1 "2019-07-24T20:17:18Z")

</div>

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

| |

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [July 25, 2019, 12:11pm UTC](https://forum.ansible.com/t/cpan-modules/30862/2 "2019-07-25T12:11:43Z")

</div>

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](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  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Keith\_Mills](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@Keith\_Mills](https://forum.ansible.com/u/Keith_Mills)\
**Post date:** [July 25, 2019, 2:12pm UTC](https://forum.ansible.com/t/cpan-modules/30862/3 "2019-07-25T14:12:56Z")

</div>

Hi Stefan,

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

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [July 25, 2019, 3:54pm UTC](https://forum.ansible.com/t/cpan-modules/30862/4 "2019-07-25T15:54:24Z")

</div>

> 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/&quot](http://hCPAN2.sde.rdlabs.hpecorp.net/&quot);  
> ...
> 
> 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](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](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](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](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](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](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](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](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](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 :

&nbsp;&nbsp;&nbsp;- libexpat1-dev # XML::Parser  
&nbsp;&nbsp;&nbsp;- libssl-dev # SOAP::Lite  
&nbsp;&nbsp;&nbsp;- zlib1g-dev # SOAP::Lite

RedHat:

&nbsp;&nbsp;&nbsp;&nbsp;- expat-devel # XML::Parser

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Keith\_Mills](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@Keith\_Mills](https://forum.ansible.com/u/Keith_Mills)\
**Post date:** [July 25, 2019, 8:04pm UTC](https://forum.ansible.com/t/cpan-modules/30862/5 "2019-07-25T20:04:46Z")

</div>

Hi Stefan,

I’ve installed:

Debian/Ubuntu

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

RedHat

- expat-devel

I tweaked the tasks again:

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [July 26, 2019, 5:35am UTC](https://forum.ansible.com/t/cpan-modules/30862/6 "2019-07-26T05:35:31Z")

</div>

> 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/&quot](http://hCPAN2.sde.rdlabs.hpecorp.net/&quot);  
> ...
> 
> 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  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Keith\_Mills](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@Keith\_Mills](https://forum.ansible.com/u/Keith_Mills)\
**Post date:** [July 26, 2019, 1:34pm UTC](https://forum.ansible.com/t/cpan-modules/30862/7 "2019-07-26T13:34:07Z")

</div>

Thanks Stefan!

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

---

<div class="post-metadata">

**Author:** ![Keith\_Mills](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@Keith\_Mills](https://forum.ansible.com/u/Keith_Mills)\
**Post date:** [July 29, 2019, 3:57pm UTC](https://forum.ansible.com/t/cpan-modules/30862/8 "2019-07-29T15:57:16Z")

</div>

Do you know how I would use ansible\_distribution in [myconfig.pm](http://myconfig.pm/)

---

<div class="post-metadata">

**Author:** ![Keith\_Mills](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@Keith\_Mills](https://forum.ansible.com/u/Keith_Mills)\
**Post date:** [July 29, 2019, 6:50pm UTC](https://forum.ansible.com/t/cpan-modules/30862/9 "2019-07-29T18:50:46Z")

</div>

Hi Stefan,

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