Ansible expect module to prompt yes to a question (with spl characters)

4,654 views
Skip to first unread message

Vikas Kumar

unread,
Sep 29, 2016, 9:03:43 AM9/29/16
to Ansible Project
Hello Everyone,

How can I use Ansible expect module to say yes for this prompt.

Are you sure you want to continue (yes/no)?

I tried to use this in vain. I think Ansible does not like characters like these -  ( , / , ) , ?

- expect:
    command
: /my/command
    responses
:
     
Are you sure you want to continue (yes/no)?: yes


Thanks in advance.

Cheers,
Vikas

Kai Stian Olstad

unread,
Sep 29, 2016, 9:12:46 AM9/29/16
to ansible...@googlegroups.com
On 29.09.2016 15:03, Vikas Kumar wrote:
> Hello Everyone,
>
> How can I use Ansible expect module to say yes for this prompt.
>
> Are you sure you want to continue (yes/no)?
>
> I tried to use this in vain. I think Ansible does not like characters
> like
> these - *( , / , ) , ?*

Ansible and expect like them. But responses in expect is regexp and (, )
and ? and many more is special character,
for a full list see https://docs.python.org/2/library/re.html

>
> - expect:
> command: /my/command
> responses:
> Are you sure you want to continue (yes/no)?: yes
>

The special characters need to be escaped since you mean them literally.
Try this
Are you sure you want to continue \(yes/no\)\?: yes

--
Kai Stian Olstad

Vikas Kumar

unread,
Sep 29, 2016, 9:25:46 AM9/29/16
to Ansible Project, ansible-pr...@olstad.com
Thanks Kai,

I did tried that earlier but encountered below error

An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/var/folders/qw/5nbqbmj97hsfz3z5lkwqk9lr0000gn/T/ansible_eLtUlG/ansible_module_expect.py", line 230, in <module>
    main()
  File "/var/folders/qw/5nbqbmj97hsfz3z5lkwqk9lr0000gn/T/ansible_eLtUlG/ansible_module_expect.py", line 149, in main
    response = u'%s\n' % value.rstrip('\n').decode()
AttributeError: 'bool' object has no attribute 'rstrip'

fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "expect"}, "module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/qw/5nbqbmj97hsfz3z5lkwqk9lr0000gn/T/ansible_eLtUlG/ansible_module_expect.py\", line 230, in <module>\n    main()\n  File \"/var/folders/qw/5nbqbmj97hsfz3z5lkwqk9lr0000gn/T/ansible_eLtUlG/ansible_module_expect.py\", line 149, in main\n    response = u'%s\\n' % value.rstrip('\\n').decode()\nAttributeError: 'bool' object has no attribute 'rstrip'\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}

- Vikas

Matt Martz

unread,
Sep 29, 2016, 10:03:20 AM9/29/16
to ansible...@googlegroups.com, ansible-pr...@olstad.com
You likely need to quote your answer, a bare `yes` in YAML is treated as a boolean, so you will need to quote it like:  "yes"

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4a3128c3-873d-4b7f-8bb1-378e8d255dba%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Matt Martz
@sivel
sivel.net

Vikas Kumar

unread,
Sep 29, 2016, 8:42:25 PM9/29/16
to Ansible Project, ansible-pr...@olstad.com
Thanks Matt, that worked like a charm. I will keep this in my notes. 


On Friday, 30 September 2016 00:03:20 UTC+10, Matt Martz wrote:
You likely need to quote your answer, a bare `yes` in YAML is treated as a boolean, so you will need to quote it like:  "yes"

Murthy Vipparthy

unread,
May 26, 2017, 9:34:08 AM5/26/17
to Ansible Project
Hi there,

I am stuck @ similar place where I have to say enter after y when 'Do you accept this license[y/n]' . I have given following CODE and stuck, Any help appreciated.

-Murthy


responses:
         'Press \[Enter\] to continue:': \n
         'Do you accept this license\?\[y/n\]': y\n
Reply all
Reply to author
Forward
0 new messages