ansible cpanm doesn't find modules - 'NoneType' object is not iterable

379 views Asked by At

I'm trying to install multiple Perl-Modules using ansible community.general.cpanm:

- name: Install perl packages
  debug:
    msg: "{{ item }}"
  loop: "{{ imperia__cpan_packages }}"

- name: Install perl packages
  cpanm:
    name: "{{ item }}"
  loop: "{{ imperia__cpan_packages }}"

First I thought I made a mistake in syntax but then I found out as soon as the module-name is more then a single word I'm getting this error:

TASK [myplaybook : Install perl packages] *****************************************
ok: [localimp] => (item=CPAN) => {
    "msg": "CPAN"
}
ok: [localimp] => (item=DBI) => {
    "msg": "DBI"
}
ok: [localimp] => (item=DBD::SQLite) => {
    "msg": "DBD::SQLite"
}
ok: [localimp] => (item=JCRISTY/Image-Magick-6.9.12-1.tar.gz) => {
    "msg": "JCRISTY/Image-Magick-6.9.12-1.tar.gz"
}

TASK [myplaybook : Install perl packages] *****************************************
ok: [localimp] => (item=CPAN) => {"ansible_loop_var": "item", "binary": null, "changed": false, "item": "CPAN", "name": "CPAN", "version": null}
ok: [localimp] => (item=DBI) => {"ansible_loop_var": "item", "binary": null, "changed": false, "item": "DBI", "name": "DBI", "version": null}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: 'NoneType' object is not iterable
failed: [localimp] (item=DBD::SQLite) => {"ansible_loop_var": "item", "binary": null, "changed": false, "item": "DBD::SQLite", "msg": "Module failed with exception: 'NoneType' object is not iterable", "name": "DBD::SQLite", "output": {"binary": null, "name": "DBD::SQLite", "version": null}, "vars": {"binary": null, "name": "DBD::SQLite", "version": null}, "version": null}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: 'NoneType' object is not iterable
failed: [localimp] (item=JCRISTY/Image-Magick-6.9.12-1.tar.gz) => {"ansible_loop_var": "item", "binary": null, "changed": false, "item": "JCRISTY/Image-Magick-6.9.12-1.tar.gz", "msg": "Module failed with exception: 'NoneType' object is not iterable", "name": "JCRISTY/Image-Magick-6.9.12-1.tar.gz", "output": {"binary": null, "name": "JCRISTY/Image-Magick-6.9.12-1.tar.gz", "version": null}, "vars": {"binary": null, "name": "JCRISTY/Image-Magick-6.9.12-1.tar.gz", "version": null}, "version": null}

PLAY RECAP *********************************************************************

My research so far wasn't quite successful because the Error Module failed with exception: 'NoneType' object is not iterable can have way to many reasons...

2

There are 2 answers

0
Benedikt Köppel On

It seems to happen for Perl modules that have more than one word in the name. I could not fix the issue, but here is my workaround:

- name: Install Perl libraries
  become: false
  shell:
    cmd: cpanm -l ~/.perl/ install App::RecordStream
    creates: /home/me/.perl/bin/recs
0
user19792824 On

I was getting the same error. In my case, I did not have cpanm installed remotely, and when I yum installed cpanm, it worked fine.

https://docs.ansible.com/ansible/2.9/modules/cpanm_module.html

Please note that http://search.cpan.org/dist/App-cpanminus/bin/cpanm, cpanm must be installed on the remote host.

example:

- name: Installing CPANM
  yum: pkg=perl-App-cpanminus