MJG
MJG

Reputation: 69

Ansible can not find pexpect but it is installed

Friends,

I am trying to execute a task using ansible.builtin.expect module on a CentOS 8 host and I am getting the following error:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError:
No module named 'pexpect'fatal: [gblix]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library 
(pexpect) on centos's Python /usr/libexec/platform-python. 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 ran pip3 install pexexpect and it is installed:

Requirement already satisfied: pexpect in /home/marcelo/.local/lib/python3.6/site-packages
Requirement already satisfied: ptyprogress>=0.5 in /home/marcelo/.local/lib/python3.6/site-packages
(from pexpect)

Then I ran ansible gblix -m setup | grep ansible_python_version and the output was "ansible_python_version": "3.6.8"

I checked as well the my /usr/bin directory and the output looks like this:

[marcelo@centos bin]$ ls -l | grep python
lrwxrwxrwx. 1 root root       9 Aug 31  2020 python2 -> python2.7
-rwxr-xr-x. 1 root root    8224 Aug 31  2020 python2.7
lrwxrwxrwx. 1 root root      25 May 16 14:52 python3 -> /etc/alternatives/python3
lrwxrwxrwx. 1 root root      31 Nov  4  2020 python3.6 -> /usr/libexec/platform-python3.6
lrwxrwxrwx. 1 root root      32 Nov  4  2020 python3.6m -> /usr/libexec/platform-python3.6m
lrwxrwxrwx. 1 root root      24 Feb 23 19:27 unversioned-python -> /etc/alternatives/python

If I am not wrong, pexpect is installed and ansible is using the right python interpreter. Any idea how can I solve this problem? I have a lot of information but I kind of don't know how to interpret it to find a solution?

Upvotes: 0

Views: 3532

Answers (1)

mdaniel
mdaniel

Reputation: 33231

A common solution to a missing python dependency in ansible is to just include the requirement in the playbook, to ensure that it is not only currently available, but will be available in the future, too

- name: ensure pexpect is installed in the playbook python
  pip:
    name: pexpect
    state: present

- name: now you can use that dependency in all cases
  expect: ...

Upvotes: 2

Related Questions