Ansible pylibssh import error

RHEL 8.10
ansible core 2.16.7
python version 3.12.1

I’m getting a error on every play I try to run, not really sure what happened since I’m still new to linux and ansible.

Error:
FAILED! => {“changed”: false, “msg”: “Failed to import the required Python library (ansible-pylibssh) on “server” Python /usr/bin/python3.12. 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”}

I tried installing pylibssh in appropriate location but I get the following error:

Not really sure what to do now. :frowning:

Hi
I assume you did the following to install pylibssh on your RHEL server ? pip3 install ansible-pylibssh ?
If yes, you can check the path where it is installed with pip3 show ansible-pylibssh

And then, compare if you ansible configuration know this location with : ansible --version at line ansible python module location

Maybe your module is properly installed but somewhere ansible isn’t aware of.

1 Like

cmd “pip3 show ansible-pylibssh” points to /.local/lib/python3.6/site-packages

I’m not really sure how to troubleshoot this issue

Ok and what does ansible --version show about python modules ?

ansible python module location = ./.local/lib/python3.12/site-packages/ansible

its pointing to a different location

Ok so it means your module is properly installed but ansible isn’t aware of where it is installed.
When you’re installing your module, you’re doing it with the same account that has been used to install ansible?

If no, try to switch your user and re-install pylibssh

Else, you can specify the folder where pip install your package, i.e :

pip install --target ./.local/lib/python3.12/site-packages/ansible ansible-pylibssh

It looks as though you have both python 3.6 and python 3.12 installed. This is perfectly fine as you can have both installed at the same time. But they do not share modules. It appears like ansible is using python 3.12 while pip3 is using python 3.6. This is why ansible can not find the module you installed using pip3. Try installing the modules you need with pip3.12 if you have it. You can also use “python3.12 -m pip” to run pip with python 3.12.

1 Like

I had this same problem. I ran sudo dnf install python3.12-pip on the ansible controller, and then ran python3.12 -m pip install --user ansible-pylibssh, and then I was able to run my playbook.

1 Like

I believe issue has been solved but I’m not sure what happened.

about 2 days ago I installed it again using “pip3 install --user ansible-pylibssh” and everything installed correctly and ansible works now

like i said it works now lol