Search code examples
ansiblepexpect

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


I am trying to use ansible to deploy our system. I used expect module in yml file and try using ansible-playbook to run it and got this error:

fatal: [192.168.100.132]: FAILED! => {"changed": false, "failed": true, "msg": "The pexpect python module is required"}

Then I downloaded the pexpect-4.2.1 package from pypi.python.org and install it by "python setup.py install". But it doesn't work and error never changed. What should I do to deal with the error ?

Some code from yml file:

- name: auth root
  expect:
    command: mysql_secure_installation
    responses:
      'Enter password for user root:': '{{password.stdout}}'
      'New password:': 'dtise123'
      'Re-enter new password:': 'dtise123'
      'Do you wish to continue with the password provided\?\(Press y\|Y for Yes, any other key for No\) :': 'y'
      'Remove anonymous users\? \(Press y\|Y for Yes, any other key for No\) :': 'y'
      'Disallow root login remotely\? \(Press y\|Y for Yes, any other key for No\) :': 'y'
      'Remove test database and access to it\? \(Press y\|Y for Yes, any other key for No\) :': 'y'
      'Reload privilege tables now\? \(Press y\|Y for Yes, any other key for No\) :': 'y'
    echo: yes

I downloaded the pexpect-4.2.1.tar.gz from pypi.python.org and did like this:

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

Solution

  • I installed it [pexpect] on the Ansible host. Do I need to install it on each node machine?

    Yes, modules are executed on target machines and prerequisites (if they exist) must be installed on them.