Ansible Expect Module

243 views
Skip to first unread message

Veda K

unread,
May 24, 2016, 5:54:27 AM5/24/16
to Ansible Project
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

Kai Stian Olstad

unread,
May 24, 2016, 11:29:30 AM5/24/16
to ansible...@googlegroups.com
The responses is python regex and []()? has special meaning, so I guess
you need to escape them.
The first response would be:
(?i)Customize user account for ambari-server daemon \[y/n\] \(n\)\?: y

--
Kai Stian Olstad

Veda K

unread,
May 24, 2016, 4:29:08 PM5/24/16
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages