Problem to install or detect if passlib module is installed

Hi,

I installed passlib python like below :

- pip:
    name: "passlib"
  environment:
    http_proxy: "{{ proxy.url }}:{{ proxy.port }}"
    https_proxy: "{{ proxy.url }}:{{ proxy.port }}"

It works since many time.

I’ve a playbook to deploy configuration on DBServer, and execute the task above.

But since yesterday on some DBServer, i’ve got this error.

{
  "exception": "Traceback (most recent call last):\n  File \"/tmp/ansible_pip_payload_yosxm2nv/ansible_pip_payload.zip/ansible/modules/pip.py\", line 284, in <module>\n    from packaging.requirements import Requirement as parse_requirement\nModuleNotFoundError: No module named 'packaging'\n",
  "msg": "Failed to import the required Python library (packaging) on XXXXXXXXXgm'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",
  "invocation": {
    "module_args": {
      "name": [
        "passlib"
      ],
      "state": "present",
      "virtualenv_site_packages": false,
      "virtualenv_command": "virtualenv",
      "editable": false,
      "version": null,
      "requirements": null,
      "virtualenv": null,
      "virtualenv_python": null,
      "extra_args": null,
      "chdir": null,
      "executable": null,
      "umask": null
    }
  },
  "_ansible_no_log": false,
  "attempts": 5,
  "changed": false,
  "item": "passlib",
  "ansible_loop_var": "item",
  "_ansible_item_label": "passlib"
}

This module is already installed on the DBServer

[root@XXXXXXXXX log]#  pip3 install passlib
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Requirement already satisfied: passlib in /usr/local/lib/python3.6/site-packages

Do you know what’s wrong with my configuration please ?

Thanks for your help,

Matt

“msg”: “Failed to import the required Python library (packaging) on XXXXXXXXXgm’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”,

has a different path / python interpreter than

Requirement already satisfied: passlib in /usr/local/lib/python3.6/site-packages

(ansible is failing to find the module in /usr/bin/python3.12 while root is confirming its installed in /usr/local/lib/python3.6/site-packages)

1 Like

Hi @Lyle_McKarns,

Thanks for your reply.

I found this topic :

When i set the var [ansible_python_interpreter] in my playbook :

  vars:
     ansible_python_interpreter: "/usr/bin/python3"

The playbook works.

I found the difference between why it works on a DBServer and not working on other DBserver.
It’s what you mentionned with [ /usr/bin/python3.12]

On working DBServer, the python3.12 is not installed :

[root@OKDBSERVER check_mk]# ll /usr/bin/python3*
lrwxrwxrwx 1 root root 25 22 juin   2022 /usr/bin/python3 -> /etc/alternatives/python3
lrwxrwxrwx 1 root root 31 12 déc.  14:55 /usr/bin/python3.6 -> /usr/libexec/platform-python3.6
lrwxrwxrwx 1 root root 17 12 déc.  14:55 /usr/bin/python3.6-config -> python3.6m-config
lrwxrwxrwx 1 root root 32 12 déc.  14:55 /usr/bin/python3.6m -> /usr/libexec/platform-python3.6m
lrwxrwxrwx 1 root root 39 12 déc.  14:55 /usr/bin/python3.6m-config -> /usr/libexec/platform-python3.6m-config
lrwxrwxrwx 1 root root 46 12 déc.  14:55 /usr/bin/python3.6m-x86_64-config -> /usr/libexec/platform-python3.6m-x86_64-config
lrwxrwxrwx 1 root root 32 21 nov.   2023 /usr/bin/python3-config -> /etc/alternatives/python3-config

On not working DBServer python3.12 is installed :

[root@KODBSERVER etc]# ll /usr/bin/python3*
lrwxrwxrwx 1 root root   25 20 juin   2024 /usr/bin/python3 -> /etc/alternatives/python3
-rwxr-xr-x 1 root root 7752 12 déc.  14:05 /usr/bin/python3.12
lrwxrwxrwx 1 root root   31 12 déc.  14:55 /usr/bin/python3.6 -> /usr/libexec/platform-python3.6
lrwxrwxrwx 1 root root   17 12 déc.  14:55 /usr/bin/python3.6-config -> python3.6m-config
lrwxrwxrwx 1 root root   32 12 déc.  14:55 /usr/bin/python3.6m -> /usr/libexec/platform-python3.6m
lrwxrwxrwx 1 root root   39 12 déc.  14:55 /usr/bin/python3.6m-config -> /usr/libexec/platform-python3.6m-config
lrwxrwxrwx 1 root root   46 12 déc.  14:55 /usr/bin/python3.6m-x86_64-config -> /usr/libexec/platform-python3.6m-x86_64-config
lrwxrwxrwx 1 root root   32 20 juin   2024 /usr/bin/python3-config -> /etc/alternatives/python3-config

The alternative for python3 pointed target [/usr/bin/python3.6] :

[root@KODBSERVER etc]# ll /etc/alternatives/python3
lrwxrwxrwx 1 root root 18 20 juin   2024 /etc/alternatives/python3 -> /usr/bin/python3.6

I don’t know why python3.12 is installed on some DBServer…

Matt