# expect with duplicated responses

**URL:** <https://forum.ansible.com/t/expect-with-duplicated-responses/29808>\
**Category:** Ansible Project\
**Created:** [March 1, 2019, 9:47pm UTC](https://forum.ansible.com/t/expect-with-duplicated-responses/29808 "2019-03-01T21:47:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [March 1, 2019, 9:47pm UTC](https://forum.ansible.com/t/expect-with-duplicated-responses/29808/1 "2019-03-01T21:47:46Z")

</div>

When using the following (first time using expect) I have many responses with the same prompt. I took care of the first 20 of them as you can see below, however, the same prompt comes up again later during the install. I get complaints about duplicate values and the installer fails. How can I work around this (I wish this particular installer had a response file to configure that wasn’t garbage)

Error:

`  
[WARNING]: While constructing a mapping from /etc/ansible/role/agent-install/tasks/main.yml, line 27, column 7, found a duplicate dict key (PRESS TO CONTINUE:). Using last defined value only.

`

Code:

`

- name: Execute the installer  
expect:  
command: “{{ directory }}/setup.bin”  
responses:  
‘PRESS TO CONTINUE:’:
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”
- “”

# The above command being repeated should be sufficient, but adding a couple of more

# just in case. Having extras in this case will not hurt

- “”
- “”  
‘DO YOU ACCEPT THE TERMS OF THIS LICENSE AGREEMENT? (Y/N):’: “Y”  
‘ENTER AN ABSOLUTE PATH, OR PRESS TO ACCEPT THE DEFAULT:’: “”  
‘Manager IP or hostname: :’: 1.1.1.1  
‘Manager Install Port (default 12345) : :’: “”  
‘Manager Secure Port (default 23456) : :’: “”  
‘PRESS TO CONTINUE:’:
- “”
- “”  
‘PRESS TO EXIT THE INSTALLER:’: “”

`

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [March 1, 2019, 9:52pm UTC](https://forum.ansible.com/t/expect-with-duplicated-responses/29808/2 "2019-03-01T21:52:58Z")

</div>

turns out I can’t use this anyway due to the version of pexpect (booh!), but I would still like to know the answer for future use.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 1, 2019, 9:54pm UTC](https://forum.ansible.com/t/expect-with-duplicated-responses/29808/3 "2019-03-01T21:54:58Z")

</div>

As the error say, you can only have one "PRESS \<ENTER\> TO CONTINUE:" so all the reposes must be merged into one.  
responses is a dictionary, and dict can only have unique keys.

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [March 1, 2019, 9:56pm UTC](https://forum.ansible.com/t/expect-with-duplicated-responses/29808/4 "2019-03-01T21:56:57Z")

</div>

So, is this even possible in this situation where the same key comes up later?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 1, 2019, 10:05pm UTC](https://forum.ansible.com/t/expect-with-duplicated-responses/29808/5 "2019-03-01T22:05:07Z")

</div>

Yes, you just add all the responses under the same key.  
Responses don't need to be in the order they occurs, when expect sees the string(key) it takes the next element in the list(value) of that key.

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [March 1, 2019, 10:08pm UTC](https://forum.ansible.com/t/expect-with-duplicated-responses/29808/6 "2019-03-01T22:08:56Z")

</div>

Nice! I wasn’t aware of that. I wasn’t liking how large that expect task was getting. Thanks!
