# Having issues with Expect: module

**URL:** <https://forum.ansible.com/t/having-issues-with-expect-module/20308>\
**Category:** Ansible Project\
**Created:** [January 21, 2016, 11:16pm UTC](https://forum.ansible.com/t/having-issues-with-expect-module/20308 "2016-01-21T23:16:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Byron\_Kim](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@Byron\_Kim](https://forum.ansible.com/u/Byron_Kim)\
**Post date:** [January 21, 2016, 11:16pm UTC](https://forum.ansible.com/t/having-issues-with-expect-module/20308/1 "2016-01-21T23:16:00Z")

</div>

I can’t seem to find much documentation or uses of this module. I tried reading up on pexpect documentation however, i’m unable to find my answer.

I’m having ansible run a script and then there are prompts that need to be answered.

`

- name: GENERATE CERTIFICATE AND KEY  
expect:  
command: /home/user/script arg1  
chdir: /home/user/  
responses:  
(^)(?i)Enter: ‘{{ passphrase }}’  
(^)(?i)Verifying: ‘{{ passphrase }}’  
(^)(?i)Common: ‘{{ common\_name }}’  
`

When the ./script runs, it has a series of text and the prompt finishes with:

‘Enter PEM pass phrase:’

is the `(^)(?i)` the correct regex I would be using to match the text ‘Enter’?

---

<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 21, 2016, 11:23pm UTC](https://forum.ansible.com/t/having-issues-with-expect-module/20308/2 "2016-01-21T23:23:17Z")

</div>

Id recommend just starting off with using `Enter: “{{ passphrase}}”

The (?i) indicates a case insensitive search, and the parents around ^ are unnecessary, and the can be problematic as sometimes expect sees a \n or a space as the first char.

---

<div class="post-metadata">

**Author:** ![Byron\_Kim](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@Byron\_Kim](https://forum.ansible.com/u/Byron_Kim)\
**Post date:** [January 21, 2016, 11:34pm UTC](https://forum.ansible.com/t/having-issues-with-expect-module/20308/3 "2016-01-21T23:34:38Z")

</div>

Hi Matt - thanks for the quick response. That seemed to have done the trick.

Thanks!

---

<div class="post-metadata">

**Author:** ![adhithacholan\_karuna](https://avatars.discourse-cdn.com/v4/letter/a/e19adc/32.png) [@adhithacholan\_karuna](https://forum.ansible.com/u/adhithacholan_karuna)\
**Post date:** [June 16, 2016, 5:44am UTC](https://forum.ansible.com/t/having-issues-with-expect-module/20308/4 "2016-06-16T05:44:06Z")

</div>

Hi Matt,  
Can you please help me here on “duplicate dict key”

[kodiak@localhost 10.0.1.51]$ cat dockerimage.yml

---

<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:** [June 16, 2016, 1:08pm UTC](https://forum.ansible.com/t/having-issues-with-expect-module/20308/5 "2016-06-16T13:08:09Z")

</div>

The `expect` module has the ability to respond multiple times to a single expected string, so instead of defining the expected string 2 times, you define it once, but give it a list of responses. Such as:

- expect:  
command: /usr/local/sbin/install\_blade.sh  
responses:  
‘(?i)Enter choice:’:
- “2”
- “99”  
‘(?i)Enter desired hostname:’: “rhel72”  
‘(?i)associate hostname with:’: “oambr-ext”

This will require that you are running ansible 2.1, since that is the first version to have the multi answers per question functionality.
