When I use ansible module expect, I get this msg: The pexpect python module is required

19,842

As is typical with some of the modules in ansible you have to install certain Python modules on the remote server's side.

You can use the pip module to facilitate this through your ansible playbook like so:

- name: install pexpect
  pip:
    name: pexpect
  become: yes

Your distro may have these available as DEB or RPM files as well. If so you might want to install this Python module using the distro's package manager instead.

In your case it's likely that the Python you installed the pexpect module into is not the same one that ansible is using. In this case I'd use the system's package manager to install pexpect.

via package managers

on Debian/Ubuntu systems using apt-get:

$ sudo apt-get install python-pexpect

On Redhat distros (Fedora/CentOS):

$ sudo yum install -y pexpect

References

Share:
19,842

Related videos on Youtube

pyramid13
Author by

pyramid13

Updated on September 18, 2022

Comments

  • pyramid13
    pyramid13 over 1 year

    Some code from yml file:

    - name: --- run /opt/installer/bin/install.sh ---
      expect:
          command: /opt/installer/bin/install.sh
          responses:
            'Are you installing the application at the central data center? [yes/no default: yes]? [yes]': "\n"
            'What is the code of central data center [default: 01]? [01]': "\n"
            'What is ip or hostname of your server [default: localhost]? [localhost]': 'portal'
    

    and I installed pexpect 3.3 modules on both servers (ansible and target machines).

    [root@portal pexpect-3.3]# python setup.py install
    running install
    running build
    running build_py
    running install_lib
    running install_egg_info
    Removing /usr/lib/python2.7/site-packages/pexpect-3.3-py2.7.egg-info
    Writing /usr/lib/python2.7/site-packages/pexpect-3.3-py2.7.egg-info
    

    when I run playbook I get this error :

    TASK [ansible-portal : --- run /opt/installer/bin/install.sh ---] *************************************************************************
    fatal: [portal]: FAILED! => {"changed": false, "msg": "The pexpect python module is required"}
    

    More information :

    [root@ansible ansible]# ansible --version
    ansible 2.4.2.0
      config file = /etc/ansible/ansible.cfg
      configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
      ansible python module location = /usr/lib/python2.7/site-packages/ansible
      executable location = /usr/bin/ansible
      python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]