# Ansible Expect Module

**URL:** <https://forum.ansible.com/t/ansible-expect-module/21530>\
**Category:** Ansible Project\
**Created:** [May 23, 2016, 8:50pm UTC](https://forum.ansible.com/t/ansible-expect-module/21530 "2016-05-23T20:50:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veda\_K](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@Veda\_K](https://forum.ansible.com/u/Veda_K)\
**Post date:** [May 23, 2016, 8:50pm UTC](https://forum.ansible.com/t/ansible-expect-module/21530/1 "2016-05-23T20:50:28Z")

</div>

Hi,

I am new to ansible and ambari. I am trying to set up ambari-server using ansible expect module to respond to questions/options. My code snippet of expect module is :

expect:  
command: ambari-server setup  
responses:  
(?i)Customize user account for ambari-server daemon [y/n] (n)?: y  
(?i)Enter user account for ambari-server daemon (root): ambari  
(?i)Enter choice (1): ‘1’  
(?i)Enter advanced database configuration [y/n] (n)?: n  
timeout: 30  
echo: yes

I keep running into error:

fatal: [hostnamet]: FAILED! =\> {“changed”: true, “cmd”: “ambari-server setup”, “delta”: “0:00:30.181524”, “end”: “2016-05-23 20:48:29.951770”, “failed”: true, “invocation”: {“module\_args”: {“chdir”: null, “command”: “ambari-server setup”, “creates”: null, “echo”: true, “removes”: null, “responses”: {“(?i)Customize user account for ambari-server daemon [y/n] (n)?”: “y”, “(?i)Enter advanced database configuration [y/n] (n)?”: “n”, “(?i)Enter choice (1)”: “1”, “(?i)Enter user account for ambari-server daemon (root)”: “ambari”}, “timeout”: 30}, “module\_name”: “expect”}, “rc”: null, “start”: “2016-05-23 20:47:59.770246”, “stdout”: "Using python /usr/bin/python\r\nSetup ambari-server\r\nChecking SELinux…\r\nSELinux status is ‘disabled’\r\nCustomize user account for ambari-server daemon [y/n] (n)? ", “stdout\_lines”: [“Using python /usr/bin/python”, “Setup ambari-server”, “Checking SELinux…”, “SELinux status is ‘disabled’”, "Customize user account for ambari-server daemon [y/n] (n)? "]}

It doesn’t seem to be taking my inputs as in the error, not sure.

Can someone please help me here?

Regards,  
Veda

---

<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:** [May 24, 2016, 3:29pm UTC](https://forum.ansible.com/t/ansible-expect-module/21530/2 "2016-05-24T15:29:21Z")

</div>

The responses is python regex and ()? has special meaning, so I guess you need to escape them.  
The first response would be:  
&nbsp;&nbsp;&nbsp;(?i)Customize user account for ambari-server daemon \[y/n\] \(n\)\?: y

---

<div class="post-metadata">

**Author:** ![Veda\_K](https://avatars.discourse-cdn.com/v4/letter/v/bbce88/32.png) [@Veda\_K](https://forum.ansible.com/u/Veda_K)\
**Post date:** [May 24, 2016, 8:29pm UTC](https://forum.ansible.com/t/ansible-expect-module/21530/3 "2016-05-24T20:29:08Z")

</div>

Thanks Kai!

It worked and snippet is here:

expect:  
command: ambari-server setup  
responses:  
‘Customize user account for ambari-server daemon [y/n] (n)?’: y  
‘Enter user account for ambari-server daemon (root)’: ambari  
‘Enter choice (1)’: ‘1’  
‘Do you accept the Oracle Binary Code License Agreement [y/n] (y)?’: y

‘Enter advanced database configuration [y/n] (n)?’: n  
timeout: 300  
echo: yes

Regards,  
Veda
