expect module throw exception when decoding responses dict

Hi,

When I ran this sample:

  • expect:
    command: passwd master
    responses:
    (?i)password: “234567”

sudo: yes
register: hello

name: Debug hello.stdout as part of a string

  • debug: msg={{ hello.stdout }}

Print all contents of the shell task’s output.

  • debug: var=hello

It threw these exception:
TASK [router : expect command=passwd master responses={u’Enter new UNIX password’: u’234567’}] ***
fatal: [147.128.112.106]: FAILED! => {“changed”: false, “failed”: true, “msg”: "
BECOME-SUCCESS-djevcomgojpacemokygqkwzibvtnyxno
Traceback (most recent call last):
File "/home/xjigzho_local/.ansible/tmp/ansible-tmp-1454491175.33-231534496369283/expect", line 2084, in
main()
File "/home/xjigzho_local/.ansible/tmp/ansible-tmp-1454491175.33-231534496369283/expect", line 155, in main
events=events, cwd=chdir, echo=echo)
File "/usr/lib/python2.7/dist-packages/pexpect/init.py", line 224, in runu
env=env, _spawn=spawnu, **kwargs)
File "/usr/lib/python2.7/dist-packages/pexpect/init.py", line 233, in _run
cwd=cwd, env=env, **kwargs)
File "/usr/lib/python2.7/dist-packages/pexpect/init.py", line 1754, in init
super(spawnu, self).init(*args, **kwargs)
TypeError: init() got an unexpected keyword argument ‘echo’
Exception AttributeError: "‘spawnu’ object has no attribute ‘closed’" in <bound method spawnu.del of <pexpect.spawnu object at 0x7f346cfad410>> ignored
", “parsed”: false}

Something wrong with expect module. Why it threw excption?
Thanks.

It appears you may not be using a new enough version of pexpect. What version do you have installed?

Hi Matt,

I have updated the pexpect this time, but it still threw this exception:

root@073891424fc3:/opt/ansible/ansible/samples# pip install pexpect
Downloading/unpacking pexpect
Downloading pexpect-4.0.1.tar.gz (143kB): 143kB downloaded

Downloading ptyprocess-0.5.1-py2.py3-none-any.whl
Installing collected packages: pexpect, ptyprocess
Running setup.py install for pexpect
File “/usr/local/lib/python2.7/dist-packages/pexpect/async.py”, line 16
transport, pw = yield from asyncio.get_event_loop()
^
SyntaxError: invalid syntax

Successfully installed pexpect ptyprocess
Cleaning up…
root@073891424fc3:/opt/ansible/ansible/samples# pip list
alabaster (0.7.7)
ansible (2.0.0)


pexpect (4.0.1)

root@073891424fc3:/opt/ansible/ansible/samples# ansible-playbook site.yml -c paramiko

PLAY [Generate router configuration files] *************************************

TASK [setup] *******************************************************************
ok: [147.128.112.106]

TASK [router : expect command=sudo passwd master responses={u’(?i)password’: u’234567’}] ***
fatal: [147.128.112.106]: FAILED! => {“changed”: false, “failed”: true, “msg”: “Traceback (most recent call last):\r\n File "/home/xjigzho_local/.ansible/tmp/ansible-tmp-1454563825.52-194772997459918/expect", line 2084, in \r\n main()\r\n File "/home/xjigzho_local/.ansible/tmp/ansible-tmp-1454563825.52-194772997459918/expect", line 155, in main\r\n events=events, cwd=chdir, echo=echo)\r\n File "/usr/lib/python2.7/dist-packages/pexpect/init.py", line 224, in runu\r\n env=env, _spawn=spawnu, **kwargs)\r\n File "/usr/lib/python2.7/dist-packages/pexpect/init.py", line 233, in _run\r\n cwd=cwd, env=env, **kwargs)\r\n File "/usr/lib/python2.7/dist-packages/pexpect/init.py", line 1754, in init\r\n super(spawnu, self).init(*args, **kwargs)\r\nTypeError: init() got an unexpected keyword argument ‘echo’\r\nException AttributeError: "‘spawnu’ object has no attribute ‘closed’" in <bound method spawnu.del of <pexpect.spawnu object at 0x7fcf859b83d0>> ignored\r\n”, “parsed”: false}

PLAY RECAP *********************************************************************
147.128.112.106 : ok=1 changed=0 unreachable=0 failed=1

BRs/Jay

2016/2/4 Thursday UTC+8AM10:41:31,Matt Martz reply:

When you upgraded it put pexpect in /usr/local/lib however the error from your Ansible run indicates that pexpect was used from /usr/lib

Also, make sure you are upgrading pexpect on the remote target machine.

Hi Matt.

I have reinstalled ansible and pexpect and then it works.
I appreciate your comments and help.
Thanks.