Ansible package_facts在SLES 15执行失败:无法导入rpm模块
问题:Ansible package_facts模块在SLES 15执行失败,SLES 12运行正常
任务代码
- name: Gathering facts ansible.builtin.package_facts: manager: auto
报错信息
警告内容
[WARNING]: Found "rpm" but Failed to import the required Python library (rpm) on SLES15's Python /usr/bin/python3.6. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter
错误信息
FAILED! => {"changed": false, "msg": "Could not detect a supported package manager from the following list: ['pkg', 'portage', 'apt', 'rpm'], or the required Python library is not installed. Check warnings for details."}
已尝试操作及后续报错
- 已在远程SLES 15节点安装
rpm包,但问题未解决 - 在Python交互shell中导入
rpm模块时,出现如下错误:
"Failed to import system RPM module." ImportError: Failed to import system RPM module. Make sure RPM Python bindings are installed on your system.
解决方法
SLES 15中,Python3对应的RPM绑定库并非默认的rpm包,而是单独的python3-rpm包,执行以下步骤修复:
- 在SLES 15远程节点运行安装命令:
zypper install python3-rpm
- 安装完成后,重新执行Ansible的package_facts任务即可正常运行。
内容的提问来源于stack exchange,提问作者Ash
相关产品推荐
相关产品推荐

