Failed to import the required Python library (pexpect) on sejenk01's Python /usr/bin/python.

SUMMARY

We are getting below errors if using the except module in the ansible playbooks.
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named ptyprocess fatal: [sejenk01]: FAILED! => {“changed”: false, “msg”: “Failed to import the required Python library (pexpect) on sejenk01’s Python /usr/bin/python. Please read module documentation and install 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”}

PLAYBOOK:- name: Creating a OSB domain
expect:
command: “{{ wldt_home }}/weblogic-deploy/bin/createDomain.sh -run_rcu -oracle_home {{ oracle_home }} -domain_parent {{ domainParentDir }} -domain_type OSB -model_file {{ oracle_jinja_templates }}/OsbDomainModel.yaml -rcu_db {{ connection_string }} -rcu_prefix {{ schema_prefix }} -rcu_db_user {{ db_user }}”
responses:
‘Enter the RCU database SYS user password’: “{{ db_password }}”
‘Please enter the RCU Schema password’: “{{ schema_password }}”
timeout: 1200
ISSUE TYPE- Bug Report
COMPONENT NAME

ansible

ANSIBLE VERSION

ansible 2.9.10
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/Users/prathapdasari/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /Library/Python/2.7/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.16 (default, Jun 5 2020, 22:59:21) [GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc-
PrathapDasaris-MacBook-Pro:ansible-wdt prathapdasari$

python --version
Python 2.7.5

OS / ENVIRONMENT

Linux sefmw01 4.1.12-124.39.5.1.el7uek.x86_64 #2 SMP Tue Jun 9 20:03:37 PDT 2020 x86_64 x86_64 x86_64 GNU/Linux

EXPECTED RESULTS

it should be completed on remote servers without any errors.

Hi

SUMMARY

We are getting below errors if using the except module in the ansible playbooks.

Did you actually read the error? It says exactly what is wrong, with
hints on how to fix it:

Hi,

The package already installed on the remote host but still, it´s failing with the above error.
[root@sejenk01 ~]# yum install pexpect
Loaded plugins: ulninfo
Package pexpect-2.3-11.el7.noarch already installed and latest version
Nothing to do

Regards,
Prathap

Ansible needs the python pexpect package.

Ok. Apologies for this because I am new to scripting and doing the first time so little confused.

Now I need to install python packages on my remote hots right ?. If yes, can I follow the below steps to install python packages?

mv pexpect-4.2.1.tar.gz /usr/local/src/
cd /usr/local/src
tar zxvf pexpect-4.2.1.tar.gz
cd pexpect-4.2.1
python setup.py install

Regards,
Prathap