Rocky9 & Ansible + community collections

Itroductory data:

  1. management machine Rocky 9.2 with installed Ansible and python
Ansible & python version
[svc_ansible@srv-ansible01 playbooks]$ ansible --version
ansible [core 2.14.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/svc_ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /home/svc_ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.2 (main, May 24 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True
  1. managed stations with Rocky 9.2
  2. managed mikrotiks with RouterOS

Typical operations between management machine and managed stations - work fine.

example of typical operation
[svc_ansible@srv-ansible01 playbooks]$ ansible linux_servers -m shell -a "cat /etc/rocky-release"
vh-rock01.abc.lab CHANGED | rc=0 >>
Rocky Linux release 9.2 (Blue Onyx)
srv-zabbix01.abc.lab | CHANGED | rc=0 >>
Rocky Linux release 9.2 (Blue Onyx)
srv-dbs02.abc.lab | CHANGED | rc=0 >>
Rocky Linux release 9.2 (Blue Onyx)
srv-app01.abc.lab | CHANGED | rc=0 >>
Rocky Linux release 9.2 (Blue Onyx)
srv-fs01.abc.lab | CHANGED | rc=0 >>
Rocky Linux release 9.2 (Blue Onyx)

Problem: Typical operations between management machine and managed mikrotiks - give a error:

error
[svc_ansible@srv-ansible01 playbooks]$ ansible-playbook test.yml
PLAY [Show users] *************************************************************************

TASK [get users] **************************************************************************
[WARNING]: ansible-pylibssh not installed, falling back to paramiko
fatal: [r02.abc.lab]: FAILED! => {"changed": false, "msg": "paramiko is not installed: No module named 'paramiko'"}

PLAY RECAP ********************************************************************************
r02.abc.lab              : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Config files:

/etc/ansible/hosts
# This is the ansible 'hosts' file.

[linux_servers:children]
rocky_linux

[routers]
r02.abc.lab

[routers:vars]
ansible_network_os=community.routeros.routeros
ansible_user=svc_anslibe
ansible_connection=ansible.netcommon.network_cli

[rocky_linux]
vh-rock01.abc.lab
srv-zabbix01.abc.lab
srv-dbs02.abc.lab
srv-app01.abc.lab
srv-fs01.abc.lab
/etc/ansible/ansible.cfg

in connection with the character limit in the topic posted on pastebin

test.yml
- name: "Show users"
  hosts: routers
  gather_facts: no
  remote_user: svc_anslibe

  tasks:
    - name: get users
      community.routeros.command:
        commands:
          - /user print
      register: output

    - name: Print output
      ansible.builtin.debug:
        var: output.stdout_lines

I have tried re-installing the packages:

ansible-pylibssh
[svc_ansible@srv-ansible01 playbooks]$ pip install ansible-pylibssh
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: ansible-pylibssh in /home/svc_ansible/.local/lib/python3.9/site-packages (1.1.0)
WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
distutils: /home/svc_ansible/.local/lib/python3.9/site-packages
sysconfig: /home/svc_ansible/.local/lib64/python3.9/site-packages
WARNING: Additional context:
user = True
home = None
root = None
prefix = None
paramiko
[svc_ansible@srv-ansible01 playbooks]$ pip install paramiko
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: paramiko in /usr/local/lib/python3.9/site-packages (3.2.0)
Requirement already satisfied: pynacl>=1.5 in /usr/local/lib64/python3.9/site-packages (from paramiko) (1.5.0)
Requirement already satisfied: cryptography>=3.3 in /usr/local/lib64/python3.9/site-packages (from paramiko) (41.0.2)
Requirement already satisfied: bcrypt>=3.2 in /usr/local/lib64/python3.9/site-packages (from paramiko) (4.0.1)
Requirement already satisfied: cffi>=1.12 in /usr/local/lib64/python3.9/site-packages (from cryptography>=3.3->paramiko) (1.15.1)
Requirement already satisfied: pycparser in /usr/local/lib/python3.9/site-packages (from cffi>=1.12->cryptography>=3.3->paramiko) (2.21)
WARNING: Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
distutils: /home/svc_ansible/.local/lib/python3.9/site-packages
sysconfig: /home/svc_ansible/.local/lib64/python3.9/site-packages
WARNING: Additional context:
user = True
home = None
root = None
prefix = None

but that doesn’t fix the problem.
Please advice on how to fix this problem!

Hey!
Since the last minor releases of 8 and 9 ansible uses python3.11, so you have to run python3.11 -m pip install paramiko to get paramiko

Btw, as pip says, you should always use python3 -m pip instead of pip

I did the update python ftom 3.9 → 3.11.4, then install

python3.11 -m pip install ansible-pylibssh
python3.11 -m pip install paramiko

and this resolve my problem.
thx! :grinning:

1 Like

I hope you didn’t break your system reading this link :slight_smile:
There is literally nothing to do, ansible-core depends on the python3.11 which is in the AppStream repo, all you maybe have to do is install python3.11-pip and then use python3.11 -m pip (it is also possible to set the alternatives link for python3 to 3.11 but might break other installed applications) (make sure you never change the platform-python link that will definitely break stuff)

If you manually build python, you will have to update it manually (beside SELinux might be mad at you if the executables are not put in the correct directories).