venom619
(James)
October 3, 2024, 5:56pm
1
Hello,
I keep getting the following errors when I run my cisco playbook:
Failed to import the required Python library (ansible-pylibssh) on itbckt-01’s 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
ansible --version shows
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.12/site-packages/ansible
ansible collection location = /home/n40059_su/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.12.3 (main, Jun 19 2024, 10:06:03) [GCC 8.5.0 20210514 (Red Hat 8.5.0-22)] (/usr/bin/python3.12)
jinja version = 3.1.2
libyaml = True
python3 --version
Python 3.6.8
Ive set the ‘ansible_python_interpreter’ everywhere. In the play file like this:
- name: capture show output
hosts: routers
gather_facts: no
connection: network_cli
vars:
ansible_python_interpreter: /usr/bin/python3.6
ansible_network_os: cisco.ios.ios
tasks:
- name: show run
ios_command:
commands:
- show version
register: config
- name: save output to local directory
copy:
content: "{{ config.stdout | replace('\\n', '\n') }}"
dest: "show-output/{{ inventory_hostname }}.ios
in the host file:
[routers]
172.x.0.4
172.x.0.2
172.x.0.1
172.28.0.4
172.28.0.5
#ansible_python_interpreter: /usr/bin/python3.6
[all]
ansible_connection=ssh
ansible_python_interpreter: /usr/bin/python3.6
ansible_connection: ansible.netcommon.network_cli
ansible_network_os: ios
ansible_network_os: nxos
It still complains.
please help!
jiholland
(Jørn Ivar)
October 3, 2024, 6:27pm
2
Ansible is using python3.12
So you need to remove this
From the error message, it looks like you are missing ansible-pylibssh
which should be installed with the same Python interpreter that Ansible is using.
python3.12 -m pip install ansible-pylibssh
venom619
(James)
October 3, 2024, 6:42pm
3
sudo python3.12 -m pip install ansible-p ylibssh
/bin/python3.12: No module named pip3
I keep getting this. And ive installed the package with:
sudo pip3 install ansible-pylibssh
jiholland
(Jørn Ivar)
October 3, 2024, 6:52pm
4
You don’t want to use sudo
when installing packages with pip.
What is the output of $ pip3 --version
?
jiholland
(Jørn Ivar)
October 3, 2024, 7:11pm
5
Either way, I’m pretty sure pip3 is pointing to python3.6, so this does not help since Ansible is using Python3.12.
I see that you are on rhel 8.
venom619:
(Red Hat 8.5.0-22)
And I guess you installed python3.12 with dnf/yum, but you probably didn’t install pip since this is failing:
So you want to install pip for python3.12 and then ansible-pylibssh.
$ sudo dnf install python3.12-pip
$ python3.12 -m pip install ansible-pylibssh
venom619
(James)
October 3, 2024, 7:49pm
6
jiholland:
ansible-pylibssh
Hi so if i wanted to download ansible-pylibssh offline, would I get these files here? ansible-pylibssh · PyPI
If so how would i install it?
it looks like its already installed with pip 3. can I just make ansible use 3.6 python version?
pip3 show ansible-pylibssh
Name: ansible-pylibssh
Version: 1.2.0.post4
Summary: Python bindings for libssh client specific to Ansible use case
Home-page: https://github.com/ansible/pylibssh
Author: Ansible, Inc.
Author-email: info+github/ansible/pylibssh@ansible.com
License: LGPLv2+
Location: /usr/local/lib64/python3.6/site-packages
Requires:
venom619
(James)
October 3, 2024, 8:03pm
7
jiholland:
pip3 --version
pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
jiholland
(Jørn Ivar)
October 3, 2024, 8:27pm
8
Yes.
Something like this:
python3 -m pip install --user --no-index --find-links . --upgrade ansible_pylibssh-1.2.2-cp312-cp312-manylinux_2_28_x86_64.whl
Newer versions of Ansible (for the controller) do not support that.
I suggest you take a look at this document:
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-and-upgrading-ansible-with-pip
I also recommend creating and activating a virtual environment in Python before pip installing Ansible and other packages.
venom619
(James)
October 4, 2024, 2:49pm
9
Ok so i did try that for that specific version. I just copied it on roots dir and got the following:
ansible_pylibssh-1.2.2-cp312-cp312-manylinux_2_28_x86_64.whl is not a supported wheel on this platform.
jiholland
(Jørn Ivar)
October 4, 2024, 5:41pm
10
That was just an example. You will have to get the compatible version with your OS/platform.