# Can't get expect to work - The pexpect python module is required

**URL:** <https://forum.ansible.com/t/cant-get-expect-to-work-the-pexpect-python-module-is-required/20241>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [January 16, 2016, 11:16pm UTC](https://forum.ansible.com/t/cant-get-expect-to-work-the-pexpect-python-module-is-required/20241 "2016-01-16T23:16:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaadu](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jaadu](https://forum.ansible.com/u/jaadu)\
**Post date:** [January 16, 2016, 11:16pm UTC](https://forum.ansible.com/t/cant-get-expect-to-work-the-pexpect-python-module-is-required/20241/1 "2016-01-16T23:16:28Z")

</div>

I am playing around with Ansible on Ubuntu 14.04 VMs and can’t seem to get expect to work. I have tried installing ansible and pexpect via apt-get and pip, but keep getting the following error:

> fatal: [vagrant]: FAILED! =\> {“changed”: false, “failed”: true, “invocation”: {“module\_args”: {“chdir”: null, “command”: “domainjoin-cli leave user”, “creates”: null, “echo”: false, “removes”: null, “responses”: {“password”: “password”}, “timeout”: 30}, “module\_name”: “expect”}, “msg”: “The pexpect python module is required”}

“pip freeze” says:

> Jinja2==2.8  
> Landscape-Client==14.12  
> MarkupSafe==0.23  
> PAM==0.4.2  
> PyYAML==3.11  
> Twisted-Core==13.2.0  
> ansible==2.0.0.2  
> apt-xapian-index==0.45  
> argparse==1.2.1  
> chardet==2.0.1  
> colorama==0.2.5  
> configobj==4.7.2  
> ecdsa==0.13  
> html5lib==0.999  
> paramiko==1.16.0  
> pexpect==4.0.1  
> ptyprocess==0.5  
> pyOpenSSL==0.13  
> pycrypto==2.6.1  
> pyserial==2.6  
> python-apt==0.9.3.5ubuntu2  
> python-debian==0.1.21-nmu2ubuntu2  
> requests==2.2.1  
> six==1.5.2  
> ssh-import-id==3.21  
> urllib3==1.7.1  
> wheel==0.24.0  
> wsgiref==0.1.2  
> zope.interface==4.0.5

my playbook code:

> - hosts: local\_lab  
> remote\_user: vagrant  
> become: true  
> vars:  
> admin\_user: “{{user}}”  
> admin\_pass: “{{pass}}”  
> tasks:
> - name: pbis-open - remove old - leave domain  
> expect:  
> command: domainjoin-cli leave {{admin\_user}}  
> responses:  
> (?i)password: “{{admin\_pass}}”

my cli command:

> ansible-playbook -vvvv pbis-open.yml --inventory-file=lab --extra-vars=“user=user pass=password”

Thanks for your time. Any help is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 18, 2016, 2:15pm UTC](https://forum.ansible.com/t/cant-get-expect-to-work-the-pexpect-python-module-is-required/20241/2 "2016-01-18T14:15:48Z")

</div>

pexpect must be installed on the hosts that you are targeting. So if you want to run a command with expect on a remote server called server1, pexpect must be installed on server1.

You may wish to run an apt task to instal pexpect on all remote servers before trying to use the expect module.

---

<div class="post-metadata">

**Author:** ![jaadu](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jaadu](https://forum.ansible.com/u/jaadu)\
**Post date:** [January 18, 2016, 2:20pm UTC](https://forum.ansible.com/t/cant-get-expect-to-work-the-pexpect-python-module-is-required/20241/3 "2016-01-18T14:20:15Z")

</div>

Thank you very much!

---

<div class="post-metadata">

**Author:** ![DJ1](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DJ1](https://forum.ansible.com/u/DJ1)\
**Post date:** [February 25, 2017, 7:53am UTC](https://forum.ansible.com/t/cant-get-expect-to-work-the-pexpect-python-module-is-required/20241/4 "2017-02-25T07:53:32Z")

</div>

I would like to add another note for other potential users (including myself in the future) that may encounter this problem but may be attributed to a different root cause. I came across this problem and found out that it was due to the pexpect version difference. My ansible was running using Python 3.5 where my pexpect was installed for Python 2.7. I had to install pexpect for Python 3.5 and that fixed the problem. This problem will likely arise if you are using virtual environments.
