Skip to content
Advertisement

I get the message: “The pexpect python module is required” when running pexpect module on ansible

I am very new to ansible and I am trying to run a playbook to change root password of hosts so I am using the expect command of pexpect module. I successfully managed to install pexpect v4.7 with python 2.7 on the hosts and on the local server running the playbook. However when the playbook is being run, it fails with error: “The pexpect python module is required”

According to the requirements, pexpect and python are of the correct version

Files installed on hosts for pexpect and python: 
/usr/lib/python2.7/site-packages/pexpect
/usr/lib/python2.7/site-packages/pexpect-4.7.0-py2.7.egg-info
/usr/pexpect-4.7.0
/usr/pexpect-4.7.0/doc/api/pexpect.rst
/usr/pexpect-4.7.0/pexpect.egg-info
/usr/pexpect-4.7.0/tests/pexpectTest.py
/usr/pexpect-4.7.0/pexpect
/usr/pexpect-4.7.0/build/lib/pexpect

The playbook is as follows:

---
- hosts: all
  become: true

  tasks:
    - name: change password for root user
      expect: 
        command: passwd root
        responses: 
           (?i)password: "password"

Am I doing something wrong? Please help!

Advertisement

Answer

I managed to fix the issue by removing pexpect from all hosts then installing epel-release, pip and pexpect packages accordingly.

Advertisement