# Issues with expect

**URL:** <https://forum.ansible.com/t/issues-with-expect/20200>\
**Category:** Ansible Project\
**Created:** [January 13, 2016, 4:53pm UTC](https://forum.ansible.com/t/issues-with-expect/20200 "2016-01-13T16:53:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Constant](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Mark\_Constant](https://forum.ansible.com/u/Mark_Constant)\
**Post date:** [January 13, 2016, 4:53pm UTC](https://forum.ansible.com/t/issues-with-expect/20200/1 "2016-01-13T16:53:22Z")

</div>

I installed ansible 2.0 using pip. I am trying to use the expect command and it is not working. When I try to add  
-name: Install Program  
expect:  
command: some command  
responses:

I get ERROR! Syntax Error while loading YAML.

If I take out the -name and do

-expect:  
command: some command  
responses:

It says -expect is not a valid attribute for a task

Are the extras modules installed when you use pip now? I tried pip install ansible-modules-extras but it said it could not find a version that satisfies the requirements. My python (installed using yum) version is 2.7 and my pexect version was just installed using pip and it above 3.3. When I did yum the expect version looked old.

Also when doing the responses is there much information on how the response should be formatted? In the ansible document I see something like (i?)password. Is there any documentation on what the (i?) means and thing such as do I need to type in the whole question that will be asked or can I do some kind of other matching like if the question starts with? Or can I put (i?) and anything I want and it understands to just answer the question presented?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 13, 2016, 5:03pm UTC](https://forum.ansible.com/t/issues-with-expect/20200/2 "2016-01-13T17:03:43Z")

</div>

looks like you have a bad indent, this is not an expect issue but a  
general parser one, responses should be at same level as command.

as for install, there is no change extras is part of main ansible  
install and does not requires separate install yet.

not sure what (i?) is though ....

---

<div class="post-metadata">

**Author:** ![Mark\_Constant](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@Mark\_Constant](https://forum.ansible.com/u/Mark_Constant)\
**Post date:** [January 14, 2016, 6:26pm UTC](https://forum.ansible.com/t/issues-with-expect/20200/3 "2016-01-14T18:26:17Z")

</div>

The (I?) is from the example in the documentation. I meant to really put (?I). There really seems to be know documentation on how to properly format the response questions.

- expect:  
command: passwd username  
responses:  
(?i)password: “MySekretPa$$word”

---

<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 14, 2016, 6:42pm UTC](https://forum.ansible.com/t/issues-with-expect/20200/4 "2016-01-14T18:42:10Z")

</div>

Mark,

The response questions can either be statically defined strings or regex. The (?i) is python regex syntax for for indicating case insensitive comparison.

The underlying library used by the expect module is pexpect.

Further information at:  
[https://pexpect.readthedocs.org/en/stable/api/pexpect.html#run-function](https://pexpect.readthedocs.org/en/stable/api/pexpect.html#run-function)  
[https://docs.python.org/2/library/re.html#regular-expression-syntax](https://docs.python.org/2/library/re.html#regular-expression-syntax)
