0

I'm using Ansible and testing a module: ansible.builtin.package_facts

- name: Gather the package facts
  ansible.builtin.package_facts:
  manager: auto

- name: Print the package facts
  ansible.builtin.debug:
    var: ansible_facts.packages

- name: Check whether a package called foobar is installed
  ansible.builtin.debug:
    msg: "{{ ansible_facts.packages }}"

But it will fail at the first task and the error is

TASK [test_role : Gather the package facts] ************************************
[WARNING]: Found "rpm" but Failed to import the required Python library (rpm)
on vsa12701896's Python /data/venv/bin/python3. Please read the module
documentation and install it 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
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Could not detect a supported package manager from the following list: ['rpm', 'apk', 'portage', 'pkg', 'pacman', 'apt', 'pkg_info'], or the required Python library is not installed. Check warnings for details."}

I'm sure I've installed that python3-rpm lib and confirm the python version is 3.9:

(venv) vsa12701896:/data/src # zypper search python3-rpm
Loading repository data...
Reading installed packages...

S | Name        | Summary                                       | Type
--+-------------+-----------------------------------------------+--------
i | python3-rpm | Python Bindings for Manipulating RPM Packages | package

    Note: For an extended search including not yet activated remote resources
    please use 'zypper search-packages'.
(venv) vsa12701896:/data/src # pip3 list|grep rpm
rpm                       0.2.0
(venv) vsa12701896:/data/src # python --version
Python 3.9.19

Where is the issue?

============================================== Update:

  1. on this host, there's no other python interpreter ... only this python3.9 installed
  2. that rpm package is installed --
(venv) vsa12701896:/data/venv/bin # python3 -m pip freeze | grep rpm
rpm==0.2.0
  1. by more check -- I find it looks this "rpm" packages got some problem on itself --

    (venv) vsa12701896:/data/venv/bin # python3 -c "import rpm; print(rpm.version)" Traceback (most recent call last): File "/data/venv/lib64/python3.9/site-packages/rpm/init.py", line 106, in shim_module_initializing NameError: name 'shim_module_initializing' is not defined

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "", line 1, in File "/data/venv/lib64/python3.9/site-packages/rpm/init.py", line 109, in initialize() File "/data/venv/lib64/python3.9/site-packages/rpm/init.py", line 98, in initialize raise ImportError( ImportError: Failed to import system RPM module. Make sure RPM Python bindings are installed on your system.

5
  • 2
    The error message says: "Please read the module documentation and install it 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". Did you do those things? Commented Aug 24, 2024 at 1:57
  • 2
    Note that it talks about the python interpreter that Ansible is >using<. If you have multiple python versions installed, or multiple python environments, it could be that Ansible is not using the python env that you installed "python3-rpm" into. (It looks Ansible is actually using a virtual environment at /data/venv/.) Commented Aug 24, 2024 at 2:02
  • 1
    I think pip3 might not be using the same version number as python3 interpreter that is being used by ansible. Could you run command python3 -m pip freeze | grep rpm to confirm if the python3 interpretter has rpm installed? If not, you can use the command python3 -m pip install rpm to install it Commented Aug 24, 2024 at 4:36
  • Where have you installed it? On the Control Node and or on all Remote Nodes? Commented Aug 25, 2024 at 17:36
  • thanks for your help. I've edit the question with details. Commented Aug 27, 2024 at 7:19

1 Answer 1

0

After test, I found it's due to the "rpm" lib is incompatible with python3.9, it's only compatible with python3.6 or lower --

I prepared two venvs -- venv36 -- python3.6 venv -- python3.9

(venv) vsa12701896:/data/venv/bin # python3.9 -c "import rpm; print(rpm.__version__)"
Traceback (most recent call last):
  File "/data/venv/lib64/python3.9/site-packages/rpm/__init__.py", line 106, in <module>
    _shim_module_initializing_
NameError: name '_shim_module_initializing_' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/data/venv/lib64/python3.9/site-packages/rpm/__init__.py", line 109, in <module>
    initialize()
  File "/data/venv/lib64/python3.9/site-packages/rpm/__init__.py", line 98, in initialize
    raise ImportError(
ImportError: Failed to import system RPM module. Make sure RPM Python bindings are installed on your system.
(venv) vsa12701896:/data # cd venv36/bin
(venv) vsa12701896:/data/venv36/bin # source activate
(venv) vsa12701896:/data/venv36/bin # python3.6 -c "import rpm; print(rpm.__version__)"
4.14.3
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.