开发者问题收集

ansible cpanm 找不到模块-'NoneType'对象不可迭代

2022-04-04
413

我尝试使用 ansible community.general.cpanm 安装多个 Perl 模块:

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

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

一开始我以为我犯了一个语法错误,但后来我发现,只要模块名称超过一个单词,我就会收到此错误:

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 *********************************************************************

到目前为止,我的研究还不是很成功,因为错误 模块失败并出现异常:'NoneType' 对象不可迭代 可能有很多原因……

2个回答

我遇到了同样的错误。就我而言,我没有远程安装 cpanm,当我使用 yum 安装 cpanm 时,它运行正常。

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.

示例:

- name: Installing CPANM
  yum: pkg=perl-App-cpanminus
user19792824
2022-08-18

这似乎发生在名称中包含多个单词的 Perl 模块中。我无法修复此问题,但这是我的解决方法:

- name: Install Perl libraries
  become: false
  shell:
    cmd: cpanm -l ~/.perl/ install App::RecordStream
    creates: /home/me/.perl/bin/recs
Benedikt Köppel
2022-08-01