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

4,473 views
Skip to first unread message

jaadu

unread,
Jan 18, 2016, 8:26:15 AM1/18/16
to Ansible Project
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. 

Matt Martz

unread,
Jan 18, 2016, 9:15:54 AM1/18/16
to ansible...@googlegroups.com
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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/74da8bea-97f8-451b-9c4b-430d2ded0c10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

jaadu

unread,
Jan 18, 2016, 9:20:15 AM1/18/16
to Ansible Project
<face palm>

Thank you very much!
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

DJ

unread,
Feb 25, 2017, 4:15:30 AM2/25/17
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages